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
|
||||
|
||||
import java.io.IOException
|
||||
import java.nio.file.*
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.createSymbolicLinkPointingTo
|
||||
import kotlin.io.path.deleteIfExists
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.test.*
|
||||
import kotlin.io.path.deleteRecursively
|
||||
import kotlin.test.AfterTest
|
||||
|
||||
abstract class AbstractPathTest {
|
||||
private val cleanUpActions = mutableListOf<Pair<Path, (Path) -> Unit>>()
|
||||
@@ -22,24 +20,10 @@ abstract class AbstractPathTest {
|
||||
}
|
||||
|
||||
fun Path.cleanupRecursively(): Path {
|
||||
cleanUpActions.add(this to {
|
||||
if (it.exists(LinkOption.NOFOLLOW_LINKS)) Files.walkFileTree(it, cleanupVisitor)
|
||||
})
|
||||
cleanUpActions.add(this to { it.deleteRecursively() })
|
||||
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
|
||||
fun cleanUp() {
|
||||
for ((path, action) in cleanUpActions) {
|
||||
|
||||
Reference in New Issue
Block a user