moved all unit tests into single project to avoid dependency issues

This commit is contained in:
Irmen de Jong 2021-12-04 18:20:22 +01:00
parent ce3c34e458
commit 0498444ef2
44 changed files with 99 additions and 289 deletions

6
.idea/kotlinc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="11" />
</component>
</project>

View File

@ -1,10 +0,0 @@
<component name="libraryTable">
<library name="hamcrest" type="repository">
<properties maven-id="org.hamcrest:hamcrest:2.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -1,17 +0,0 @@
<component name="libraryTable">
<library name="junit.jupiter" type="repository">
<properties maven-id="org.junit.jupiter:junit-jupiter:5.7.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.7.2/junit-jupiter-5.7.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.7.2/junit-jupiter-api-5.7.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.7.2/junit-platform-commons-1.7.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.7.2/junit-jupiter-params-5.7.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.7.2/junit-jupiter-engine-5.7.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.7.2/junit-platform-engine-1.7.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -3,7 +3,6 @@ plugins {
id 'java' id 'java'
id 'application' id 'application'
id "org.jetbrains.kotlin.jvm" id "org.jetbrains.kotlin.jvm"
id "io.kotest" version "0.3.8"
} }
java { java {
@ -19,7 +18,6 @@ dependencies {
// implementation "org.jetbrains.kotlin:kotlin-reflect" // implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12" implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12"
testImplementation 'io.kotest:kotest-runner-junit5-jvm:4.6.3'
} }
sourceSets { sourceSets {
@ -31,22 +29,6 @@ sourceSets {
srcDirs = ["${project.projectDir}/res"] srcDirs = ["${project.projectDir}/res"]
} }
} }
test {
java {
srcDirs = ["${project.projectDir}/test"]
}
}
} }
// note: there are no unit tests in this module!
test {
useJUnitPlatform()
// Always run tests, even when nothing changed.
dependsOn 'cleanTest'
// Show test results.
testLogging {
events "skipped", "failed"
}
}

View File

@ -4,16 +4,13 @@
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build" /> <excludeFolder url="file://$MODULE_DIR$/build" />
</content> </content>
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" /> <orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="module" module-name="compilerInterfaces" /> <orderEntry type="module" module-name="compilerInterfaces" />
<orderEntry type="module" module-name="compilerAst" /> <orderEntry type="module" module-name="compilerAst" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
<orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" />
</component> </component>
</module> </module>

View File

@ -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.

View File

@ -545,16 +545,16 @@ class AsmGen(private val program: Program,
fun asmVariableName(identifier: IdentifierReference) = fun asmVariableName(identifier: IdentifierReference) =
fixNameSymbols(identifier.nameInSource.joinToString(".")) fixNameSymbols(identifier.nameInSource.joinToString("."))
internal fun asmSymbolName(regs: RegisterOrPair): String = fun asmSymbolName(regs: RegisterOrPair): String =
if (regs in Cx16VirtualRegisters) if (regs in Cx16VirtualRegisters)
"cx16." + regs.toString().lowercase() "cx16." + regs.toString().lowercase()
else else
throw AssemblyError("no symbol name for register $regs") throw AssemblyError("no symbol name for register $regs")
internal fun asmSymbolName(name: String) = fixNameSymbols(name) fun asmSymbolName(name: String) = fixNameSymbols(name)
internal fun asmVariableName(name: String) = fixNameSymbols(name) fun asmVariableName(name: String) = fixNameSymbols(name)
internal fun asmSymbolName(name: Iterable<String>) = fixNameSymbols(name.joinToString(".")) fun asmSymbolName(name: Iterable<String>) = fixNameSymbols(name.joinToString("."))
internal fun asmVariableName(name: Iterable<String>) = fixNameSymbols(name.joinToString(".")) fun asmVariableName(name: Iterable<String>) = fixNameSymbols(name.joinToString("."))
internal fun loadByteFromPointerIntoA(pointervar: IdentifierReference): String { internal fun loadByteFromPointerIntoA(pointervar: IdentifierReference): String {

View File

@ -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)
}

View File

@ -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<String> = emptySet()
override val purefunctionNames: Set<String> = emptySet()
override fun constValue(
name: String,
args: List<Expression>,
position: Position,
): NumericLiteralValue? = null
override fun returnType(name: String, args: MutableList<Expression>) = 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<UByte> {
return emptyList()
}
override fun decodeString(bytes: List<UByte>, altEncoding: Boolean): String {
return ""
}
}

