prog8/compiler/test/helpers_pathsTests.kt

310 lines
9.5 KiB
Kotlin
Raw Normal View History

package prog8tests
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
2022-06-26 16:51:03 +00:00
import prog8tests.helpers.*
2021-10-10 22:22:04 +00:00
import kotlin.io.path.Path
import kotlin.io.path.div
// Do not move into folder helpers/!
// This folder is also used by compiler/test
// but the testing of the helpers themselves must be performed ONLY HERE.
//
class PathsHelpersTests: FunSpec({
context("AssumeNotExists") {
context("WithOnePathArg") {
test("on non-existing path") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "i_do_not_exist"
withClue("should return the path") {
2022-06-26 16:51:03 +00:00
assumeNotExists(path) shouldBe path
}
}
test("on existing file") {
shouldThrow<java.lang.AssertionError> {
2022-06-26 16:51:03 +00:00
assumeNotExists(fixturesDir / "ast_simple_main.p8")
}
}
test("on existing directory") {
shouldThrow<java.lang.AssertionError> {
2022-06-26 16:51:03 +00:00
assumeNotExists(fixturesDir)
}
}
}
context("WithOneStringArg") {
test("on non-existing path") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "i_do_not_exist"
withClue("should return the path") {
2022-06-26 16:51:03 +00:00
assumeNotExists("$path") shouldBe path
}
}
test("on existing file") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "ast_simple_main.p8"
shouldThrow<java.lang.AssertionError> {
2022-06-26 16:51:03 +00:00
assumeNotExists("$path")
}
}
test("on existing directory") {
shouldThrow<java.lang.AssertionError> {
2022-06-26 16:51:03 +00:00
assumeNotExists("${fixturesDir}")
}
}
}
context("WithPathAndStringArgs") {
test("on non-existing path") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "i_do_not_exist"
withClue("should return the path") {
2022-06-26 16:51:03 +00:00
assumeNotExists(fixturesDir / "i_do_not_exist") shouldBe path
}
}
test("on existing file") {
shouldThrow<java.lang.AssertionError> {
2022-06-26 16:51:03 +00:00
assumeNotExists(fixturesDir, "ast_simple_main.p8")
}
}
test("on existing directory") {
shouldThrow<java.lang.AssertionError> {
2022-06-26 16:51:03 +00:00
assumeNotExists(fixturesDir, "..")
}
}
}
}
context("AssumeDirectory") {
context("WithOnePathArg") {
test("on non-existing path") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "i_do_not_exist"
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory(path)
}
}
test("on existing file") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "ast_simple_main.p8"
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory(path)
}
}
test("on existing directory") {
2022-06-26 16:51:03 +00:00
val path = workingDir
withClue("should return the path") {
2022-06-26 16:51:03 +00:00
assumeDirectory(path) shouldBe path
}
}
}
context("WithOneStringArg") {
test("on non-existing path") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "i_do_not_exist"
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory("$path")
}
}
test("on existing file") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "ast_simple_main.p8"
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory("$path")
}
}
test("on existing directory") {
2022-06-26 16:51:03 +00:00
val path = workingDir
withClue("should return the path") {
2022-06-26 16:51:03 +00:00
assumeDirectory("$path") shouldBe path
}
}
}
context("WithPathAndStringArgs") {
test("on non-existing path") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory(fixturesDir, "i_do_not_exist")
}
}
test("on existing file") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory(fixturesDir, "ast_simple_main.p8")
}
}
test("on existing directory") {
2022-06-26 16:51:03 +00:00
val path = workingDir / ".."
withClue("should return resulting path") {
2022-06-26 16:51:03 +00:00
assumeDirectory(workingDir / "..") shouldBe path
}
}
}
context("WithStringAndStringArgs") {
test("on non-existing path") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory("${fixturesDir}", "i_do_not_exist")
}
}
test("on existing file") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory("${fixturesDir}", "ast_simple_main.p8")
}
}
test("on existing directory") {
2022-06-26 16:51:03 +00:00
val path = workingDir / ".."
withClue("should return resulting path") {
2022-06-26 16:51:03 +00:00
assumeDirectory(workingDir / "..") shouldBe path
}
}
}
context("WithStringAndPathArgs") {
test("on non-existing path") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory("${fixturesDir}", Path("i_do_not_exist"))
}
}
test("on existing file") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeDirectory("${fixturesDir}", Path("ast_simple_main.p8"))
}
}
test("on existing directory") {
2022-06-26 16:51:03 +00:00
val path = workingDir / ".."
withClue("should return resulting path") {
2022-06-26 16:51:03 +00:00
assumeDirectory(workingDir / Path("..")) shouldBe path
}
}
}
}
context("AssumeReadableFile") {
context("WithOnePathArg") {
test("on non-existing path") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "i_do_not_exist"
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile(path)
}
}
test("on readable file") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "ast_simple_main.p8"
withClue("should return the path") {
2022-06-26 16:51:03 +00:00
assumeReadableFile(path) shouldBe path
}
}
test("on directory") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile(fixturesDir)
}
}
}
context("WithOneStringArg") {
test("on non-existing path") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "i_do_not_exist"
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile("$path")
}
}
test("on readable file") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "ast_simple_main.p8"
withClue("should return the resulting path") {
2022-06-26 16:51:03 +00:00
assumeReadableFile("$path") shouldBe path
}
}
test("on directory") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile("${fixturesDir}")
}
}
}
context("WithPathAndStringArgs") {
test("on non-existing path") {
shouldThrow<java.lang.AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile(fixturesDir, "i_do_not_exist")
}
}
test("on readable file") {
2022-06-26 16:51:03 +00:00
val path = fixturesDir / "ast_simple_main.p8"
withClue("should return the resulting path") {
2022-06-26 16:51:03 +00:00
assumeReadableFile(fixturesDir / "ast_simple_main.p8") shouldBe path
}
}
test("on directory") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile(fixturesDir, "..")
}
}
}
context("WithPathAndPathArgs") {
test("on non-existing path") {
shouldThrow<java.lang.AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile(fixturesDir, Path("i_do_not_exist"))
}
}
test("on readable file") {
withClue("should return the resulting path") {
2022-06-26 16:51:03 +00:00
assumeReadableFile(fixturesDir / Path("ast_simple_main.p8")) shouldBe fixturesDir / "ast_simple_main.p8"
}
}
test("on directory") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile(fixturesDir, Path(".."))
}
}
}
context("WithStringAndStringArgs") {
test("on non-existing path") {
shouldThrow<java.lang.AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile("${fixturesDir}", "i_do_not_exist")
}
}
test("on readable file") {
withClue("should return the resulting path") {
2022-06-26 16:51:03 +00:00
assumeReadableFile(fixturesDir / "ast_simple_main.p8") shouldBe fixturesDir / "ast_simple_main.p8"
}
}
test("on directory") {
shouldThrow<AssertionError> {
2022-06-26 16:51:03 +00:00
assumeReadableFile("${fixturesDir}", "..")
}
}
}
}
})