2021-12-04 17:20:22 +00:00
|
|
|
package prog8tests
|
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-04-15 20:38:32 +00:00
|
|
|
import prog8tests.helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "i_do_not_exist"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeNotExists(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeNotExists(Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "i_do_not_exist"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "ast_simple_main.p8"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<java.lang.AssertionError> {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeNotExists("${Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "i_do_not_exist"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeNotExists(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeNotExists(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeNotExists(Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "i_do_not_exist"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory(path)
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2022-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "ast_simple_main.p8"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory(path)
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2022-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.workingDir
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "i_do_not_exist"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory("$path")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing file") {
|
2022-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "ast_simple_main.p8"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory("$path")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on existing directory") {
|
2022-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.workingDir
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory(Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.workingDir / ".."
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return resulting path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory("${Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory("${Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.workingDir / ".."
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return resulting path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory("${Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory("${Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.workingDir / ".."
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return resulting path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeDirectory(Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "i_do_not_exist"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile(path)
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on readable file") {
|
2022-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "ast_simple_main.p8"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile(Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "i_do_not_exist"
|
2021-11-07 20:18:18 +00:00
|
|
|
shouldThrow<AssertionError> {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile("$path")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-07 16:25:53 +00:00
|
|
|
test("on readable file") {
|
2022-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "ast_simple_main.p8"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the resulting path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile("${Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile(Helpers.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-04-15 20:38:32 +00:00
|
|
|
val path = Helpers.fixturesDir / "ast_simple_main.p8"
|
2021-11-07 16:25:53 +00:00
|
|
|
withClue("should return the resulting path") {
|
2022-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile(Helpers.fixturesDir / Path("ast_simple_main.p8")) shouldBe Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile(Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile("${Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile(Helpers.fixturesDir / "ast_simple_main.p8") shouldBe Helpers.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-04-15 20:38:32 +00:00
|
|
|
Helpers.assumeReadableFile("${Helpers.fixturesDir}", "..")
|
2021-07-31 12:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-07 16:25:53 +00:00
|
|
|
})
|