2021-07-11 15:32:29 +00:00
|
|
|
package prog8tests.helpers
|
|
|
|
|
|
|
|
import kotlin.test.*
|
|
|
|
import kotlin.io.path.*
|
|
|
|
|
|
|
|
import java.nio.file.Path
|
|
|
|
|
|
|
|
|
2021-07-31 12:44:02 +00:00
|
|
|
val workingDir = assumeDirectory("").absolute() // Note: "." does NOT work..!
|
|
|
|
val fixturesDir = assumeDirectory(workingDir,"test/fixtures")
|
|
|
|
val resourcesDir = assumeDirectory(workingDir,"res")
|
|
|
|
val outputDir = assumeDirectory(workingDir, "build/tmp/test")
|
2021-07-11 15:32:29 +00:00
|
|
|
|
2021-07-31 12:44:02 +00:00
|
|
|
fun assumeNotExists(path: Path): Path {
|
|
|
|
assertFalse(path.exists(), "sanity check: should not exist: ${path.absolute()}")
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
|
|
|
fun assumeNotExists(pathStr: String): Path = assumeNotExists(Path(pathStr))
|
|
|
|
fun assumeNotExists(path: Path, other: String): Path = assumeNotExists(path.div(other))
|
|
|
|
|
|
|
|
fun assumeReadable(path: Path): Path {
|
2021-07-11 15:32:29 +00:00
|
|
|
assertTrue(path.isReadable(), "sanity check: should be readable: ${path.absolute()}")
|
2021-07-31 12:44:02 +00:00
|
|
|
return path
|
2021-07-11 15:32:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-31 12:44:02 +00:00
|
|
|
fun assumeReadableFile(path: Path): Path {
|
2021-07-11 15:32:29 +00:00
|
|
|
assertTrue(path.isRegularFile(), "sanity check: should be normal file: ${path.absolute()}")
|
2021-07-31 12:44:02 +00:00
|
|
|
return assumeReadable(path)
|
2021-07-11 15:32:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-31 12:44:02 +00:00
|
|
|
fun assumeReadableFile(pathStr: String): Path = assumeReadableFile(Path(pathStr))
|
|
|
|
fun assumeReadableFile(pathStr: String, other: Path): Path = assumeReadableFile(Path(pathStr), other)
|
|
|
|
fun assumeReadableFile(pathStr: String, other: String): Path = assumeReadableFile(Path(pathStr), other)
|
|
|
|
fun assumeReadableFile(path: Path, other: String): Path = assumeReadableFile(path.div(other))
|
|
|
|
fun assumeReadableFile(path: Path, other: Path): Path = assumeReadableFile(path.div(other))
|
|
|
|
|
|
|
|
fun assumeDirectory(path: Path): Path {
|
2021-07-11 15:32:29 +00:00
|
|
|
assertTrue(path.isDirectory(), "sanity check; should be directory: $path")
|
2021-07-31 12:44:02 +00:00
|
|
|
return path
|
2021-07-11 15:32:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-31 12:44:02 +00:00
|
|
|
fun assumeDirectory(pathStr: String): Path = assumeDirectory(Path(pathStr))
|
|
|
|
fun assumeDirectory(path: Path, other: String): Path = assumeDirectory(path.div(other))
|
2021-07-11 15:32:29 +00:00
|
|
|
|
2021-07-31 12:44:02 +00:00
|
|
|
|
|
|
|
@Deprecated("Directories are checked automatically at init.",
|
|
|
|
ReplaceWith("/* nothing */"))
|
2021-08-01 08:11:29 +00:00
|
|
|
@Suppress("UNUSED_PARAMETER")
|
2021-07-11 17:04:53 +00:00
|
|
|
fun sanityCheckDirectories(workingDirName: String? = null) {
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|