Move Path.tryCreateSymbolicLinkTo to AbstractPathTest.kt

This commit is contained in:
Abduqodiri Qurbonzoda
2022-08-02 00:48:59 +03:00
committed by Space
parent 81d6fea0c4
commit f0da420b1f
3 changed files with 11 additions and 11 deletions
@@ -8,6 +8,7 @@ package kotlin.jdk7.test
import java.io.IOException
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
import kotlin.io.path.createSymbolicLinkPointingTo
import kotlin.io.path.deleteIfExists
import kotlin.io.path.exists
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) {
try {
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.referenceFilesOnly
import kotlin.jdk7.test.PathTreeWalkTest.Companion.testVisitedFiles
import kotlin.jdk7.test.PathTreeWalkTest.Companion.tryCreateSymbolicLinkTo
import kotlin.test.*
class FileVisitorBuilderTest : AbstractPathTest() {
@@ -28,16 +28,6 @@ class PathTreeWalkTest : AbstractPathTest() {
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) {
val actual = walk.map { it.relativeToOrSelf(basedir).invariantSeparatorsPathString }
assertEquals(expected.sorted(), actual.toList().sorted(), message?.invoke())