2024-09-08 14:03:57 +00:00
|
|
|
package prog8tests.compiler
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 20:18:18 +00:00
|
|
|
import io.kotest.assertions.throwables.shouldThrow
|
2021-11-07 16:25:53 +00:00
|
|
|
import io.kotest.assertions.withClue
|
|
|
|
import io.kotest.core.spec.style.FunSpec
|
2021-11-07 20:18:18 +00:00
|
|
|
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
|
2021-08-02 13:47:42 +00:00
|
|
|
|
2021-07-31 12:44:02 +00:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
2021-11-07 16:25:53 +00:00
|
|
|
class PathsHelpersTests: FunSpec({
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("AssumeNotExists") {
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithOnePathArg") {
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on non-existing path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "i_do_not_exist"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeNotExists(path) shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeNotExists(fixturesDir / "ast_simple_main.p8")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeNotExists(fixturesDir)
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithOneStringArg") {
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on non-existing path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "i_do_not_exist"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeNotExists("$path") shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "ast_simple_main.p8"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeNotExists("$path")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-10-31 22:59:33 +00:00
|
|
|
assumeNotExists("$fixturesDir")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithPathAndStringArgs") {
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on non-existing path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "i_do_not_exist"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeNotExists(fixturesDir / "i_do_not_exist") shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeNotExists(fixturesDir, "ast_simple_main.p8")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeNotExists(fixturesDir, "..")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("AssumeDirectory") {
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithOnePathArg") {
|
|
|
|
test("on non-existing path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "i_do_not_exist"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory(path)
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "ast_simple_main.p8"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory(path)
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = workingDir
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory(path) shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithOneStringArg") {
|
|
|
|
test("on non-existing path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "i_do_not_exist"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory("$path")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "ast_simple_main.p8"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory("$path")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = workingDir
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory("$path") shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithPathAndStringArgs") {
|
|
|
|
test("on non-existing path") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory(fixturesDir, "i_do_not_exist")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory(fixturesDir, "ast_simple_main.p8")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = workingDir / ".."
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return resulting path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory(workingDir / "..") shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-01 13:15:54 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithStringAndStringArgs") {
|
|
|
|
test("on non-existing path") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-10-31 22:59:33 +00:00
|
|
|
assumeDirectory("$fixturesDir", "i_do_not_exist")
|
2021-08-01 13:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-10-31 22:59:33 +00:00
|
|
|
assumeDirectory("$fixturesDir", "ast_simple_main.p8")
|
2021-08-01 13:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = workingDir / ".."
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return resulting path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory(workingDir / "..") shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-08-01 13:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithStringAndPathArgs") {
|
|
|
|
test("on non-existing path") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-10-31 22:59:33 +00:00
|
|
|
assumeDirectory("$fixturesDir", Path("i_do_not_exist"))
|
2021-08-01 13:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-10-31 22:59:33 +00:00
|
|
|
assumeDirectory("$fixturesDir", Path("ast_simple_main.p8"))
|
2021-08-01 13:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = workingDir / ".."
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return resulting path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeDirectory(workingDir / Path("..")) shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-08-01 13:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("AssumeReadableFile") {
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithOnePathArg") {
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on non-existing path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "i_do_not_exist"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile(path)
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on readable file") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "ast_simple_main.p8"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile(path) shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on directory") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile(fixturesDir)
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithOneStringArg") {
|
2021-07-31 12:44:02 +00:00
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on non-existing path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "i_do_not_exist"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile("$path")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on readable file") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "ast_simple_main.p8"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the resulting path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile("$path") shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on directory") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-10-31 22:59:33 +00:00
|
|
|
assumeReadableFile("$fixturesDir")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithPathAndStringArgs") {
|
|
|
|
test("on non-existing path") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile(fixturesDir, "i_do_not_exist")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on readable file") {
|
2022-06-26 16:51:03 +00:00
|
|
|
val path = fixturesDir / "ast_simple_main.p8"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the resulting path") {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile(fixturesDir / "ast_simple_main.p8") shouldBe path
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on directory") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile(fixturesDir, "..")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithPathAndPathArgs") {
|
|
|
|
test("on non-existing path") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile(fixturesDir, Path("i_do_not_exist"))
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
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"
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on directory") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-06-26 16:51:03 +00:00
|
|
|
assumeReadableFile(fixturesDir, Path(".."))
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
context("WithStringAndStringArgs") {
|
|
|
|
test("on non-existing path") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-10-31 22:59:33 +00:00
|
|
|
assumeReadableFile("$fixturesDir", "i_do_not_exist")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
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"
|
2021-11-07 16:25:53 +00:00
|
|
|
}
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on directory") {
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-10-31 22:59:33 +00:00
|
|
|
assumeReadableFile("$fixturesDir", "..")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 16:25:53 +00:00
|
|
|
})
|