View File

@ -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<String>()
val warnings = mutableListOf<String>()
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()
}
}

View File

@ -4,10 +4,9 @@
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build" /> <excludeFolder url="file://$MODULE_DIR$/build" />
</content> </content>
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="compilerInterfaces" /> <orderEntry type="module" module-name="compilerInterfaces" />

View File

@ -19,6 +19,7 @@ dependencies {
implementation project(':codeOptimizers') implementation project(':codeOptimizers')
implementation project(':compilerAst') implementation project(':compilerAst')
implementation project(':codeGeneration') implementation project(':codeGeneration')
implementation 'org.antlr:antlr4-runtime:4.9.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// implementation "org.jetbrains.kotlin:kotlin-reflect" // implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.3' implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.3'

View File

@ -8,7 +8,7 @@
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build" /> <excludeFolder url="file://$MODULE_DIR$/build" />
</content> </content>
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="compilerAst" /> <orderEntry type="module" module-name="compilerAst" />
@ -19,5 +19,6 @@
<orderEntry type="module" module-name="codeGeneration" /> <orderEntry type="module" module-name="codeGeneration" />
<orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" /> <orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" /> <orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
<orderEntry type="library" name="antlr.antlr4" level="project" />
</component> </component>
</module> </module>

View File

@ -110,8 +110,7 @@ class ModuleImporter(private val program: Program,
} }
) )
if(importedModule!=null) removeDirectivesFromImportedModule(importedModule)
removeDirectivesFromImportedModule(importedModule)
return importedModule return importedModule
} }

View File

