2021-12-04 17:20:22 +00:00
|
|
|
package prog8tests.helpers
|
2021-07-11 15:32:29 +00:00
|
|
|
|
2021-11-07 20:18:18 +00:00
|
|
|
import io.kotest.assertions.withClue
|
|
|
|
import io.kotest.matchers.shouldBe
|
2021-11-07 16:25:53 +00:00
|
|
|
import java.nio.file.Files
|
2021-07-11 15:32:29 +00:00
|
|
|
import java.nio.file.Path
|
2021-10-10 22:22:04 +00:00
|
|
|
import kotlin.io.path.*
|
2021-07-11 15:32:29 +00:00
|
|
|
|
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
val workingDir = assumeDirectory("").absolute() // Note: "." does NOT work..!
|
|
|
|
val fixturesDir = assumeDirectory(workingDir, "test/fixtures")
|
|
|
|
val resourcesDir = assumeDirectory(workingDir, "res")
|
|
|
|
val outputDir: Path =
|
|
|
|
createIfNotExists(workingDir, "build/tmp/test").also { assumeDirectory(workingDir, "build/tmp/test") }
|
2021-11-07 16:25:53 +00:00
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
fun createIfNotExists(workingDir: Path, path: String): Path {
|
|
|
|
val dir = workingDir / path
|
|
|
|
if (!dir.toFile().isDirectory)
|
|
|
|
Files.createDirectories(dir)
|
|
|
|
return dir
|
|
|
|
}
|
2021-07-11 15:32:29 +00:00
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
fun assumeNotExists(path: Path): Path {
|
|
|
|
withClue("sanity check: should not exist: ${path.absolute()}") {
|
|
|
|
path.exists() shouldBe false
|
2021-11-07 20:18:18 +00:00
|
|
|
}
|
2022-06-26 16:51:03 +00:00
|
|
|
return path
|
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
fun assumeNotExists(pathStr: String): Path = assumeNotExists(Path(pathStr))
|
|
|
|
fun assumeNotExists(path: Path, other: String): Path = assumeNotExists(path / other)
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
fun assumeReadable(path: Path): Path {
|
|
|
|
withClue("sanity check: should be readable: ${path.absolute()}") {
|
|
|
|
path.isReadable() shouldBe true
|
2021-11-07 20:18:18 +00:00
|
|
|
}
|
2022-06-26 16:51:03 +00:00
|
|
|
return path
|
|
|
|
}
|
2021-07-11 15:32:29 +00:00
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
fun assumeReadableFile(path: Path): Path {
|
|
|
|
withClue("sanity check: should be normal file: ${path.absolute()}") {
|
|
|
|
path.isRegularFile() shouldBe true
|
2021-11-07 20:18:18 +00:00
|
|
|
}
|
2022-06-26 16:51:03 +00:00
|
|
|
return assumeReadable(path)
|
|
|
|
}
|
2021-07-11 15:32:29 +00:00
|
|
|
|
2022-06-26 16:51:03 +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 / other)
|
|
|
|
fun assumeReadableFile(path: Path, other: Path): Path = assumeReadableFile(path / other)
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
fun assumeDirectory(path: Path): Path {
|
|
|
|
withClue("sanity check; should be directory: $path") {
|
|
|
|
path.isDirectory() shouldBe true
|
2021-11-07 20:18:18 +00:00
|
|
|
}
|
2022-06-26 16:51:03 +00:00
|
|
|
return path
|
|
|
|
}
|
2021-07-11 15:32:29 +00:00
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
fun assumeDirectory(pathStr: String): Path = assumeDirectory(Path(pathStr))
|
|
|
|
fun assumeDirectory(path: Path, other: String): Path = assumeDirectory(path / other)
|
|
|
|
fun assumeDirectory(pathStr: String, other: String): Path = assumeDirectory(Path(pathStr) / other)
|
|
|
|
fun assumeDirectory(pathStr: String, other: Path): Path = assumeDirectory(Path(pathStr) / other)
|
2021-07-11 15:32:29 +00:00
|
|
|
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
@Deprecated(
|
|
|
|
"Directories are checked automatically at init.",
|
|
|
|
ReplaceWith("/* nothing */")
|
|
|
|
)
|
|
|
|
@Suppress("UNUSED_PARAMETER")
|
|
|
|
fun sanityCheckDirectories(workingDirName: String? = null) {
|
|
|
|
}
|