From 0498444ef2e52c03ef3dfb2a63db1a040110f32b Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 4 Dec 2021 18:20:22 +0100 Subject: [PATCH] moved all unit tests into single project to avoid dependency issues --- .idea/kotlinc.xml | 6 +++ .idea/libraries/hamcrest.xml | 10 ----- .idea/libraries/junit_jupiter.xml | 17 ------- codeGeneration/build.gradle | 20 +-------- codeGeneration/codeGeneration.iml | 5 +-- codeGeneration/readme-tests.txt | 2 + .../compiler/target/cpu6502/codegen/AsmGen.kt | 10 ++--- codeGeneration/test/ProjectConfig.kt | 8 ---- codeGeneration/test/helpers/Dummies.kt | 37 ---------------- .../test/helpers/ErrorReporterForTests.kt | 30 ------------- codeOptimizers/codeOptimizers.iml | 3 +- compiler/build.gradle | 1 + compiler/compiler.iml | 3 +- compiler/src/prog8/compiler/ModuleImporter.kt | 3 +- compiler/test/ModuleImporterTests.kt | 20 ++++----- compiler/test/TestCompilerOnExamples.kt | 2 +- .../test/TestCompilerOnImportsAndIncludes.kt | 2 +- compiler/test/TestCompilerOnRanges.kt | 3 +- compiler/test/TestCompilerOptionLibdirs.kt | 11 ++--- .../TestImportedModulesOrderAndOptions.kt | 2 +- .../test/ast}/TestAstToSourceText.kt | 6 +-- .../test/ast}/TestProg8Parser.kt | 17 ++++--- .../test => compiler/test/ast}/TestProgram.kt | 6 +-- .../test/ast}/TestSourceCode.kt | 14 +++--- .../test/ast}/TestSubroutines.kt | 0 .../codegeneration}/AsmGenSymbolsTests.kt | 10 ++--- .../test/fixtures/ast_empty.p8 | 0 .../fixtures/ast_file_with_syntax_error.p8 | 0 .../test/fixtures/ast_simple_main.p8 | 0 compiler/test/helpers/Dummies.kt | 8 ++++ compiler/test/helpers/compileXyz.kt | 4 +- .../test/helpers/mapCombinations.kt | 2 +- .../test/helpers/paths.kt | 2 +- .../test/helpers_pathsTests.kt | 32 +++++++------- compilerAst/build.gradle | 23 ---------- compilerAst/compilerAst.iml | 5 +-- compilerAst/readme-tests.txt | 2 + compilerAst/src/prog8/parser/SourceCode.kt | 2 +- compilerAst/test/ProjectConfig.kt | 8 ---- compilerAst/test/helpers/Dummies.kt | 44 ------------------- compilerInterfaces/compilerInterfaces.iml | 2 +- dbusCompilerService/dbusCompilerService.iml | 2 +- httpCompilerService/httpCompilerService.iml | 2 +- parser/parser.iml | 2 +- 44 files changed, 99 insertions(+), 289 deletions(-) create mode 100644 .idea/kotlinc.xml delete mode 100644 .idea/libraries/hamcrest.xml delete mode 100644 .idea/libraries/junit_jupiter.xml create mode 100644 codeGeneration/readme-tests.txt delete mode 100644 codeGeneration/test/ProjectConfig.kt delete mode 100644 codeGeneration/test/helpers/Dummies.kt delete mode 100644 codeGeneration/test/helpers/ErrorReporterForTests.kt rename {compilerAst/test => compiler/test/ast}/TestAstToSourceText.kt (95%) rename {compilerAst/test => compiler/test/ast}/TestProg8Parser.kt (98%) rename {compilerAst/test => compiler/test/ast}/TestProgram.kt (96%) rename {compilerAst/test => compiler/test/ast}/TestSourceCode.kt (93%) rename {compilerAst/test => compiler/test/ast}/TestSubroutines.kt (100%) rename {codeGeneration/test => compiler/test/codegeneration}/AsmGenSymbolsTests.kt (97%) rename compilerAst/test/fixtures/empty.p8 => compiler/test/fixtures/ast_empty.p8 (100%) rename compilerAst/test/fixtures/file_with_syntax_error.p8 => compiler/test/fixtures/ast_file_with_syntax_error.p8 (100%) rename compilerAst/test/fixtures/simple_main.p8 => compiler/test/fixtures/ast_simple_main.p8 (100%) rename {compilerAst => compiler}/test/helpers/mapCombinations.kt (98%) rename {compilerAst => compiler}/test/helpers/paths.kt (98%) rename {compilerAst => compiler}/test/helpers_pathsTests.kt (88%) create mode 100644 compilerAst/readme-tests.txt delete mode 100644 compilerAst/test/ProjectConfig.kt delete mode 100644 compilerAst/test/helpers/Dummies.kt diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 000000000..9b02d599e --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/hamcrest.xml b/.idea/libraries/hamcrest.xml deleted file mode 100644 index 3f07c43e5..000000000 --- a/.idea/libraries/hamcrest.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/junit_jupiter.xml b/.idea/libraries/junit_jupiter.xml deleted file mode 100644 index 6021a8070..000000000 --- a/.idea/libraries/junit_jupiter.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/codeGeneration/build.gradle b/codeGeneration/build.gradle index e4bc7d4a3..cffee9ed1 100644 --- a/codeGeneration/build.gradle +++ b/codeGeneration/build.gradle @@ -3,7 +3,6 @@ plugins { id 'java' id 'application' id "org.jetbrains.kotlin.jvm" - id "io.kotest" version "0.3.8" } java { @@ -19,7 +18,6 @@ dependencies { // implementation "org.jetbrains.kotlin:kotlin-reflect" implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12" - testImplementation 'io.kotest:kotest-runner-junit5-jvm:4.6.3' } sourceSets { @@ -31,22 +29,6 @@ sourceSets { srcDirs = ["${project.projectDir}/res"] } } - test { - java { - srcDirs = ["${project.projectDir}/test"] - } - } } - -test { - useJUnitPlatform() - - // Always run tests, even when nothing changed. - dependsOn 'cleanTest' - - // Show test results. - testLogging { - events "skipped", "failed" - } -} +// note: there are no unit tests in this module! diff --git a/codeGeneration/codeGeneration.iml b/codeGeneration/codeGeneration.iml index 173053009..4fb573763 100644 --- a/codeGeneration/codeGeneration.iml +++ b/codeGeneration/codeGeneration.iml @@ -4,16 +4,13 @@ - - + - - \ No newline at end of file diff --git a/codeGeneration/readme-tests.txt b/codeGeneration/readme-tests.txt new file mode 100644 index 000000000..b97671511 --- /dev/null +++ b/codeGeneration/readme-tests.txt @@ -0,0 +1,2 @@ +Unittests for things in this module are located in the Compiler module instead, +for convenience sake, and to not spread the test cases around too much. diff --git a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt index 3ce056bae..eff0f6055 100644 --- a/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt +++ b/codeGeneration/src/prog8/compiler/target/cpu6502/codegen/AsmGen.kt @@ -545,16 +545,16 @@ class AsmGen(private val program: Program, fun asmVariableName(identifier: IdentifierReference) = fixNameSymbols(identifier.nameInSource.joinToString(".")) - internal fun asmSymbolName(regs: RegisterOrPair): String = + fun asmSymbolName(regs: RegisterOrPair): String = if (regs in Cx16VirtualRegisters) "cx16." + regs.toString().lowercase() else throw AssemblyError("no symbol name for register $regs") - internal fun asmSymbolName(name: String) = fixNameSymbols(name) - internal fun asmVariableName(name: String) = fixNameSymbols(name) - internal fun asmSymbolName(name: Iterable) = fixNameSymbols(name.joinToString(".")) - internal fun asmVariableName(name: Iterable) = fixNameSymbols(name.joinToString(".")) + fun asmSymbolName(name: String) = fixNameSymbols(name) + fun asmVariableName(name: String) = fixNameSymbols(name) + fun asmSymbolName(name: Iterable) = fixNameSymbols(name.joinToString(".")) + fun asmVariableName(name: Iterable) = fixNameSymbols(name.joinToString(".")) internal fun loadByteFromPointerIntoA(pointervar: IdentifierReference): String { diff --git a/codeGeneration/test/ProjectConfig.kt b/codeGeneration/test/ProjectConfig.kt deleted file mode 100644 index 92399d615..000000000 --- a/codeGeneration/test/ProjectConfig.kt +++ /dev/null @@ -1,8 +0,0 @@ -package prog8tests.asmgen - -import io.kotest.core.config.AbstractProjectConfig -import kotlin.math.max - -object ProjectConfig : AbstractProjectConfig() { - override val parallelism = max(2, Runtime.getRuntime().availableProcessors() / 2) -} diff --git a/codeGeneration/test/helpers/Dummies.kt b/codeGeneration/test/helpers/Dummies.kt deleted file mode 100644 index bc06d2ab8..000000000 --- a/codeGeneration/test/helpers/Dummies.kt +++ /dev/null @@ -1,37 +0,0 @@ -package prog8tests.asmgen.helpers - -import prog8.ast.IBuiltinFunctions -import prog8.ast.base.Position -import prog8.ast.expressions.Expression -import prog8.ast.expressions.InferredTypes -import prog8.ast.expressions.NumericLiteralValue -import prog8.compilerinterface.IMemSizer -import prog8.ast.base.DataType -import prog8.compilerinterface.IStringEncoding - - -internal val DummyFunctions = object : IBuiltinFunctions { - override val names: Set = emptySet() - override val purefunctionNames: Set = emptySet() - override fun constValue( - name: String, - args: List, - position: Position, - ): NumericLiteralValue? = null - - override fun returnType(name: String, args: MutableList) = InferredTypes.InferredType.unknown() -} - -internal val DummyMemsizer = object : IMemSizer { - override fun memorySize(dt: DataType) = 0 -} - -internal val DummyStringEncoder = object : IStringEncoding { - override fun encodeString(str: String, altEncoding: Boolean): List { - return emptyList() - } - - override fun decodeString(bytes: List, altEncoding: Boolean): String { - return "" - } -} diff --git a/codeGeneration/test/helpers/ErrorReporterForTests.kt b/codeGeneration/test/helpers/ErrorReporterForTests.kt deleted file mode 100644 index c321c959f..000000000 --- a/codeGeneration/test/helpers/ErrorReporterForTests.kt +++ /dev/null @@ -1,30 +0,0 @@ -package prog8tests.asmgen.helpers - -import prog8.ast.base.Position -import prog8.compilerinterface.IErrorReporter - -internal class ErrorReporterForTests(private val throwExceptionAtReportIfErrors: Boolean=true): IErrorReporter { - - - val errors = mutableListOf() - val warnings = mutableListOf() - - override fun err(msg: String, position: Position) { - errors.add("${position.toClickableStr()} $msg") - } - - override fun warn(msg: String, position: Position) { - warnings.add("${position.toClickableStr()} $msg") - } - - override fun noErrors(): Boolean = errors.isEmpty() - - override fun report() { - warnings.forEach { println("UNITTEST COMPILATION REPORT: WARNING: $it") } - errors.forEach { println("UNITTEST COMPILATION REPORT: ERROR: $it") } - if(throwExceptionAtReportIfErrors) - finalizeNumErrors(errors.size, warnings.size) - errors.clear() - warnings.clear() - } -} diff --git a/codeOptimizers/codeOptimizers.iml b/codeOptimizers/codeOptimizers.iml index a6dcf5f56..a426d893e 100644 --- a/codeOptimizers/codeOptimizers.iml +++ b/codeOptimizers/codeOptimizers.iml @@ -4,10 +4,9 @@ - - + diff --git a/compiler/build.gradle b/compiler/build.gradle index 6f9a3f6ce..43b20e420 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -19,6 +19,7 @@ dependencies { implementation project(':codeOptimizers') implementation project(':compilerAst') implementation project(':codeGeneration') + implementation 'org.antlr:antlr4-runtime:4.9.2' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" // implementation "org.jetbrains.kotlin:kotlin-reflect" implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.3' diff --git a/compiler/compiler.iml b/compiler/compiler.iml index f431d54d5..9d0945b65 100644 --- a/compiler/compiler.iml +++ b/compiler/compiler.iml @@ -8,7 +8,7 @@ - + @@ -19,5 +19,6 @@ + \ No newline at end of file diff --git a/compiler/src/prog8/compiler/ModuleImporter.kt b/compiler/src/prog8/compiler/ModuleImporter.kt index 1bec0a81d..8c8d393dd 100644 --- a/compiler/src/prog8/compiler/ModuleImporter.kt +++ b/compiler/src/prog8/compiler/ModuleImporter.kt @@ -110,8 +110,7 @@ class ModuleImporter(private val program: Program, } ) - if(importedModule!=null) - removeDirectivesFromImportedModule(importedModule) + removeDirectivesFromImportedModule(importedModule) return importedModule } diff --git a/compiler/test/ModuleImporterTests.kt b/compiler/test/ModuleImporterTests.kt index f1c8fe56b..d2ec30790 100644 --- a/compiler/test/ModuleImporterTests.kt +++ b/compiler/test/ModuleImporterTests.kt @@ -8,11 +8,6 @@ import prog8.compiler.ModuleImporter import prog8.compilerinterface.IErrorReporter import prog8.parser.ParseError import prog8.parser.SourceCode -import prog8tests.ast.helpers.* -import prog8tests.helpers.ErrorReporterForTests -import prog8tests.helpers.DummyFunctions -import prog8tests.helpers.DummyMemsizer -import prog8tests.helpers.DummyStringEncoder import kotlin.io.path.* import io.kotest.assertions.fail import io.kotest.assertions.throwables.shouldThrow @@ -21,6 +16,11 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldBeIn import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain +import prog8tests.helpers.* +import prog8tests.helpers.DummyFunctions +import prog8tests.helpers.DummyMemsizer +import prog8tests.helpers.DummyStringEncoder +import prog8tests.helpers.ErrorReporterForTests class TestModuleImporter: FunSpec({ @@ -103,7 +103,7 @@ class TestModuleImporter: FunSpec({ Path(".").div(workingDir.relativize(fixturesDir)), // we do want a dot "." in front ).map { it.invariantSeparatorsPathString } val importer = makeImporter(null, searchIn) - val fileName = "simple_main.p8" + val fileName = "ast_simple_main.p8" val path = assumeReadableFile(searchIn[0], fileName) val module = importer.importModule(path.absolute()).getOrElse { throw it } @@ -117,7 +117,7 @@ class TestModuleImporter: FunSpec({ Path(".").div(workingDir.relativize(fixturesDir)), // we do want a dot "." in front ).map { it.invariantSeparatorsPathString } val importer = makeImporter(null, searchIn) - val fileName = "simple_main.p8" + val fileName = "ast_simple_main.p8" val path = assumeReadableFile(searchIn[0], fileName) withClue("sanity check: path should NOT be absolute") { path.isAbsolute shouldBe false @@ -134,7 +134,7 @@ class TestModuleImporter: FunSpec({ .div(workingDir.relativize(fixturesDir)) .invariantSeparatorsPathString val importer = makeImporter(null, searchIn) - val fileName = "simple_main.p8" + val fileName = "ast_simple_main.p8" val path = Path(".", fileName) assumeReadableFile(searchIn, path) @@ -148,7 +148,7 @@ class TestModuleImporter: FunSpec({ test("testWithSyntaxError") { val searchIn = assumeDirectory("./", workingDir.relativize(fixturesDir)) val importer = makeImporter(null, searchIn.invariantSeparatorsPathString) - val srcPath = assumeReadableFile(fixturesDir, "file_with_syntax_error.p8") + val srcPath = assumeReadableFile(fixturesDir, "ast_file_with_syntax_error.p8") val act = { importer.importModule(srcPath) } @@ -228,7 +228,7 @@ class TestModuleImporter: FunSpec({ test("testWithSyntaxError") { val searchIn = assumeDirectory("./", workingDir.relativize(fixturesDir)) val importer = makeImporter(null, searchIn.invariantSeparatorsPathString) - val srcPath = assumeReadableFile(fixturesDir, "file_with_syntax_error.p8") + val srcPath = assumeReadableFile(fixturesDir, "ast_file_with_syntax_error.p8") repeat(2) { n -> withClue(count[n] + " call") { shouldThrow() diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index d79831626..88ae2a70e 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -7,7 +7,7 @@ import prog8.compiler.compileProgram import prog8.compiler.target.C64Target import prog8.compiler.target.Cx16Target import prog8.compilerinterface.ICompilationTarget -import prog8tests.ast.helpers.* +import prog8tests.helpers.* import prog8tests.helpers.assertSuccess import java.nio.file.Path import kotlin.io.path.absolute diff --git a/compiler/test/TestCompilerOnImportsAndIncludes.kt b/compiler/test/TestCompilerOnImportsAndIncludes.kt index 6adbc7e1e..7bf6bf7cb 100644 --- a/compiler/test/TestCompilerOnImportsAndIncludes.kt +++ b/compiler/test/TestCompilerOnImportsAndIncludes.kt @@ -10,7 +10,7 @@ import prog8.ast.expressions.StringLiteralValue import prog8.ast.statements.FunctionCallStatement import prog8.ast.statements.Label import prog8.compiler.target.Cx16Target -import prog8tests.ast.helpers.* +import prog8tests.helpers.* import prog8tests.helpers.assertFailure import prog8tests.helpers.assertSuccess import prog8tests.helpers.compileFile diff --git a/compiler/test/TestCompilerOnRanges.kt b/compiler/test/TestCompilerOnRanges.kt index 401018f11..45972761b 100644 --- a/compiler/test/TestCompilerOnRanges.kt +++ b/compiler/test/TestCompilerOnRanges.kt @@ -10,12 +10,11 @@ import prog8.ast.base.Position import prog8.ast.expressions.* import prog8.ast.statements.ForLoop import prog8.ast.statements.VarDecl -import prog8.compiler.printProgram import prog8.compiler.target.C64Target import prog8.compiler.target.Cx16Target import prog8.compilerinterface.size import prog8.compilerinterface.toConstantIntegerRange -import prog8tests.ast.helpers.cartesianProduct +import prog8tests.helpers.* import prog8tests.helpers.ErrorReporterForTests import prog8tests.helpers.assertFailure import prog8tests.helpers.assertSuccess diff --git a/compiler/test/TestCompilerOptionLibdirs.kt b/compiler/test/TestCompilerOptionLibdirs.kt index 177362e8e..73e404eb3 100644 --- a/compiler/test/TestCompilerOptionLibdirs.kt +++ b/compiler/test/TestCompilerOptionLibdirs.kt @@ -5,10 +5,7 @@ import prog8.compiler.CompilationResult import prog8.compiler.CompilerArguments import prog8.compiler.compileProgram import prog8.compiler.target.Cx16Target -import prog8tests.ast.helpers.assumeReadableFile -import prog8tests.ast.helpers.fixturesDir -import prog8tests.ast.helpers.outputDir -import prog8tests.ast.helpers.workingDir +import prog8tests.helpers.* import prog8tests.helpers.assertSuccess import java.nio.file.Path import kotlin.io.path.absolute @@ -73,19 +70,19 @@ class TestCompilerOptionSourcedirs: FunSpec({ } test("testAbsoluteFilePathOutsideWorkingDir") { - val filepath = assumeReadableFile(fixturesDir, "simple_main.p8") + val filepath = assumeReadableFile(fixturesDir, "ast_simple_main.p8") compileFile(filepath.absolute(), listOf()) .assertSuccess() } test("testFilePathOutsideWorkingDirRelativeToWorkingDir") { - val filepath = workingDir.relativize(assumeReadableFile(fixturesDir, "simple_main.p8").absolute()) + val filepath = workingDir.relativize(assumeReadableFile(fixturesDir, "ast_simple_main.p8").absolute()) compileFile(filepath, listOf()) .assertSuccess() } test("testFilePathOutsideWorkingDirRelativeTo1stInSourcedirs") { - val filepath = assumeReadableFile(fixturesDir, "simple_main.p8") + val filepath = assumeReadableFile(fixturesDir, "ast_simple_main.p8") val sourcedirs = listOf("$fixturesDir") compileFile(filepath.fileName, sourcedirs) .assertSuccess() diff --git a/compiler/test/TestImportedModulesOrderAndOptions.kt b/compiler/test/TestImportedModulesOrderAndOptions.kt index 2ff78b96c..9e5e658b5 100644 --- a/compiler/test/TestImportedModulesOrderAndOptions.kt +++ b/compiler/test/TestImportedModulesOrderAndOptions.kt @@ -9,10 +9,10 @@ import prog8.compiler.determineCompilationOptions import prog8.compiler.parseImports import prog8.compiler.target.C64Target import prog8.compilerinterface.ZeropageType -import prog8tests.ast.helpers.outputDir import prog8tests.helpers.ErrorReporterForTests import prog8tests.helpers.assertSuccess import prog8tests.helpers.compileText +import prog8tests.helpers.outputDir class TestImportedModulesOrderAndOptions: FunSpec({ diff --git a/compilerAst/test/TestAstToSourceText.kt b/compiler/test/ast/TestAstToSourceText.kt similarity index 95% rename from compilerAst/test/TestAstToSourceText.kt rename to compiler/test/ast/TestAstToSourceText.kt index 2d78ce6ed..27edea169 100644 --- a/compilerAst/test/TestAstToSourceText.kt +++ b/compiler/test/ast/TestAstToSourceText.kt @@ -10,9 +10,9 @@ import prog8.ast.internedStringsModuleName import prog8.parser.ParseError import prog8.parser.Prog8Parser.parseModule import prog8.parser.SourceCode -import prog8tests.ast.helpers.DummyFunctions -import prog8tests.ast.helpers.DummyMemsizer -import prog8tests.ast.helpers.DummyStringEncoder +import prog8tests.helpers.DummyFunctions +import prog8tests.helpers.DummyMemsizer +import prog8tests.helpers.DummyStringEncoder class TestAstToSourceText: AnnotationSpec() { diff --git a/compilerAst/test/TestProg8Parser.kt b/compiler/test/ast/TestProg8Parser.kt similarity index 98% rename from compilerAst/test/TestProg8Parser.kt rename to compiler/test/ast/TestProg8Parser.kt index b8e160693..aeb070212 100644 --- a/compilerAst/test/TestProg8Parser.kt +++ b/compiler/test/ast/TestProg8Parser.kt @@ -21,9 +21,8 @@ import prog8.ast.statements.* import prog8.parser.ParseError import prog8.parser.Prog8Parser.parseModule import prog8.parser.SourceCode -import prog8tests.ast.helpers.* -import prog8tests.ast.helpers.DummyFunctions -import prog8tests.ast.helpers.DummyMemsizer +import prog8tests.helpers.* +import prog8tests.helpers.DummyFunctions import kotlin.io.path.Path import kotlin.io.path.isRegularFile import kotlin.io.path.name @@ -186,7 +185,7 @@ class TestProg8Parser: FunSpec( { } test("from an empty file should result in empty Module") { - val path = assumeReadableFile(fixturesDir, "empty.p8") + val path = assumeReadableFile(fixturesDir, "ast_empty.p8") val module = parseModule(SourceCode.File(path)) module.statements.size shouldBe 0 } @@ -205,7 +204,7 @@ class TestProg8Parser: FunSpec( { } test("parsed from a file") { - val path = assumeReadableFile(fixturesDir, "simple_main.p8") + val path = assumeReadableFile(fixturesDir, "ast_simple_main.p8") val module = parseModule(SourceCode.File(path)) module.name shouldBe path.nameWithoutExtension } @@ -268,7 +267,7 @@ class TestProg8Parser: FunSpec( { } test("in ParseError from bad file source code") { - val path = assumeReadableFile(fixturesDir, "file_with_syntax_error.p8") + val path = assumeReadableFile(fixturesDir, "ast_file_with_syntax_error.p8") val e = shouldThrow { parseModule(SourceCode.File(path)) } assertPosition(e.position, SourceCode.relative(path).toString(), 2, 6) @@ -284,13 +283,13 @@ class TestProg8Parser: FunSpec( { } test("of Module parsed from a file") { - val path = assumeReadableFile(fixturesDir, "simple_main.p8") + val path = assumeReadableFile(fixturesDir, "ast_simple_main.p8") val module = parseModule(SourceCode.File(path)) assertPositionOf(module, SourceCode.relative(path).toString(), 1, 0) } test("of non-root Nodes parsed from file") { - val path = assumeReadableFile(fixturesDir, "simple_main.p8") + val path = assumeReadableFile(fixturesDir, "ast_simple_main.p8") val module = parseModule(SourceCode.File(path)) val mpf = module.position.file @@ -354,7 +353,7 @@ class TestProg8Parser: FunSpec( { } test("isn't absolute for filesystem paths") { - val path = assumeReadableFile(fixturesDir, "simple_main.p8") + val path = assumeReadableFile(fixturesDir, "ast_simple_main.p8") val module = parseModule(SourceCode.File(path)) assertSomethingForAllNodes(module) { Path(it.position.file).isAbsolute shouldBe false diff --git a/compilerAst/test/TestProgram.kt b/compiler/test/ast/TestProgram.kt similarity index 96% rename from compilerAst/test/TestProgram.kt rename to compiler/test/ast/TestProgram.kt index cbb73e367..173fce518 100644 --- a/compilerAst/test/TestProgram.kt +++ b/compiler/test/ast/TestProgram.kt @@ -12,9 +12,9 @@ import prog8.ast.Program import prog8.ast.base.Position import prog8.ast.internedStringsModuleName import prog8.parser.SourceCode -import prog8tests.ast.helpers.DummyFunctions -import prog8tests.ast.helpers.DummyMemsizer -import prog8tests.ast.helpers.DummyStringEncoder +import prog8tests.helpers.DummyFunctions +import prog8tests.helpers.DummyMemsizer +import prog8tests.helpers.DummyStringEncoder class TestProgram: FunSpec({ diff --git a/compilerAst/test/TestSourceCode.kt b/compiler/test/ast/TestSourceCode.kt similarity index 93% rename from compilerAst/test/TestSourceCode.kt rename to compiler/test/ast/TestSourceCode.kt index 0035582ee..f34b8e0ab 100644 --- a/compilerAst/test/TestSourceCode.kt +++ b/compiler/test/ast/TestSourceCode.kt @@ -6,10 +6,10 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import prog8.parser.SourceCode import prog8.parser.SourceCode.Companion.libraryFilePrefix -import prog8tests.ast.helpers.assumeNotExists -import prog8tests.ast.helpers.assumeReadableFile -import prog8tests.ast.helpers.fixturesDir -import prog8tests.ast.helpers.resourcesDir +import prog8tests.helpers.assumeNotExists +import prog8tests.helpers.assumeReadableFile +import prog8tests.helpers.fixturesDir +import prog8tests.helpers.resourcesDir import kotlin.io.path.Path @@ -40,7 +40,7 @@ class TestSourceCode: AnnotationSpec() { @Test fun testFromPathWithMissingExtension_p8() { val pathWithoutExt = assumeNotExists(fixturesDir,"simple_main") - assumeReadableFile(fixturesDir,"simple_main.p8") + assumeReadableFile(fixturesDir,"ast_simple_main.p8") shouldThrow { SourceCode.File(pathWithoutExt) } } @@ -51,7 +51,7 @@ class TestSourceCode: AnnotationSpec() { @Test fun testFromPathWithExistingPath() { - val filename = "simple_main.p8" + val filename = "ast_simple_main.p8" val path = assumeReadableFile(fixturesDir, filename) val src = SourceCode.File(path) val expectedOrigin = SourceCode.relative(path).toString() @@ -63,7 +63,7 @@ class TestSourceCode: AnnotationSpec() { @Test fun testFromPathWithExistingNonNormalizedPath() { - val filename = "simple_main.p8" + val filename = "ast_simple_main.p8" val path = Path(".", "test", "..", "test", "fixtures", filename) val srcFile = assumeReadableFile(path).toFile() val src = SourceCode.File(path) diff --git a/compilerAst/test/TestSubroutines.kt b/compiler/test/ast/TestSubroutines.kt similarity index 100% rename from compilerAst/test/TestSubroutines.kt rename to compiler/test/ast/TestSubroutines.kt diff --git a/codeGeneration/test/AsmGenSymbolsTests.kt b/compiler/test/codegeneration/AsmGenSymbolsTests.kt similarity index 97% rename from codeGeneration/test/AsmGenSymbolsTests.kt rename to compiler/test/codegeneration/AsmGenSymbolsTests.kt index 4748ba7fd..eb0a8cc13 100644 --- a/codeGeneration/test/AsmGenSymbolsTests.kt +++ b/compiler/test/codegeneration/AsmGenSymbolsTests.kt @@ -1,4 +1,4 @@ -package prog8tests.asmgen +package prog8tests.codegeneration import io.kotest.assertions.withClue import io.kotest.core.spec.style.StringSpec @@ -15,10 +15,10 @@ import prog8.compiler.target.c64.C64MachineDefinition import prog8.compiler.target.cpu6502.codegen.AsmGen import prog8.compilerinterface.* import prog8.parser.SourceCode -import prog8tests.asmgen.helpers.DummyFunctions -import prog8tests.asmgen.helpers.DummyMemsizer -import prog8tests.asmgen.helpers.DummyStringEncoder -import prog8tests.asmgen.helpers.ErrorReporterForTests +import prog8tests.helpers.DummyFunctions +import prog8tests.helpers.DummyMemsizer +import prog8tests.helpers.DummyStringEncoder +import prog8tests.helpers.ErrorReporterForTests import java.nio.file.Path class AsmGenSymbolsTests: StringSpec({ diff --git a/compilerAst/test/fixtures/empty.p8 b/compiler/test/fixtures/ast_empty.p8 similarity index 100% rename from compilerAst/test/fixtures/empty.p8 rename to compiler/test/fixtures/ast_empty.p8 diff --git a/compilerAst/test/fixtures/file_with_syntax_error.p8 b/compiler/test/fixtures/ast_file_with_syntax_error.p8 similarity index 100% rename from compilerAst/test/fixtures/file_with_syntax_error.p8 rename to compiler/test/fixtures/ast_file_with_syntax_error.p8 diff --git a/compilerAst/test/fixtures/simple_main.p8 b/compiler/test/fixtures/ast_simple_main.p8 similarity index 100% rename from compilerAst/test/fixtures/simple_main.p8 rename to compiler/test/fixtures/ast_simple_main.p8 diff --git a/compiler/test/helpers/Dummies.kt b/compiler/test/helpers/Dummies.kt index 3ab6705c7..324c24669 100644 --- a/compiler/test/helpers/Dummies.kt +++ b/compiler/test/helpers/Dummies.kt @@ -34,3 +34,11 @@ internal val DummyStringEncoder = object : IStringEncoding { return "" } } + +internal val AsciiStringEncoder = object : IStringEncoding { + override fun encodeString(str: String, altEncoding: Boolean): List = str.map { it.code.toUByte() } + + override fun decodeString(bytes: List, altEncoding: Boolean): String { + return bytes.joinToString() + } +} diff --git a/compiler/test/helpers/compileXyz.kt b/compiler/test/helpers/compileXyz.kt index a17db2e11..ae7b99a58 100644 --- a/compiler/test/helpers/compileXyz.kt +++ b/compiler/test/helpers/compileXyz.kt @@ -10,8 +10,6 @@ import prog8.compiler.target.C64Target import prog8.compiler.target.c64.C64MachineDefinition import prog8.compiler.target.cpu6502.codegen.AsmGen import prog8.compilerinterface.* -import prog8tests.ast.helpers.assumeReadableFile -import prog8tests.ast.helpers.outputDir import java.nio.file.Path import kotlin.io.path.name @@ -39,7 +37,7 @@ internal fun compileFile( optimize: Boolean, fileDir: Path, fileName: String, - outputDir: Path = prog8tests.ast.helpers.outputDir, + outputDir: Path = prog8tests.helpers.outputDir, errors: IErrorReporter? = null, writeAssembly: Boolean = true, optFloatExpr: Boolean = true diff --git a/compilerAst/test/helpers/mapCombinations.kt b/compiler/test/helpers/mapCombinations.kt similarity index 98% rename from compilerAst/test/helpers/mapCombinations.kt rename to compiler/test/helpers/mapCombinations.kt index 23d86411b..e1757ba36 100644 --- a/compilerAst/test/helpers/mapCombinations.kt +++ b/compiler/test/helpers/mapCombinations.kt @@ -1,4 +1,4 @@ -package prog8tests.ast.helpers +package prog8tests.helpers fun cartesianProduct(c1: Collection, c2: Collection): Sequence> { return c1.flatMap { lhsElem -> c2.map { rhsElem -> lhsElem to rhsElem } }.asSequence() diff --git a/compilerAst/test/helpers/paths.kt b/compiler/test/helpers/paths.kt similarity index 98% rename from compilerAst/test/helpers/paths.kt rename to compiler/test/helpers/paths.kt index 07fd55cf3..df59785f7 100644 --- a/compilerAst/test/helpers/paths.kt +++ b/compiler/test/helpers/paths.kt @@ -1,4 +1,4 @@ -package prog8tests.ast.helpers +package prog8tests.helpers import io.kotest.assertions.withClue import io.kotest.matchers.shouldBe diff --git a/compilerAst/test/helpers_pathsTests.kt b/compiler/test/helpers_pathsTests.kt similarity index 88% rename from compilerAst/test/helpers_pathsTests.kt rename to compiler/test/helpers_pathsTests.kt index ca586dd53..e8f814ebc 100644 --- a/compilerAst/test/helpers_pathsTests.kt +++ b/compiler/test/helpers_pathsTests.kt @@ -1,10 +1,10 @@ -package prog8tests.ast +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 -import prog8tests.ast.helpers.* +import prog8tests.helpers.* import kotlin.io.path.Path import kotlin.io.path.div @@ -28,7 +28,7 @@ class PathsHelpersTests: FunSpec({ test("on existing file") { shouldThrow { - assumeNotExists(fixturesDir / "simple_main.p8") + assumeNotExists(fixturesDir / "ast_simple_main.p8") } } @@ -49,7 +49,7 @@ class PathsHelpersTests: FunSpec({ } test("on existing file") { - val path = fixturesDir / "simple_main.p8" + val path = fixturesDir / "ast_simple_main.p8" shouldThrow { assumeNotExists("$path") } @@ -73,7 +73,7 @@ class PathsHelpersTests: FunSpec({ test("on existing file") { shouldThrow { - assumeNotExists(fixturesDir, "simple_main.p8") + assumeNotExists(fixturesDir, "ast_simple_main.p8") } } @@ -96,7 +96,7 @@ class PathsHelpersTests: FunSpec({ } test("on existing file") { - val path = fixturesDir / "simple_main.p8" + val path = fixturesDir / "ast_simple_main.p8" shouldThrow { assumeDirectory(path) } @@ -119,7 +119,7 @@ class PathsHelpersTests: FunSpec({ } test("on existing file") { - val path = fixturesDir / "simple_main.p8" + val path = fixturesDir / "ast_simple_main.p8" shouldThrow { assumeDirectory("$path") } @@ -142,7 +142,7 @@ class PathsHelpersTests: FunSpec({ test("on existing file") { shouldThrow { - assumeDirectory(fixturesDir, "simple_main.p8") + assumeDirectory(fixturesDir, "ast_simple_main.p8") } } @@ -163,7 +163,7 @@ class PathsHelpersTests: FunSpec({ test("on existing file") { shouldThrow { - assumeDirectory("$fixturesDir", "simple_main.p8") + assumeDirectory("$fixturesDir", "ast_simple_main.p8") } } @@ -184,7 +184,7 @@ class PathsHelpersTests: FunSpec({ test("on existing file") { shouldThrow { - assumeDirectory("$fixturesDir", Path("simple_main.p8")) + assumeDirectory("$fixturesDir", Path("ast_simple_main.p8")) } } @@ -209,7 +209,7 @@ class PathsHelpersTests: FunSpec({ } test("on readable file") { - val path = fixturesDir / "simple_main.p8" + val path = fixturesDir / "ast_simple_main.p8" withClue("should return the path") { assumeReadableFile(path) shouldBe path } @@ -232,7 +232,7 @@ class PathsHelpersTests: FunSpec({ } test("on readable file") { - val path = fixturesDir / "simple_main.p8" + val path = fixturesDir / "ast_simple_main.p8" withClue("should return the resulting path") { assumeReadableFile("$path") shouldBe path } @@ -253,9 +253,9 @@ class PathsHelpersTests: FunSpec({ } test("on readable file") { - val path = fixturesDir / "simple_main.p8" + val path = fixturesDir / "ast_simple_main.p8" withClue("should return the resulting path") { - assumeReadableFile(fixturesDir / "simple_main.p8") shouldBe path + assumeReadableFile(fixturesDir / "ast_simple_main.p8") shouldBe path } } @@ -275,7 +275,7 @@ class PathsHelpersTests: FunSpec({ test("on readable file") { withClue("should return the resulting path") { - assumeReadableFile(fixturesDir / Path("simple_main.p8")) shouldBe fixturesDir / "simple_main.p8" + assumeReadableFile(fixturesDir / Path("ast_simple_main.p8")) shouldBe fixturesDir / "ast_simple_main.p8" } } @@ -295,7 +295,7 @@ class PathsHelpersTests: FunSpec({ test("on readable file") { withClue("should return the resulting path") { - assumeReadableFile(fixturesDir / "simple_main.p8") shouldBe fixturesDir / "simple_main.p8" + assumeReadableFile(fixturesDir / "ast_simple_main.p8") shouldBe fixturesDir / "ast_simple_main.p8" } } diff --git a/compilerAst/build.gradle b/compilerAst/build.gradle index 8990a513d..80330b28c 100644 --- a/compilerAst/build.gradle +++ b/compilerAst/build.gradle @@ -1,7 +1,6 @@ plugins { id "java" id "org.jetbrains.kotlin.jvm" - id "io.kotest" version "0.3.8" } java { @@ -14,8 +13,6 @@ dependencies { implementation 'org.antlr:antlr4-runtime:4.9.2' implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12" implementation project(':parser') - - testImplementation 'io.kotest:kotest-runner-junit5-jvm:4.6.3' } configurations.all { @@ -28,24 +25,4 @@ sourceSets { srcDirs = ["${project.projectDir}/src"] } } - test { - java { - srcDirs = ["${project.projectDir}/test"] - } - resources { - srcDirs = ["${project.projectDir}/res"] - } - } -} - -test { - useJUnitPlatform() - - // Always run tests, even when nothing changed. - dependsOn 'cleanTest' - - // Show test results. - testLogging { - events "skipped", "failed" - } } diff --git a/compilerAst/compilerAst.iml b/compilerAst/compilerAst.iml index c3fcfe1df..2aea16405 100644 --- a/compilerAst/compilerAst.iml +++ b/compilerAst/compilerAst.iml @@ -5,16 +5,13 @@ - - + - - \ No newline at end of file diff --git a/compilerAst/readme-tests.txt b/compilerAst/readme-tests.txt new file mode 100644 index 000000000..b97671511 --- /dev/null +++ b/compilerAst/readme-tests.txt @@ -0,0 +1,2 @@ +Unittests for things in this module are located in the Compiler module instead, +for convenience sake, and to not spread the test cases around too much. diff --git a/compilerAst/src/prog8/parser/SourceCode.kt b/compilerAst/src/prog8/parser/SourceCode.kt index e20dd9221..0382e27b3 100644 --- a/compilerAst/src/prog8/parser/SourceCode.kt +++ b/compilerAst/src/prog8/parser/SourceCode.kt @@ -72,7 +72,7 @@ sealed class SourceCode { override val isFromResources = false override val isFromFilesystem = false override val origin = "$stringSourcePrefix${System.identityHashCode(text).toString(16)}>" - override fun getCharStream(): CharStream = CharStreams.fromString(text, origin) + public override fun getCharStream(): CharStream = CharStreams.fromString(text, origin) override fun readText() = text } diff --git a/compilerAst/test/ProjectConfig.kt b/compilerAst/test/ProjectConfig.kt deleted file mode 100644 index b0799e39f..000000000 --- a/compilerAst/test/ProjectConfig.kt +++ /dev/null @@ -1,8 +0,0 @@ -package prog8tests.ast - -import io.kotest.core.config.AbstractProjectConfig -import kotlin.math.max - -object ProjectConfig : AbstractProjectConfig() { - override val parallelism = max(2, Runtime.getRuntime().availableProcessors() / 2) -} diff --git a/compilerAst/test/helpers/Dummies.kt b/compilerAst/test/helpers/Dummies.kt deleted file mode 100644 index d727601bf..000000000 --- a/compilerAst/test/helpers/Dummies.kt +++ /dev/null @@ -1,44 +0,0 @@ -package prog8tests.ast.helpers - -import prog8.ast.IBuiltinFunctions -import prog8.ast.base.DataType -import prog8.ast.base.Position -import prog8.ast.expressions.Expression -import prog8.ast.expressions.InferredTypes -import prog8.ast.expressions.NumericLiteralValue -import prog8.compilerinterface.IMemSizer -import prog8.compilerinterface.IStringEncoding - -internal val DummyFunctions = object : IBuiltinFunctions { - override val names: Set = emptySet() - override val purefunctionNames: Set = emptySet() - override fun constValue( - name: String, - args: List, - position: Position, - ): NumericLiteralValue? = null - - override fun returnType(name: String, args: MutableList) = InferredTypes.InferredType.unknown() -} - -internal val DummyMemsizer = object : IMemSizer { - override fun memorySize(dt: DataType) = 0 -} - -internal val DummyStringEncoder = object : IStringEncoding { - override fun encodeString(str: String, altEncoding: Boolean): List { - return emptyList() - } - - override fun decodeString(bytes: List, altEncoding: Boolean): String { - return "" - } -} - -internal val AsciiStringEncoder = object : IStringEncoding { - override fun encodeString(str: String, altEncoding: Boolean): List = str.map { it.code.toUByte() } - - override fun decodeString(bytes: List, altEncoding: Boolean): String { - return bytes.joinToString() - } -} diff --git a/compilerInterfaces/compilerInterfaces.iml b/compilerInterfaces/compilerInterfaces.iml index 949d98b7a..a78365fea 100644 --- a/compilerInterfaces/compilerInterfaces.iml +++ b/compilerInterfaces/compilerInterfaces.iml @@ -7,7 +7,7 @@ - + diff --git a/dbusCompilerService/dbusCompilerService.iml b/dbusCompilerService/dbusCompilerService.iml index 6cadef558..976d67c13 100644 --- a/dbusCompilerService/dbusCompilerService.iml +++ b/dbusCompilerService/dbusCompilerService.iml @@ -6,7 +6,7 @@ - + diff --git a/httpCompilerService/httpCompilerService.iml b/httpCompilerService/httpCompilerService.iml index e0bcb3d99..c46de14fa 100644 --- a/httpCompilerService/httpCompilerService.iml +++ b/httpCompilerService/httpCompilerService.iml @@ -6,7 +6,7 @@ - + diff --git a/parser/parser.iml b/parser/parser.iml index 685671dfd..619a0afcd 100644 --- a/parser/parser.iml +++ b/parser/parser.iml @@ -6,7 +6,7 @@ - +