Use Path.deleteRecursively() in the Path.cleanupRecursively() test util
This commit is contained in:
committed by
Space
parent
90189f9c39
commit
f38654740e
@@ -5,13 +5,11 @@
|
|||||||
|
|
||||||
package kotlin.jdk7.test
|
package kotlin.jdk7.test
|
||||||
|
|
||||||
import java.io.IOException
|
import java.nio.file.Path
|
||||||
import java.nio.file.*
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes
|
|
||||||
import kotlin.io.path.createSymbolicLinkPointingTo
|
import kotlin.io.path.createSymbolicLinkPointingTo
|
||||||
import kotlin.io.path.deleteIfExists
|
import kotlin.io.path.deleteIfExists
|
||||||
import kotlin.io.path.exists
|
import kotlin.io.path.deleteRecursively
|
||||||
import kotlin.test.*
|
import kotlin.test.AfterTest
|
||||||
|
|
||||||
abstract class AbstractPathTest {
|
abstract class AbstractPathTest {
|
||||||
private val cleanUpActions = mutableListOf<Pair<Path, (Path) -> Unit>>()
|
private val cleanUpActions = mutableListOf<Pair<Path, (Path) -> Unit>>()
|
||||||
@@ -22,24 +20,10 @@ abstract class AbstractPathTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Path.cleanupRecursively(): Path {
|
fun Path.cleanupRecursively(): Path {
|
||||||
cleanUpActions.add(this to {
|
cleanUpActions.add(this to { it.deleteRecursively() })
|
||||||
if (it.exists(LinkOption.NOFOLLOW_LINKS)) Files.walkFileTree(it, cleanupVisitor)
|
|
||||||
})
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
private val cleanupVisitor = object : SimpleFileVisitor<Path>() {
|
|
||||||
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
|
|
||||||
file.deleteIfExists()
|
|
||||||
return super.visitFile(file, attrs)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun postVisitDirectory(dir: Path, exc: IOException?): FileVisitResult {
|
|
||||||
dir.deleteIfExists()
|
|
||||||
return super.postVisitDirectory(dir, exc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterTest
|
@AfterTest
|
||||||
fun cleanUp() {
|
fun cleanUp() {
|
||||||
for ((path, action) in cleanUpActions) {
|
for ((path, action) in cleanUpActions) {
|
||||||
|
|||||||
Reference in New Issue
Block a user