mirror of
https://github.com/irmen/prog8.git
synced 2025-02-08 16:30:28 +00:00
* test helpers assumeXyz (helpers/paths.kt) return the resulting path (unless they fail, of course); test directories are checked automatically at init, so no sanityCheckDirectories is needed anymore
This commit is contained in:
parent
ed061b362b
commit
1b451180c1
@ -24,11 +24,6 @@ import prog8.compiler.target.Cx16Target
|
|||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class TestCompilerOnCharLit {
|
class TestCompilerOnCharLit {
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
fun setUp() {
|
|
||||||
sanityCheckDirectories("compiler")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCharLitAsRomsubArg() {
|
fun testCharLitAsRomsubArg() {
|
||||||
val platform = Cx16Target
|
val platform = Cx16Target
|
||||||
|
@ -23,20 +23,14 @@ import prog8.compiler.target.ICompilationTarget
|
|||||||
//@Disabled("to save some time")
|
//@Disabled("to save some time")
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class TestCompilerOnExamples {
|
class TestCompilerOnExamples {
|
||||||
private val examplesDir = workingDir.resolve("../examples")
|
private val examplesDir = assumeDirectory(workingDir, "../examples")
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
fun setUp() {
|
|
||||||
sanityCheckDirectories("compiler")
|
|
||||||
assumeDirectory(examplesDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: make assembly stage testable - in case of failure (eg of 64tass) it Process.exit s
|
// TODO: make assembly stage testable - in case of failure (eg of 64tass) it Process.exit s
|
||||||
|
|
||||||
private fun makeDynamicCompilerTest(name: String, platform: ICompilationTarget, optimize: Boolean) : DynamicTest {
|
private fun makeDynamicCompilerTest(name: String, platform: ICompilationTarget, optimize: Boolean) : DynamicTest {
|
||||||
val searchIn = mutableListOf(examplesDir)
|
val searchIn = mutableListOf(examplesDir)
|
||||||
if (platform == Cx16Target) {
|
if (platform == Cx16Target) {
|
||||||
searchIn.add(0, examplesDir.resolve("cx16"))
|
searchIn.add(0, assumeDirectory(examplesDir, "cx16"))
|
||||||
}
|
}
|
||||||
val filepath = searchIn.map { it.resolve("$name.p8") }.first { it.exists() }
|
val filepath = searchIn.map { it.resolve("$name.p8") }.first { it.exists() }
|
||||||
val displayName = "${examplesDir.relativize(filepath)}: ${platform.name}, optimize=$optimize"
|
val displayName = "${examplesDir.relativize(filepath)}: ${platform.name}, optimize=$optimize"
|
||||||
|
@ -26,17 +26,10 @@ import prog8.compiler.target.Cx16Target
|
|||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class TestCompilerOnImportsAndIncludes {
|
class TestCompilerOnImportsAndIncludes {
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
fun setUp() {
|
|
||||||
sanityCheckDirectories("compiler")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testImportFromSameFolder() {
|
fun testImportFromSameFolder() {
|
||||||
val filepath = fixturesDir.resolve("importFromSameFolder.p8")
|
val filepath = assumeReadableFile(fixturesDir, "importFromSameFolder.p8")
|
||||||
val imported = fixturesDir.resolve("foo_bar.p8")
|
assumeReadableFile(fixturesDir, "foo_bar.p8")
|
||||||
assumeReadableFile(filepath)
|
|
||||||
assumeReadableFile(imported)
|
|
||||||
|
|
||||||
val platform = Cx16Target
|
val platform = Cx16Target
|
||||||
val result = compileFile(platform, false, fixturesDir, filepath.name)
|
val result = compileFile(platform, false, fixturesDir, filepath.name)
|
||||||
@ -57,10 +50,8 @@ class TestCompilerOnImportsAndIncludes {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAsmIncludeFromSameFolder() {
|
fun testAsmIncludeFromSameFolder() {
|
||||||
val filepath = fixturesDir.resolve("asmIncludeFromSameFolder.p8")
|
val filepath = assumeReadableFile(fixturesDir, "asmIncludeFromSameFolder.p8")
|
||||||
val included = fixturesDir.resolve("foo_bar.asm")
|
assumeReadableFile(fixturesDir,"foo_bar.asm")
|
||||||
assumeReadableFile(filepath)
|
|
||||||
assumeReadableFile(included)
|
|
||||||
|
|
||||||
val platform = Cx16Target
|
val platform = Cx16Target
|
||||||
val result = compileFile(platform, false, fixturesDir, filepath.name)
|
val result = compileFile(platform, false, fixturesDir, filepath.name)
|
||||||
@ -84,10 +75,8 @@ class TestCompilerOnImportsAndIncludes {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAsmbinaryDirectiveWithNonExistingFile() {
|
fun testAsmbinaryDirectiveWithNonExistingFile() {
|
||||||
val p8Path = fixturesDir.resolve("asmbinaryNonExisting.p8")
|
val p8Path = assumeReadableFile(fixturesDir, "asmbinaryNonExisting.p8")
|
||||||
val binPath = fixturesDir.resolve("i_do_not_exist.bin")
|
assumeNotExists(fixturesDir,"i_do_not_exist.bin")
|
||||||
assumeReadableFile(p8Path)
|
|
||||||
assumeNotExists(binPath)
|
|
||||||
|
|
||||||
compileFile(Cx16Target, false, p8Path.parent, p8Path.name, outputDir)
|
compileFile(Cx16Target, false, p8Path.parent, p8Path.name, outputDir)
|
||||||
.assertFailure()
|
.assertFailure()
|
||||||
@ -95,10 +84,8 @@ class TestCompilerOnImportsAndIncludes {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAsmbinaryDirectiveWithNonReadableFile() {
|
fun testAsmbinaryDirectiveWithNonReadableFile() {
|
||||||
val p8Path = fixturesDir.resolve("asmbinaryNonReadable.p8")
|
val p8Path = assumeReadableFile(fixturesDir, "asmbinaryNonReadable.p8")
|
||||||
val binPath = fixturesDir.resolve("subFolder")
|
assumeDirectory(fixturesDir, "subFolder")
|
||||||
assumeReadableFile(p8Path)
|
|
||||||
assumeDirectory(binPath)
|
|
||||||
|
|
||||||
compileFile(Cx16Target, false, p8Path.parent, p8Path.name, outputDir)
|
compileFile(Cx16Target, false, p8Path.parent, p8Path.name, outputDir)
|
||||||
.assertFailure()
|
.assertFailure()
|
||||||
@ -111,8 +98,8 @@ class TestCompilerOnImportsAndIncludes {
|
|||||||
Triple("sub", "asmBinaryFromSubFolder.p8", "subFolder/do_nothing2.bin"),
|
Triple("sub", "asmBinaryFromSubFolder.p8", "subFolder/do_nothing2.bin"),
|
||||||
).map {
|
).map {
|
||||||
val (where, p8Str, binStr) = it
|
val (where, p8Str, binStr) = it
|
||||||
val p8Path = fixturesDir.resolve(p8Str)
|
val p8Path = fixturesDir.div(p8Str) // sanity check below, *inside dynamicTest*
|
||||||
val binPath = fixturesDir.resolve(binStr)
|
val binPath = fixturesDir.div(binStr)
|
||||||
val displayName = "%asmbinary from ${where}folder"
|
val displayName = "%asmbinary from ${where}folder"
|
||||||
dynamicTest(displayName) {
|
dynamicTest(displayName) {
|
||||||
assumeReadableFile(p8Path)
|
assumeReadableFile(p8Path)
|
||||||
|
@ -28,11 +28,6 @@ import prog8.compiler.target.Cx16Target
|
|||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class TestCompilerOnRanges {
|
class TestCompilerOnRanges {
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
fun setUp() {
|
|
||||||
sanityCheckDirectories("compiler")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testUByteArrayInitializerWithRange_char_to_char() {
|
fun testUByteArrayInitializerWithRange_char_to_char() {
|
||||||
val platform = Cx16Target
|
val platform = Cx16Target
|
||||||
@ -91,7 +86,7 @@ class TestCompilerOnRanges {
|
|||||||
assertEquals(expectedEnd - expectedStart + 1, rhsValues.size, "rangeExpr.size()")
|
assertEquals(expectedEnd - expectedStart + 1, rhsValues.size, "rangeExpr.size()")
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun Subroutine.decl(varName: String): VarDecl {
|
fun Subroutine.decl(varName: String): VarDecl {
|
||||||
return statements.filterIsInstance<VarDecl>()
|
return statements.filterIsInstance<VarDecl>()
|
||||||
.first { it.name == varName }
|
.first { it.name == varName }
|
||||||
}
|
}
|
||||||
@ -231,7 +226,7 @@ class TestCompilerOnRanges {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testForLoopWithRange_str_downto_str() {
|
fun testForLoopWithRange_str_downto_str() {
|
||||||
val result = compileText(Cx16Target, true, """
|
compileText(Cx16Target, true, """
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte i
|
ubyte i
|
||||||
|
@ -20,9 +20,7 @@ class TestModuleImporter {
|
|||||||
val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer)
|
val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer)
|
||||||
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
||||||
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
||||||
|
val srcPath = assumeNotExists(fixturesDir, "i_do_not_exist")
|
||||||
val srcPath = fixturesDir.resolve("i_do_not_exist")
|
|
||||||
assumeNotExists(srcPath)
|
|
||||||
|
|
||||||
assertFailsWith<NoSuchFileException> { importer.importModule(srcPath) }
|
assertFailsWith<NoSuchFileException> { importer.importModule(srcPath) }
|
||||||
}
|
}
|
||||||
@ -33,8 +31,7 @@ class TestModuleImporter {
|
|||||||
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
||||||
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
||||||
|
|
||||||
val srcPath = fixturesDir
|
val srcPath = assumeDirectory(fixturesDir)
|
||||||
assumeDirectory(srcPath)
|
|
||||||
|
|
||||||
// fn importModule(Path) used to check *.isReadable()*, but NOT .isRegularFile():
|
// fn importModule(Path) used to check *.isReadable()*, but NOT .isRegularFile():
|
||||||
assumeReadable(srcPath)
|
assumeReadable(srcPath)
|
||||||
@ -49,7 +46,7 @@ class TestModuleImporter {
|
|||||||
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
||||||
|
|
||||||
val filename = "file_with_syntax_error.p8"
|
val filename = "file_with_syntax_error.p8"
|
||||||
val path = fixturesDir.resolve(filename)
|
val path = assumeReadableFile(fixturesDir, filename)
|
||||||
val act = { importer.importModule(path) }
|
val act = { importer.importModule(path) }
|
||||||
|
|
||||||
assertFailsWith<ParseError> { act() }
|
assertFailsWith<ParseError> { act() }
|
||||||
@ -69,10 +66,8 @@ class TestModuleImporter {
|
|||||||
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
||||||
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
||||||
|
|
||||||
val importing = fixturesDir.resolve("import_file_with_syntax_error.p8")
|
val importing = assumeReadableFile(fixturesDir, "import_file_with_syntax_error.p8")
|
||||||
val imported = fixturesDir.resolve("file_with_syntax_error.p8")
|
val imported = assumeReadableFile(fixturesDir, "file_with_syntax_error.p8")
|
||||||
assumeReadableFile(importing)
|
|
||||||
assumeReadableFile(imported)
|
|
||||||
|
|
||||||
val act = { importer.importModule(importing) }
|
val act = { importer.importModule(importing) }
|
||||||
|
|
||||||
@ -93,12 +88,8 @@ class TestModuleImporter {
|
|||||||
val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer)
|
val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer)
|
||||||
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
||||||
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
||||||
val filenameNoExt = "i_do_not_exist"
|
val filenameNoExt = assumeNotExists(fixturesDir, "i_do_not_exist").name
|
||||||
val filenameWithExt = filenameNoExt + ".p8"
|
val filenameWithExt = assumeNotExists(fixturesDir, "i_do_not_exist.p8").name
|
||||||
val srcPathNoExt = fixturesDir.resolve(filenameNoExt)
|
|
||||||
val srcPathWithExt = fixturesDir.resolve(filenameWithExt)
|
|
||||||
assumeNotExists(srcPathNoExt)
|
|
||||||
assumeNotExists(srcPathWithExt)
|
|
||||||
|
|
||||||
assertFailsWith<NoSuchFileException> { importer.importLibraryModule(filenameNoExt) }
|
assertFailsWith<NoSuchFileException> { importer.importLibraryModule(filenameNoExt) }
|
||||||
assertFailsWith<NoSuchFileException> { importer.importLibraryModule(filenameWithExt) }
|
assertFailsWith<NoSuchFileException> { importer.importLibraryModule(filenameWithExt) }
|
||||||
@ -109,8 +100,7 @@ class TestModuleImporter {
|
|||||||
val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer)
|
val program = Program("foo", mutableListOf(), DummyFunctions, DummyMemsizer)
|
||||||
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
||||||
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
||||||
val srcPath = fixturesDir.resolve("file_with_syntax_error.p8")
|
val srcPath = assumeReadableFile(fixturesDir,"file_with_syntax_error.p8")
|
||||||
assumeReadableFile(srcPath)
|
|
||||||
|
|
||||||
val act = { importer.importLibraryModule(srcPath.nameWithoutExtension) }
|
val act = { importer.importLibraryModule(srcPath.nameWithoutExtension) }
|
||||||
|
|
||||||
@ -132,10 +122,8 @@ class TestModuleImporter {
|
|||||||
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
val searchIn = "./" + workingDir.relativize(fixturesDir).toString().replace("\\", "/")
|
||||||
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
val importer = ModuleImporter(program, "blah", listOf(searchIn))
|
||||||
|
|
||||||
val importing = fixturesDir.resolve("import_file_with_syntax_error.p8")
|
val importing = assumeReadableFile(fixturesDir, "import_file_with_syntax_error.p8")
|
||||||
val imported = fixturesDir.resolve("file_with_syntax_error.p8")
|
val imported = assumeReadableFile(fixturesDir,"file_with_syntax_error.p8")
|
||||||
assumeReadableFile(importing)
|
|
||||||
assumeReadableFile(imported)
|
|
||||||
|
|
||||||
val act = { importer.importLibraryModule(importing.nameWithoutExtension) }
|
val act = { importer.importLibraryModule(importing.nameWithoutExtension) }
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package prog8tests
|
package prog8tests
|
||||||
|
|
||||||
|
import prog8tests.helpers.*
|
||||||
import org.junit.jupiter.api.TestInstance
|
import org.junit.jupiter.api.TestInstance
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.Disabled
|
import org.junit.jupiter.api.Disabled
|
||||||
import org.junit.jupiter.api.BeforeAll
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import prog8tests.helpers.*
|
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
|
|
||||||
import prog8.parser.ParseError
|
import prog8.parser.ParseError
|
||||||
@ -20,11 +19,6 @@ import prog8.ast.expressions.*
|
|||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class TestProg8Parser {
|
class TestProg8Parser {
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
fun setUp() {
|
|
||||||
sanityCheckDirectories("compilerAst")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testModuleSourceNeedNotEndWithNewline() {
|
fun testModuleSourceNeedNotEndWithNewline() {
|
||||||
val nl = "\n" // say, Unix-style (different flavours tested elsewhere)
|
val nl = "\n" // say, Unix-style (different flavours tested elsewhere)
|
||||||
@ -166,11 +160,8 @@ class TestProg8Parser {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun parseModuleShouldNotLookAtImports() {
|
fun parseModuleShouldNotLookAtImports() {
|
||||||
val importedNoExt = fixturesDir.resolve("i_do_not_exist")
|
val importedNoExt = assumeNotExists(fixturesDir, "i_do_not_exist")
|
||||||
val importedWithExt = fixturesDir.resolve("i_do_not_exist.p8")
|
assumeNotExists(fixturesDir, "i_do_not_exist.p8")
|
||||||
assumeNotExists(importedNoExt)
|
|
||||||
assumeNotExists(importedWithExt)
|
|
||||||
|
|
||||||
val text = "%import ${importedNoExt.name}"
|
val text = "%import ${importedNoExt.name}"
|
||||||
val module = parseModule(SourceCode.of(text))
|
val module = parseModule(SourceCode.of(text))
|
||||||
|
|
||||||
@ -186,9 +177,7 @@ class TestProg8Parser {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testParseModuleWithEmptyFile() {
|
fun testParseModuleWithEmptyFile() {
|
||||||
val path = fixturesDir.resolve("empty.p8")
|
val path = assumeReadableFile(fixturesDir,"empty.p8")
|
||||||
assumeReadableFile(path)
|
|
||||||
|
|
||||||
val module = parseModule(SourceCode.fromPath(path))
|
val module = parseModule(SourceCode.fromPath(path))
|
||||||
assertEquals(0, module.statements.size)
|
assertEquals(0, module.statements.size)
|
||||||
}
|
}
|
||||||
@ -207,10 +196,8 @@ class TestProg8Parser {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testModuleNameForSourceFromPath() {
|
fun testModuleNameForSourceFromPath() {
|
||||||
val path = fixturesDir.resolve("simple_main.p8")
|
val path = assumeReadableFile(fixturesDir,"simple_main.p8")
|
||||||
|
|
||||||
val module = parseModule(SourceCode.fromPath(path))
|
val module = parseModule(SourceCode.fromPath(path))
|
||||||
|
|
||||||
assertEquals(path.nameWithoutExtension, module.name)
|
assertEquals(path.nameWithoutExtension, module.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +240,7 @@ class TestProg8Parser {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testErrorLocationForSourceFromPath() {
|
fun testErrorLocationForSourceFromPath() {
|
||||||
val path = fixturesDir.resolve("file_with_syntax_error.p8")
|
val path = assumeReadableFile(fixturesDir, "file_with_syntax_error.p8")
|
||||||
|
|
||||||
assertFailsWith<ParseError> { parseModule(SourceCode.fromPath(path)) }
|
assertFailsWith<ParseError> { parseModule(SourceCode.fromPath(path)) }
|
||||||
try {
|
try {
|
||||||
@ -275,7 +262,7 @@ class TestProg8Parser {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testModulePositionForSourceFromPath() {
|
fun testModulePositionForSourceFromPath() {
|
||||||
val path = fixturesDir.resolve("simple_main.p8")
|
val path = assumeReadableFile(fixturesDir,"simple_main.p8")
|
||||||
|
|
||||||
val module = parseModule(SourceCode.fromPath(path))
|
val module = parseModule(SourceCode.fromPath(path))
|
||||||
assertPositionOf(module, path.absolutePathString(), 1, 0) // TODO: endCol wrong
|
assertPositionOf(module, path.absolutePathString(), 1, 0) // TODO: endCol wrong
|
||||||
@ -283,7 +270,7 @@ class TestProg8Parser {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testInnerNodePositionsForSourceFromPath() {
|
fun testInnerNodePositionsForSourceFromPath() {
|
||||||
val path = fixturesDir.resolve("simple_main.p8")
|
val path = assumeReadableFile(fixturesDir,"simple_main.p8")
|
||||||
|
|
||||||
val module = parseModule(SourceCode.fromPath(path))
|
val module = parseModule(SourceCode.fromPath(path))
|
||||||
val mpf = module.position.file
|
val mpf = module.position.file
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package prog8tests
|
package prog8tests
|
||||||
|
|
||||||
|
import prog8tests.helpers.*
|
||||||
import org.junit.jupiter.api.TestInstance
|
import org.junit.jupiter.api.TestInstance
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.BeforeAll
|
|
||||||
import org.junit.jupiter.api.*
|
import org.junit.jupiter.api.*
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import prog8tests.helpers.*
|
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
|
|
||||||
import prog8.parser.SourceCode
|
import prog8.parser.SourceCode
|
||||||
@ -14,11 +13,6 @@ import prog8.parser.SourceCode
|
|||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
class TestSourceCode {
|
class TestSourceCode {
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
fun setUp() {
|
|
||||||
sanityCheckDirectories("compilerAst")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFactoryMethod_Of() {
|
fun testFactoryMethod_Of() {
|
||||||
val text = """
|
val text = """
|
||||||
@ -34,16 +28,14 @@ class TestSourceCode {
|
|||||||
@Test
|
@Test
|
||||||
fun testFromPathWithNonExistingPath() {
|
fun testFromPathWithNonExistingPath() {
|
||||||
val filename = "i_do_not_exist.p8"
|
val filename = "i_do_not_exist.p8"
|
||||||
val path = fixturesDir.resolve(filename)
|
val path = assumeNotExists(fixturesDir, filename)
|
||||||
assumeNotExists(path)
|
|
||||||
assertFailsWith<NoSuchFileException> { SourceCode.fromPath(path) }
|
assertFailsWith<NoSuchFileException> { SourceCode.fromPath(path) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFromPathWithMissingExtension_p8() {
|
fun testFromPathWithMissingExtension_p8() {
|
||||||
val pathWithoutExt = fixturesDir.resolve("simple_main")
|
val pathWithoutExt = assumeNotExists(fixturesDir,"simple_main")
|
||||||
val pathWithExt = Path(pathWithoutExt.toString() + ".p8")
|
assumeReadableFile(fixturesDir,"simple_main.p8")
|
||||||
assumeReadableFile(pathWithExt)
|
|
||||||
assertFailsWith<NoSuchFileException> { SourceCode.fromPath(pathWithoutExt) }
|
assertFailsWith<NoSuchFileException> { SourceCode.fromPath(pathWithoutExt) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,90 +47,75 @@ class TestSourceCode {
|
|||||||
@Test
|
@Test
|
||||||
fun testFromPathWithExistingPath() {
|
fun testFromPathWithExistingPath() {
|
||||||
val filename = "simple_main.p8"
|
val filename = "simple_main.p8"
|
||||||
val path = fixturesDir.resolve(filename)
|
val path = assumeReadableFile(fixturesDir, filename)
|
||||||
val src = SourceCode.fromPath(path)
|
val src = SourceCode.fromPath(path)
|
||||||
|
|
||||||
val expectedOrigin = path.normalize().absolutePathString()
|
val expectedOrigin = path.normalize().absolutePathString()
|
||||||
assertEquals(expectedOrigin, src.origin)
|
assertEquals(expectedOrigin, src.origin)
|
||||||
|
assertEquals(path.toFile().readText(), src.asString())
|
||||||
val expectedSrcText = path.toFile().readText()
|
|
||||||
val actualSrcText = src.getCharStream().toString()
|
|
||||||
assertEquals(expectedSrcText, actualSrcText)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFromPathWithExistingNonNormalizedPath() {
|
fun testFromPathWithExistingNonNormalizedPath() {
|
||||||
val filename = "simple_main.p8"
|
val filename = "simple_main.p8"
|
||||||
val path = Path(".", "test", "..", "test", "fixtures", filename)
|
val path = Path(".", "test", "..", "test", "fixtures", filename)
|
||||||
|
val srcFile = assumeReadableFile(path).toFile()
|
||||||
val src = SourceCode.fromPath(path)
|
val src = SourceCode.fromPath(path)
|
||||||
|
|
||||||
val expectedOrigin = path.normalize().absolutePathString()
|
val expectedOrigin = path.normalize().absolutePathString()
|
||||||
assertEquals(expectedOrigin, src.origin)
|
assertEquals(expectedOrigin, src.origin)
|
||||||
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
val expectedSrcText = path.toFile().readText()
|
|
||||||
val actualSrcText = src.getCharStream().toString()
|
|
||||||
assertEquals(expectedSrcText, actualSrcText)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFromResourcesWithExistingP8File_withoutLeadingSlash() {
|
fun testFromResourcesWithExistingP8File_withoutLeadingSlash() {
|
||||||
val pathString = "prog8lib/math.p8"
|
val pathString = "prog8lib/math.p8"
|
||||||
|
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@/$pathString", src.origin)
|
assertEquals("@embedded@/$pathString", src.origin)
|
||||||
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
val expectedSrcText = resourcesDir.resolve(pathString).toFile().readText()
|
|
||||||
val actualSrcText = src.asString()
|
|
||||||
assertEquals(expectedSrcText, actualSrcText)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFromResourcesWithExistingP8File_withLeadingSlash() {
|
fun testFromResourcesWithExistingP8File_withLeadingSlash() {
|
||||||
val pathString = "/prog8lib/math.p8"
|
val pathString = "/prog8lib/math.p8"
|
||||||
|
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@$pathString", src.origin)
|
assertEquals("@embedded@$pathString", src.origin)
|
||||||
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
val expectedSrcText = resourcesDir.resolve(pathString.substring(1)).toFile().readText()
|
|
||||||
val actualSrcText = src.asString()
|
|
||||||
assertEquals(expectedSrcText, actualSrcText)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFromResourcesWithExistingAsmFile_withoutLeadingSlash() {
|
fun testFromResourcesWithExistingAsmFile_withoutLeadingSlash() {
|
||||||
val pathString = "prog8lib/math.asm"
|
val pathString = "prog8lib/math.asm"
|
||||||
|
val srcFile = assumeReadableFile(resourcesDir, pathString).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@/$pathString", src.origin)
|
assertEquals("@embedded@/$pathString", src.origin)
|
||||||
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
val expectedSrcText = resourcesDir.resolve(pathString).toFile().readText()
|
|
||||||
val actualSrcText = src.asString()
|
|
||||||
assertEquals(expectedSrcText, actualSrcText)
|
|
||||||
assertTrue(src.isFromResources, ".isFromResources")
|
assertTrue(src.isFromResources, ".isFromResources")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFromResourcesWithExistingAsmFile_withLeadingSlash() {
|
fun testFromResourcesWithExistingAsmFile_withLeadingSlash() {
|
||||||
val pathString = "/prog8lib/math.asm"
|
val pathString = "/prog8lib/math.asm"
|
||||||
|
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@$pathString", src.origin)
|
assertEquals("@embedded@$pathString", src.origin)
|
||||||
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
val expectedSrcText = resourcesDir.resolve(pathString.substring(1)).toFile().readText()
|
|
||||||
val actualSrcText = src.asString()
|
|
||||||
assertEquals(expectedSrcText, actualSrcText)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFromResourcesWithNonNormalizedPath() {
|
fun testFromResourcesWithNonNormalizedPath() {
|
||||||
val pathString = "/prog8lib/../prog8lib/math.p8"
|
val pathString = "/prog8lib/../prog8lib/math.p8"
|
||||||
|
val srcFile = assumeReadableFile(resourcesDir, pathString.substring(1)).toFile()
|
||||||
val src = SourceCode.fromResources(pathString)
|
val src = SourceCode.fromResources(pathString)
|
||||||
|
|
||||||
assertEquals("@embedded@/prog8lib/math.p8", src.origin)
|
assertEquals("@embedded@/prog8lib/math.p8", src.origin)
|
||||||
|
assertEquals(srcFile.readText(), src.asString())
|
||||||
val expectedSrcText = resourcesDir.resolve(pathString.substring(1)).toFile().readText()
|
|
||||||
val actualSrcText = src.asString()
|
|
||||||
assertEquals(expectedSrcText, actualSrcText)
|
|
||||||
assertTrue(src.isFromResources, ".isFromResources")
|
assertTrue(src.isFromResources, ".isFromResources")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,15 +123,15 @@ class TestSourceCode {
|
|||||||
@Test
|
@Test
|
||||||
fun testFromResourcesWithNonExistingFile_withLeadingSlash() {
|
fun testFromResourcesWithNonExistingFile_withLeadingSlash() {
|
||||||
val pathString = "/prog8lib/i_do_not_exist"
|
val pathString = "/prog8lib/i_do_not_exist"
|
||||||
val resPath = resourcesDir.resolve(pathString.substring(1))
|
assumeNotExists(resourcesDir, pathString.substring(1))
|
||||||
assumeNotExists(resPath)
|
|
||||||
assertThrows<NoSuchFileException> { SourceCode.fromResources(pathString) }
|
assertThrows<NoSuchFileException> { SourceCode.fromResources(pathString) }
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
fun testFromResourcesWithNonExistingFile_withoutLeadingSlash() {
|
fun testFromResourcesWithNonExistingFile_withoutLeadingSlash() {
|
||||||
val pathString = "prog8lib/i_do_not_exist"
|
val pathString = "prog8lib/i_do_not_exist"
|
||||||
val resPath = resourcesDir.resolve(pathString)
|
assumeNotExists(resourcesDir, pathString)
|
||||||
assumeNotExists(resPath)
|
|
||||||
assertThrows<NoSuchFileException> { SourceCode.fromResources(pathString) }
|
assertThrows<NoSuchFileException> { SourceCode.fromResources(pathString) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,8 +139,8 @@ class TestSourceCode {
|
|||||||
@Disabled("TODO: inside resources: cannot tell apart a folder from a file")
|
@Disabled("TODO: inside resources: cannot tell apart a folder from a file")
|
||||||
fun testFromResourcesWithDirectory() {
|
fun testFromResourcesWithDirectory() {
|
||||||
val pathString = "/prog8lib"
|
val pathString = "/prog8lib"
|
||||||
|
assumeDirectory(resourcesDir, pathString.substring(1))
|
||||||
assertThrows<AccessDeniedException> { SourceCode.fromResources(pathString) }
|
assertThrows<AccessDeniedException> { SourceCode.fromResources(pathString) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,33 +6,46 @@ import kotlin.io.path.*
|
|||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
|
||||||
val workingDir = Path("").absolute() // Note: Path(".") does NOT work..!
|
val workingDir = assumeDirectory("").absolute() // Note: "." does NOT work..!
|
||||||
val fixturesDir = workingDir.resolve("test/fixtures")
|
val fixturesDir = assumeDirectory(workingDir,"test/fixtures")
|
||||||
val resourcesDir = workingDir.resolve("res")
|
val resourcesDir = assumeDirectory(workingDir,"res")
|
||||||
val outputDir = workingDir.resolve("build/tmp/test")
|
val outputDir = assumeDirectory(workingDir, "build/tmp/test")
|
||||||
|
|
||||||
fun assumeReadable(path: Path) {
|
fun assumeNotExists(path: Path): Path {
|
||||||
assertTrue(path.isReadable(), "sanity check: should be readable: ${path.absolute()}")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun assumeReadableFile(path: Path) {
|
|
||||||
assumeReadable(path)
|
|
||||||
assertTrue(path.isRegularFile(), "sanity check: should be normal file: ${path.absolute()}")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun assumeDirectory(path: Path) {
|
|
||||||
assertTrue(path.isDirectory(), "sanity check; should be directory: $path")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun assumeNotExists(path: Path) {
|
|
||||||
assertFalse(path.exists(), "sanity check: should not exist: ${path.absolute()}")
|
assertFalse(path.exists(), "sanity check: should not exist: ${path.absolute()}")
|
||||||
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sanityCheckDirectories(workingDirName: String? = null) {
|
fun assumeNotExists(pathStr: String): Path = assumeNotExists(Path(pathStr))
|
||||||
if (workingDirName != null)
|
fun assumeNotExists(path: Path, other: String): Path = assumeNotExists(path.div(other))
|
||||||
assertEquals(workingDirName, workingDir.fileName.toString(), "name of current working dir")
|
|
||||||
assumeDirectory(workingDir)
|
fun assumeReadable(path: Path): Path {
|
||||||
assumeDirectory(fixturesDir)
|
assertTrue(path.isReadable(), "sanity check: should be readable: ${path.absolute()}")
|
||||||
assumeDirectory(resourcesDir)
|
return path
|
||||||
assumeDirectory(outputDir)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun assumeReadableFile(path: Path): Path {
|
||||||
|
assertTrue(path.isRegularFile(), "sanity check: should be normal file: ${path.absolute()}")
|
||||||
|
return assumeReadable(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
assertTrue(path.isDirectory(), "sanity check; should be directory: $path")
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
fun assumeDirectory(pathStr: String): Path = assumeDirectory(Path(pathStr))
|
||||||
|
fun assumeDirectory(path: Path, other: String): Path = assumeDirectory(path.div(other))
|
||||||
|
|
||||||
|
|
||||||
|
@Deprecated("Directories are checked automatically at init.",
|
||||||
|
ReplaceWith("/* nothing */"))
|
||||||
|
@Suppress("unused")
|
||||||
|
fun sanityCheckDirectories(workingDirName: String? = null) {
|
||||||
|
}
|
311
compilerAst/test/helpers_pathsTests.kt
Normal file
311
compilerAst/test/helpers_pathsTests.kt
Normal file
@ -0,0 +1,311 @@
|
|||||||
|
package prog8tests
|
||||||
|
|
||||||
|
import prog8tests.helpers.*
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.TestInstance
|
||||||
|
import org.hamcrest.MatcherAssert.assertThat
|
||||||
|
import org.hamcrest.Matchers.*
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Nested
|
||||||
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
|
||||||
|
import kotlin.io.path.*
|
||||||
|
import kotlin.test.assertContains
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
|
class PathsHelpersTests {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class AssumeNotExists {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithOnePathArg {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnNonExistingPath() {
|
||||||
|
val path = fixturesDir.div("i_do_not_exist")
|
||||||
|
assertThat("should return the path",
|
||||||
|
assumeNotExists(path), `is`(path))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingFile() {
|
||||||
|
assertThrows<java.lang.AssertionError> {
|
||||||
|
assumeNotExists(fixturesDir.div("simple_main.p8"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingDirectory() {
|
||||||
|
assertThrows<java.lang.AssertionError> {
|
||||||
|
assumeNotExists(fixturesDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithOneStringArg {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnNonExistingPath() {
|
||||||
|
val path = fixturesDir.div("i_do_not_exist")
|
||||||
|
assertThat("should return the path",
|
||||||
|
assumeNotExists("$path"), `is`(path))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingFile() {
|
||||||
|
val path = fixturesDir.div("simple_main.p8")
|
||||||
|
assertThrows<java.lang.AssertionError> {
|
||||||
|
assumeNotExists("$path")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingDirectory() {
|
||||||
|
assertThrows<java.lang.AssertionError> {
|
||||||
|
assumeNotExists("$fixturesDir")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithPathAndStringArgs {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnNonExistingPath() {
|
||||||
|
val path = fixturesDir.div("i_do_not_exist")
|
||||||
|
assertThat("should return the path",
|
||||||
|
assumeNotExists(fixturesDir, "i_do_not_exist"), `is`(path))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingFile() {
|
||||||
|
assertThrows<java.lang.AssertionError> {
|
||||||
|
assumeNotExists(fixturesDir, "simple_main.p8")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingDirectory() {
|
||||||
|
assertThrows<java.lang.AssertionError> {
|
||||||
|
assumeNotExists(fixturesDir, "..")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class AssumeDirectory {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithOnePathArg {
|
||||||
|
@Test
|
||||||
|
fun testOnNonExistingPath() {
|
||||||
|
val path = fixturesDir.div("i_do_not_exist")
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeDirectory(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingFile() {
|
||||||
|
val path = fixturesDir.div("simple_main.p8")
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeDirectory(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingDirectory() {
|
||||||
|
val path = workingDir
|
||||||
|
assertThat("should return the path", assumeDirectory(path), `is`(path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithOneStringArg {
|
||||||
|
@Test
|
||||||
|
fun testOnNonExistingPath() {
|
||||||
|
val path = fixturesDir.div("i_do_not_exist")
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeDirectory("$path")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingFile() {
|
||||||
|
val path = fixturesDir.div("simple_main.p8")
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeDirectory("$path")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingDirectory() {
|
||||||
|
val path = workingDir
|
||||||
|
assertThat("should return the path",
|
||||||
|
assumeDirectory("$path"), `is`(path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithPathAndStringArgs {
|
||||||
|
@Test
|
||||||
|
fun testOnNonExistingPath() {
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeDirectory(fixturesDir, "i_do_not_exist")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingFile() {
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeDirectory(fixturesDir, "simple_main.p8")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnExistingDirectory() {
|
||||||
|
val path = workingDir.div("..")
|
||||||
|
assertThat(
|
||||||
|
"should return resulting path",
|
||||||
|
assumeDirectory(workingDir, ".."), `is`(path)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class AssumeReadableFile {
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithOnePathArg {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnNonExistingPath() {
|
||||||
|
val path = fixturesDir.div("i_do_not_exist")
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeReadableFile(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnReadableFile() {
|
||||||
|
val path = fixturesDir.div("simple_main.p8")
|
||||||
|
assertThat("should return the path",
|
||||||
|
assumeReadableFile(path), `is`(path))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnDirectory() {
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeReadableFile(fixturesDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithOneStringArg {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnNonExistingPath() {
|
||||||
|
val path = fixturesDir.div("i_do_not_exist")
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeReadableFile("$path")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnReadableFile() {
|
||||||
|
val path = fixturesDir.div("simple_main.p8")
|
||||||
|
assertThat("should return the resulting path",
|
||||||
|
assumeReadableFile("$path"), `is`(path))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnDirectory() {
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeReadableFile("$fixturesDir")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithPathAndStringArgs {
|
||||||
|
@Test
|
||||||
|
fun testOnNonexistingPath() {
|
||||||
|
assertThrows<java.lang.AssertionError> {
|
||||||
|
assumeReadableFile(fixturesDir, "i_do_not_exist")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnReadableFile() {
|
||||||
|
val path = fixturesDir.div("simple_main.p8")
|
||||||
|
assertThat("should return the resulting path",
|
||||||
|
assumeReadableFile(fixturesDir, "simple_main.p8"), `is`(path))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnDirectory() {
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeReadableFile(fixturesDir, "..")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithPathAndPathArgs {
|
||||||
|
@Test
|
||||||
|
fun testOnNonexistingPath() {
|
||||||
|
assertThrows<java.lang.AssertionError> {
|
||||||
|
assumeReadableFile(fixturesDir, Path("i_do_not_exist"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun testOnReadableFile() {
|
||||||
|
assertThat("should return the resulting path",
|
||||||
|
assumeReadableFile(fixturesDir, Path("simple_main.p8")),
|
||||||
|
`is`(fixturesDir.div("simple_main.p8"))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnDirectory() {
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeReadableFile(fixturesDir, Path(".."))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class WithStringAndStringArgs {
|
||||||
|
@Test
|
||||||
|
fun testOnNonexistingPath() {
|
||||||
|
assertThrows<java.lang.AssertionError> {
|
||||||
|
assumeReadableFile("$fixturesDir", "i_do_not_exist")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnReadableFile() {
|
||||||
|
assertThat("should return the resulting path",
|
||||||
|
assumeReadableFile(fixturesDir.toString(), "simple_main.p8"),
|
||||||
|
`is`(fixturesDir.div("simple_main.p8"))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testOnDirectory() {
|
||||||
|
assertThrows<AssertionError> {
|
||||||
|
assumeReadableFile("$fixturesDir", "..")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user