Move Path.tryCreateSymbolicLinkTo to AbstractPathTest.kt
This commit is contained in:
committed by
Space
parent
81d6fea0c4
commit
f0da420b1f
@@ -8,6 +8,7 @@ package kotlin.jdk7.test
|
|||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.file.*
|
import java.nio.file.*
|
||||||
import java.nio.file.attribute.BasicFileAttributes
|
import java.nio.file.attribute.BasicFileAttributes
|
||||||
|
import kotlin.io.path.createSymbolicLinkPointingTo
|
||||||
import kotlin.io.path.deleteIfExists
|
import kotlin.io.path.deleteIfExists
|
||||||
import kotlin.io.path.exists
|
import kotlin.io.path.exists
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
@@ -50,6 +51,16 @@ abstract class AbstractPathTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Path.tryCreateSymbolicLinkTo(original: Path): Path? {
|
||||||
|
return try {
|
||||||
|
this.createSymbolicLinkPointingTo(original)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// the underlying OS may not support symbolic links or may require a privilege
|
||||||
|
println("Creating a symbolic link failed with $e")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun withRestrictedRead(vararg paths: Path, block: () -> Unit) {
|
fun withRestrictedRead(vararg paths: Path, block: () -> Unit) {
|
||||||
try {
|
try {
|
||||||
if (paths.all { it.toFile().setReadable(false) }) {
|
if (paths.all { it.toFile().setReadable(false) }) {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import kotlin.jdk7.test.PathTreeWalkTest.Companion.createTestFiles
|
|||||||
import kotlin.jdk7.test.PathTreeWalkTest.Companion.referenceFilenames
|
import kotlin.jdk7.test.PathTreeWalkTest.Companion.referenceFilenames
|
||||||
import kotlin.jdk7.test.PathTreeWalkTest.Companion.referenceFilesOnly
|
import kotlin.jdk7.test.PathTreeWalkTest.Companion.referenceFilesOnly
|
||||||
import kotlin.jdk7.test.PathTreeWalkTest.Companion.testVisitedFiles
|
import kotlin.jdk7.test.PathTreeWalkTest.Companion.testVisitedFiles
|
||||||
import kotlin.jdk7.test.PathTreeWalkTest.Companion.tryCreateSymbolicLinkTo
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
class FileVisitorBuilderTest : AbstractPathTest() {
|
class FileVisitorBuilderTest : AbstractPathTest() {
|
||||||
|
|||||||
@@ -28,16 +28,6 @@ class PathTreeWalkTest : AbstractPathTest() {
|
|||||||
return basedir
|
return basedir
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Path.tryCreateSymbolicLinkTo(original: Path): Path? {
|
|
||||||
return try {
|
|
||||||
this.createSymbolicLinkPointingTo(original)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// the underlying OS may not support symbolic links or may require a privilege
|
|
||||||
println("Creating a symbolic link failed with $e")
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testVisitedFiles(expected: List<String>, walk: Sequence<Path>, basedir: Path, message: (() -> String)? = null) {
|
fun testVisitedFiles(expected: List<String>, walk: Sequence<Path>, basedir: Path, message: (() -> String)? = null) {
|
||||||
val actual = walk.map { it.relativeToOrSelf(basedir).invariantSeparatorsPathString }
|
val actual = walk.map { it.relativeToOrSelf(basedir).invariantSeparatorsPathString }
|
||||||
assertEquals(expected.sorted(), actual.toList().sorted(), message?.invoke())
|
assertEquals(expected.sorted(), actual.toList().sorted(), message?.invoke())
|
||||||
|
|||||||
Reference in New Issue
Block a user