@ -8,11 +8,6 @@ import prog8.compiler.ModuleImporter
import prog8.compilerinterface.IErrorReporter import prog8.compilerinterface.IErrorReporter
import prog8.parser.ParseError import prog8.parser.ParseError
import prog8.parser.SourceCode 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 kotlin.io.path.*
import io.kotest.assertions.fail import io.kotest.assertions.fail
import io.kotest.assertions.throwables.shouldThrow 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.collections.shouldBeIn
import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain 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({ class TestModuleImporter: FunSpec({
@ -103,7 +103,7 @@ class TestModuleImporter: FunSpec({
Path(".").div(workingDir.relativize(fixturesDir)), // we do want a dot "." in front Path(".").div(workingDir.relativize(fixturesDir)), // we do want a dot "." in front
).map { it.invariantSeparatorsPathString } ).map { it.invariantSeparatorsPathString }
val importer = makeImporter(null, searchIn) val importer = makeImporter(null, searchIn)
val fileName = "simple_main.p8" val fileName = "ast_simple_main.p8"
val path = assumeReadableFile(searchIn[0], fileName) val path = assumeReadableFile(searchIn[0], fileName)
val module = importer.importModule(path.absolute()).getOrElse { throw it } 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 Path(".").div(workingDir.relativize(fixturesDir)), // we do want a dot "." in front
).map { it.invariantSeparatorsPathString } ).map { it.invariantSeparatorsPathString }
val importer = makeImporter(null, searchIn) val importer = makeImporter(null, searchIn)
val fileName = "simple_main.p8" val fileName = "ast_simple_main.p8"
val path = assumeReadableFile(searchIn[0], fileName) val path = assumeReadableFile(searchIn[0], fileName)
withClue("sanity check: path should NOT be absolute") { withClue("sanity check: path should NOT be absolute") {
path.isAbsolute shouldBe false path.isAbsolute shouldBe false
@ -134,7 +134,7 @@ class TestModuleImporter: FunSpec({
.div(workingDir.relativize(fixturesDir)) .div(workingDir.relativize(fixturesDir))
.invariantSeparatorsPathString .invariantSeparatorsPathString
val importer = makeImporter(null, searchIn) val importer = makeImporter(null, searchIn)
val fileName = "simple_main.p8" val fileName = "ast_simple_main.p8"
val path = Path(".", fileName) val path = Path(".", fileName)
assumeReadableFile(searchIn, path) assumeReadableFile(searchIn, path)
@ -148,7 +148,7 @@ class TestModuleImporter: FunSpec({
test("testWithSyntaxError") { test("testWithSyntaxError") {
val searchIn = assumeDirectory("./", workingDir.relativize(fixturesDir)) val searchIn = assumeDirectory("./", workingDir.relativize(fixturesDir))
val importer = makeImporter(null, searchIn.invariantSeparatorsPathString) 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) } val act = { importer.importModule(srcPath) }
@ -228,7 +228,7 @@ class TestModuleImporter: FunSpec({
test("testWithSyntaxError") { test("testWithSyntaxError") {
val searchIn = assumeDirectory("./", workingDir.relativize(fixturesDir)) val searchIn = assumeDirectory("./", workingDir.relativize(fixturesDir))
val importer = makeImporter(null, searchIn.invariantSeparatorsPathString) 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") { repeat(2) { n -> withClue(count[n] + " call") {
shouldThrow<ParseError>() shouldThrow<ParseError>()

View File

@ -7,7 +7,7 @@ import prog8.compiler.compileProgram
import prog8.compiler.target.C64Target import prog8.compiler.target.C64Target
import prog8.compiler.target.Cx16Target import prog8.compiler.target.Cx16Target
import prog8.compilerinterface.ICompilationTarget import prog8.compilerinterface.ICompilationTarget
import prog8tests.ast.helpers.* import prog8tests.helpers.*
import prog8tests.helpers.assertSuccess import prog8tests.helpers.assertSuccess
import java.nio.file.Path import java.nio.file.Path
import kotlin.io.path.absolute import kotlin.io.path.absolute

View File

@ -10,7 +10,7 @@ import prog8.ast.expressions.StringLiteralValue
import prog8.ast.statements.FunctionCallStatement import prog8.ast.statements.FunctionCallStatement
import prog8.ast.statements.Label import prog8.ast.statements.Label
import prog8.compiler.target.Cx16Target import prog8.compiler.target.Cx16Target
import prog8tests.ast.helpers.* import prog8tests.helpers.*
import prog8tests.helpers.assertFailure import prog8tests.helpers.assertFailure
import prog8tests.helpers.assertSuccess import prog8tests.helpers.assertSuccess
import prog8tests.helpers.compileFile import prog8tests.helpers.compileFile

View File

@ -10,12 +10,11 @@ import prog8.ast.base.Position
import prog8.ast.expressions.* import prog8.ast.expressions.*
import prog8.ast.statements.ForLoop import prog8.ast.statements.ForLoop
import prog8.ast.statements.VarDecl import prog8.ast.statements.VarDecl
import prog8.compiler.printProgram
import prog8.compiler.target.C64Target import prog8.compiler.target.C64Target
import prog8.compiler.target.Cx16Target import prog8.compiler.target.Cx16Target
import prog8.compilerinterface.size import prog8.compilerinterface.size
import prog8.compilerinterface.toConstantIntegerRange import prog8.compilerinterface.toConstantIntegerRange
import prog8tests.ast.helpers.cartesianProduct import prog8tests.helpers.*
import prog8tests.helpers.ErrorReporterForTests import prog8tests.helpers.ErrorReporterForTests
import prog8tests.helpers.assertFailure import prog8tests.helpers.assertFailure
import prog8tests.helpers.assertSuccess import prog8tests.helpers.assertSuccess

View File

@ -5,10 +5,7 @@ import prog8.compiler.CompilationResult
import prog8.compiler.CompilerArguments import prog8.compiler.CompilerArguments
import prog8.compiler.compileProgram import prog8.compiler.compileProgram
import prog8.compiler.target.Cx16Target import prog8.compiler.target.Cx16Target
import prog8tests.ast.helpers.assumeReadableFile import prog8tests.helpers.*
import prog8tests.ast.helpers.fixturesDir
import prog8tests.ast.helpers.outputDir
import prog8tests.ast.helpers.workingDir
import prog8tests.helpers.assertSuccess import prog8tests.helpers.assertSuccess
import java.nio.file.Path import java.nio.file.Path
import kotlin.io.path.absolute import kotlin.io.path.absolute
@ -73,19 +70,19 @@ class TestCompilerOptionSourcedirs: FunSpec({
} }
test("testAbsoluteFilePathOutsideWorkingDir") { test("testAbsoluteFilePathOutsideWorkingDir") {
val filepath = assumeReadableFile(fixturesDir, "simple_main.p8") val filepath = assumeReadableFile(fixturesDir, "ast_simple_main.p8")
compileFile(filepath.absolute(), listOf()) compileFile(filepath.absolute(), listOf())
.assertSuccess() .assertSuccess()
} }
test("testFilePathOutsideWorkingDirRelativeToWorkingDir") { 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()) compileFile(filepath, listOf())
.assertSuccess() .assertSuccess()
} }
test("testFilePathOutsideWorkingDirRelativeTo1stInSourcedirs") { test("testFilePathOutsideWorkingDirRelativeTo1stInSourcedirs") {
val filepath = assumeReadableFile(fixturesDir, "simple_main.p8") val filepath = assumeReadableFile(fixturesDir, "ast_simple_main.p8")
val sourcedirs = listOf("$fixturesDir") val sourcedirs = listOf("$fixturesDir")
compileFile(filepath.fileName, sourcedirs) compileFile(filepath.fileName, sourcedirs)
.assertSuccess() .assertSuccess()

View File

@ -9,10 +9,10 @@ import prog8.compiler.determineCompilationOptions
import prog8.compiler.parseImports import prog8.compiler.parseImports
import prog8.compiler.target.C64Target import prog8.compiler.target.C64Target
import prog8.compilerinterface.ZeropageType import prog8.compilerinterface.ZeropageType
import prog8tests.ast.helpers.outputDir
import prog8tests.helpers.ErrorReporterForTests import prog8tests.helpers.ErrorReporterForTests
import prog8tests.helpers.assertSuccess import prog8tests.helpers.assertSuccess
import prog8tests.helpers.compileText import prog8tests.helpers.compileText
import prog8tests.helpers.outputDir
class TestImportedModulesOrderAndOptions: FunSpec({ class TestImportedModulesOrderAndOptions: FunSpec({

View File

@ -10,9 +10,9 @@ import prog8.ast.internedStringsModuleName
import prog8.parser.ParseError import prog8.parser.ParseError
import prog8.parser.Prog8Parser.parseModule import prog8.parser.Prog8Parser.parseModule
import prog8.parser.SourceCode import prog8.parser.SourceCode
import prog8tests.ast.helpers.DummyFunctions import prog8tests.helpers.DummyFunctions
import prog8tests.ast.helpers.DummyMemsizer import prog8tests.helpers.DummyMemsizer
import prog8tests.ast.helpers.DummyStringEncoder import prog8tests.helpers.DummyStringEncoder
class TestAstToSourceText: AnnotationSpec() { class TestAstToSourceText: AnnotationSpec() {

View File

@ -21,9 +21,8 @@ import prog8.ast.statements.*
import prog8.parser.ParseError import prog8.parser.ParseError
import prog8.parser.Prog8Parser.parseModule import prog8.parser.Prog8Parser.parseModule
import prog8.parser.SourceCode import prog8.parser.SourceCode
import prog8tests.ast.helpers.* import prog8tests.helpers.*
import prog8tests.ast.helpers.DummyFunctions import prog8tests.helpers.DummyFunctions
import prog8tests.ast.helpers.DummyMemsizer
import kotlin.io.path.Path import kotlin.io.path.Path
import kotlin.io.path.isRegularFile import kotlin.io.path.isRegularFile
import kotlin.io.path.name import kotlin.io.path.name
@ -186,7 +185,7 @@ class TestProg8Parser: FunSpec( {
} }
test("from an empty file should result in empty Module") { 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)) val module = parseModule(SourceCode.File(path))
module.statements.size shouldBe 0 module.statements.size shouldBe 0
} }
@ -205,7 +204,7 @@ class TestProg8Parser: FunSpec( {
} }
test("parsed from a file") { 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)) val module = parseModule(SourceCode.File(path))
module.name shouldBe path.nameWithoutExtension module.name shouldBe path.nameWithoutExtension
} }
@ -268,7 +267,7 @@ class TestProg8Parser: FunSpec( {
} }
test("in ParseError from bad file source code") { 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<ParseError> { parseModule(SourceCode.File(path)) } val e = shouldThrow<ParseError> { parseModule(SourceCode.File(path)) }
assertPosition(e.position, SourceCode.relative(path).toString(), 2, 6) assertPosition(e.position, SourceCode.relative(path).toString(), 2, 6)
@ -284,13 +283,13 @@ class TestProg8Parser: FunSpec( {
} }
test("of Module parsed from a file") { 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)) val module = parseModule(SourceCode.File(path))
assertPositionOf(module, SourceCode.relative(path).toString(), 1, 0) assertPositionOf(module, SourceCode.relative(path).toString(), 1, 0)
} }
test("of non-root Nodes parsed from file") { 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 module = parseModule(SourceCode.File(path))
val mpf = module.position.file val mpf = module.position.file
@ -354,7 +353,7 @@ class TestProg8Parser: FunSpec( {
} }
test("isn't absolute for filesystem paths") { 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)) val module = parseModule(SourceCode.File(path))
assertSomethingForAllNodes(module) { assertSomethingForAllNodes(module) {
Path(it.position.file).isAbsolute shouldBe false Path(it.position.file).isAbsolute shouldBe false

View File

@ -12,9 +12,9 @@ import prog8.ast.Program
import prog8.ast.base.Position import prog8.ast.base.Position
import prog8.ast.internedStringsModuleName import prog8.ast.internedStringsModuleName
import prog8.parser.SourceCode import prog8.parser.SourceCode
import prog8tests.ast.helpers.DummyFunctions import prog8tests.helpers.DummyFunctions
import prog8tests.ast.helpers.DummyMemsizer import prog8tests.helpers.DummyMemsizer
import prog8tests.ast.helpers.DummyStringEncoder import prog8tests.helpers.DummyStringEncoder
class TestProgram: FunSpec({ class TestProgram: FunSpec({

View File

@ -6,10 +6,10 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain import io.kotest.matchers.string.shouldContain
import prog8.parser.SourceCode import prog8.parser.SourceCode
import prog8.parser.SourceCode.Companion.libraryFilePrefix import prog8.parser.SourceCode.Companion.libraryFilePrefix
import prog8tests.ast.helpers.assumeNotExists import prog8tests.helpers.assumeNotExists
import prog8tests.ast.helpers.assumeReadableFile import prog8tests.helpers.assumeReadableFile
import prog8tests.ast.helpers.fixturesDir import prog8tests.helpers.fixturesDir
import prog8tests.ast.helpers.resourcesDir import prog8tests.helpers.resourcesDir
import kotlin.io.path.Path import kotlin.io.path.Path
@ -40,7 +40,7 @@ class TestSourceCode: AnnotationSpec() {
@Test @Test
fun testFromPathWithMissingExtension_p8() { fun testFromPathWithMissingExtension_p8() {
val pathWithoutExt = assumeNotExists(fixturesDir,"simple_main") val pathWithoutExt = assumeNotExists(fixturesDir,"simple_main")
assumeReadableFile(fixturesDir,"simple_main.p8") assumeReadableFile(fixturesDir,"ast_simple_main.p8")
shouldThrow<NoSuchFileException> { SourceCode.File(pathWithoutExt) } shouldThrow<NoSuchFileException> { SourceCode.File(pathWithoutExt) }
} }
@ -51,7 +51,7 @@ class TestSourceCode: AnnotationSpec() {
@Test @Test
fun testFromPathWithExistingPath() { fun testFromPathWithExistingPath() {
val filename = "simple_main.p8" val filename = "ast_simple_main.p8"
val path = assumeReadableFile(fixturesDir, filename) val path = assumeReadableFile(fixturesDir, filename)
val src = SourceCode.File(path) val src = SourceCode.File(path)
val expectedOrigin = SourceCode.relative(path).toString() val expectedOrigin = SourceCode.relative(path).toString()
@ -63,7 +63,7 @@ class TestSourceCode: AnnotationSpec() {
@Test @Test
fun testFromPathWithExistingNonNormalizedPath() { fun testFromPathWithExistingNonNormalizedPath() {
val filename = "simple_main.p8" val filename = "ast_simple_main.p8"
val path = Path(".", "test", "..", "test", "fixtures", filename) val path = Path(".", "test", "..", "test", "fixtures", filename)
val srcFile = assumeReadableFile(path).toFile() val srcFile = assumeReadableFile(path).toFile()
val src = SourceCode.File(path) val src = SourceCode.File(path)

View File

@ -1,4 +1,4 @@
package prog8tests.asmgen package prog8tests.codegeneration
import io.kotest.assertions.withClue import io.kotest.assertions.withClue
import io.kotest.core.spec.style.StringSpec 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.compiler.target.cpu6502.codegen.AsmGen
import prog8.compilerinterface.* import prog8.compilerinterface.*
import prog8.parser.SourceCode import prog8.parser.SourceCode
import prog8tests.asmgen.helpers.DummyFunctions import prog8tests.helpers.DummyFunctions
import prog8tests.asmgen.helpers.DummyMemsizer import prog8tests.helpers.DummyMemsizer
import prog8tests.asmgen.helpers.DummyStringEncoder import prog8tests.helpers.DummyStringEncoder
import prog8tests.asmgen.helpers.ErrorReporterForTests import prog8tests.helpers.ErrorReporterForTests
import java.nio.file.Path import java.nio.file.Path
class AsmGenSymbolsTests: StringSpec({ class AsmGenSymbolsTests: StringSpec({

View File

@ -34,3 +34,11 @@ internal val DummyStringEncoder = object : IStringEncoding {
return "" return ""
} }
} }
internal val AsciiStringEncoder = object : IStringEncoding {
override fun encodeString(str: String, altEncoding: Boolean): List<UByte> = str.map { it.code.toUByte() }
override fun decodeString(bytes: List<UByte>, altEncoding: Boolean): String {
return bytes.joinToString()
}
}

View File

@ -10,8 +10,6 @@ import prog8.compiler.target.C64Target
import prog8.compiler.target.c64.C64MachineDefinition import prog8.compiler.target.c64.C64MachineDefinition
import prog8.compiler.target.cpu6502.codegen.AsmGen import prog8.compiler.target.cpu6502.codegen.AsmGen
import prog8.compilerinterface.* import prog8.compilerinterface.*
import prog8tests.ast.helpers.assumeReadableFile
import prog8tests.ast.helpers.outputDir
import java.nio.file.Path import java.nio.file.Path
import kotlin.io.path.name import kotlin.io.path.name
@ -39,7 +37,7 @@ internal fun compileFile(
optimize: Boolean, optimize: Boolean,
fileDir: Path, fileDir: Path,
fileName: String, fileName: String,
outputDir: Path = prog8tests.ast.helpers.outputDir, outputDir: Path = prog8tests.helpers.outputDir,
errors: IErrorReporter? = null, errors: IErrorReporter? = null,
writeAssembly: Boolean = true, writeAssembly: Boolean = true,
optFloatExpr: Boolean = true optFloatExpr: Boolean = true

View File

@ -1,4 +1,4 @@
package prog8tests.ast.helpers package prog8tests.helpers
fun <T, U> cartesianProduct(c1: Collection<T>, c2: Collection<U>): Sequence<Pair<T, U>> { fun <T, U> cartesianProduct(c1: Collection<T>, c2: Collection<U>): Sequence<Pair<T, U>> {
return c1.flatMap { lhsElem -> c2.map { rhsElem -> lhsElem to rhsElem } }.asSequence() return c1.flatMap { lhsElem -> c2.map { rhsElem -> lhsElem to rhsElem } }.asSequence()

View File

@ -1,4 +1,4 @@
package prog8tests.ast.helpers package prog8tests.helpers
import io.kotest.assertions.withClue import io.kotest.assertions.withClue
import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldBe

View File

@ -1,10 +1,10 @@
package prog8tests.ast package prog8tests
import io.kotest.assertions.throwables.shouldThrow import io.kotest.assertions.throwables.shouldThrow
import io.kotest.assertions.withClue import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldBe
import prog8tests.ast.helpers.* import prog8tests.helpers.*
import kotlin.io.path.Path import kotlin.io.path.Path
import kotlin.io.path.div import kotlin.io.path.div
@ -28,7 +28,7 @@ class PathsHelpersTests: FunSpec({
test("on existing file") { test("on existing file") {
shouldThrow<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeNotExists(fixturesDir / "simple_main.p8") assumeNotExists(fixturesDir / "ast_simple_main.p8")
} }
} }
@ -49,7 +49,7 @@ class PathsHelpersTests: FunSpec({
} }
test("on existing file") { test("on existing file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "ast_simple_main.p8"
shouldThrow<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeNotExists("$path") assumeNotExists("$path")
} }
@ -73,7 +73,7 @@ class PathsHelpersTests: FunSpec({
test("on existing file") { test("on existing file") {
shouldThrow<java.lang.AssertionError> { shouldThrow<java.lang.AssertionError> {
assumeNotExists(fixturesDir, "simple_main.p8") assumeNotExists(fixturesDir, "ast_simple_main.p8")
} }
} }
@ -96,7 +96,7 @@ class PathsHelpersTests: FunSpec({
} }
test("on existing file") { test("on existing file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "ast_simple_main.p8"
shouldThrow<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory(path) assumeDirectory(path)
} }
@ -119,7 +119,7 @@ class PathsHelpersTests: FunSpec({
} }
test("on existing file") { test("on existing file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "ast_simple_main.p8"
shouldThrow<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory("$path") assumeDirectory("$path")
} }
@ -142,7 +142,7 @@ class PathsHelpersTests: FunSpec({
test("on existing file") { test("on existing file") {
shouldThrow<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory(fixturesDir, "simple_main.p8") assumeDirectory(fixturesDir, "ast_simple_main.p8")
} }
} }
@ -163,7 +163,7 @@ class PathsHelpersTests: FunSpec({
test("on existing file") { test("on existing file") {
shouldThrow<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory("$fixturesDir", "simple_main.p8") assumeDirectory("$fixturesDir", "ast_simple_main.p8")
} }
} }
@ -184,7 +184,7 @@ class PathsHelpersTests: FunSpec({
test("on existing file") { test("on existing file") {
shouldThrow<AssertionError> { shouldThrow<AssertionError> {
assumeDirectory("$fixturesDir", Path("simple_main.p8")) assumeDirectory("$fixturesDir", Path("ast_simple_main.p8"))
} }
} }
@ -209,7 +209,7 @@ class PathsHelpersTests: FunSpec({
} }
test("on readable file") { test("on readable file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "ast_simple_main.p8"
withClue("should return the path") { withClue("should return the path") {
assumeReadableFile(path) shouldBe path assumeReadableFile(path) shouldBe path
} }
@ -232,7 +232,7 @@ class PathsHelpersTests: FunSpec({
} }
test("on readable file") { test("on readable file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "ast_simple_main.p8"
withClue("should return the resulting path") { withClue("should return the resulting path") {
assumeReadableFile("$path") shouldBe path assumeReadableFile("$path") shouldBe path
} }
@ -253,9 +253,9 @@ class PathsHelpersTests: FunSpec({
} }
test("on readable file") { test("on readable file") {
val path = fixturesDir / "simple_main.p8" val path = fixturesDir / "ast_simple_main.p8"
withClue("should return the resulting path") { 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") { test("on readable file") {
withClue("should return the resulting path") { 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") { test("on readable file") {
withClue("should return the resulting path") { 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"
} }
} }

View File

@ -1,7 +1,6 @@
plugins { plugins {
id "java" id "java"
id "org.jetbrains.kotlin.jvm" id "org.jetbrains.kotlin.jvm"
id "io.kotest" version "0.3.8"
} }
java { java {
@ -14,8 +13,6 @@ dependencies {
implementation 'org.antlr:antlr4-runtime:4.9.2' implementation 'org.antlr:antlr4-runtime:4.9.2'
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12" implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.12"
implementation project(':parser') implementation project(':parser')
testImplementation 'io.kotest:kotest-runner-junit5-jvm:4.6.3'
} }
configurations.all { configurations.all {
@ -28,24 +25,4 @@ sourceSets {
srcDirs = ["${project.projectDir}/src"] 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"
}
} }

View File

@ -5,16 +5,13 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build" /> <excludeFolder url="file://$MODULE_DIR$/build" />
</content> </content>
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="parser" /> <orderEntry type="module" module-name="parser" />
<orderEntry type="library" name="antlr.antlr4" level="project" /> <orderEntry type="library" name="antlr.antlr4" level="project" />
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" /> <orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
</component> </component>
</module> </module>

View File

@ -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.

View File

@ -72,7 +72,7 @@ sealed class SourceCode {
override val isFromResources = false override val isFromResources = false
override val isFromFilesystem = false override val isFromFilesystem = false
override val origin = "$stringSourcePrefix${System.identityHashCode(text).toString(16)}>" 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 override fun readText() = text
} }

View File

@ -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)
}

View File

@ -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<String> = emptySet()
override val purefunctionNames: Set<String> = emptySet()
override fun constValue(
name: String,
args: List<Expression>,
position: Position,
): NumericLiteralValue? = null
override fun returnType(name: String, args: MutableList<Expression>) = 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<UByte> {
return emptyList()
}
override fun decodeString(bytes: List<UByte>, altEncoding: Boolean): String {
return ""
}
}
internal val AsciiStringEncoder = object : IStringEncoding {
override fun encodeString(str: String, altEncoding: Boolean): List<UByte> = str.map { it.code.toUByte() }
override fun decodeString(bytes: List<UByte>, altEncoding: Boolean): String {
return bytes.joinToString()
}
}

View File

@ -7,7 +7,7 @@
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build" /> <excludeFolder url="file://$MODULE_DIR$/build" />
</content> </content>
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="compilerAst" /> <orderEntry type="module" module-name="compilerAst" />

View File

@ -6,7 +6,7 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/build" /> <excludeFolder url="file://$MODULE_DIR$/build" />
</content> </content>
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="library" name="jetbrains.kotlinx.cli.jvm" level="project" /> <orderEntry type="library" name="jetbrains.kotlinx.cli.jvm" level="project" />

View File

@ -6,7 +6,7 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/build" /> <excludeFolder url="file://$MODULE_DIR$/build" />
</content> </content>
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module" module-name="compiler" /> <orderEntry type="module" module-name="compiler" />

View File

@ -6,7 +6,7 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/build" /> <excludeFolder url="file://$MODULE_DIR$/build" />
</content> </content>
<orderEntry type="jdk" jdkName="openjdk-11" jdkType="JavaSDK" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="antlr.antlr4" level="project" /> <orderEntry type="library" name="antlr.antlr4" level="project" />
</component> </component>