2021-06-28 16:42:05 +00:00
|
|
|
package prog8tests
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
import io.kotest.core.spec.style.FunSpec
|
2022-03-07 20:41:12 +00:00
|
|
|
import io.kotest.matchers.shouldNotBe
|
2022-03-11 18:54:30 +00:00
|
|
|
import prog8.code.core.ICompilationTarget
|
2022-03-11 19:35:25 +00:00
|
|
|
import prog8.code.target.C64Target
|
|
|
|
import prog8.code.target.Cx16Target
|
2021-11-30 00:40:21 +00:00
|
|
|
import prog8.compiler.CompilationResult
|
|
|
|
import prog8.compiler.CompilerArguments
|
2021-06-28 16:42:05 +00:00
|
|
|
import prog8.compiler.compileProgram
|
2022-06-26 16:51:03 +00:00
|
|
|
import prog8tests.helpers.assumeDirectory
|
|
|
|
import prog8tests.helpers.cartesianProduct
|
|
|
|
import prog8tests.helpers.outputDir
|
|
|
|
import prog8tests.helpers.workingDir
|
2021-11-07 23:16:58 +00:00
|
|
|
import java.nio.file.Path
|
2021-10-10 22:22:04 +00:00
|
|
|
import kotlin.io.path.absolute
|
|
|
|
import kotlin.io.path.exists
|
2021-06-28 16:42:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ATTENTION: this is just kludge!
|
|
|
|
* They are not really unit tests, but rather tests of the whole process,
|
|
|
|
* from source file loading all the way through to running 64tass.
|
|
|
|
*/
|
2021-11-07 23:16:58 +00:00
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
private val examplesDir = assumeDirectory(workingDir, "../examples")
|
2021-11-07 23:16:58 +00:00
|
|
|
|
2022-03-07 20:41:12 +00:00
|
|
|
private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilationTarget): CompilationResult? {
|
2021-11-30 00:40:21 +00:00
|
|
|
val args = CompilerArguments(
|
|
|
|
filepath,
|
|
|
|
optimize,
|
|
|
|
optimizeFloatExpressions = true,
|
2022-01-01 15:35:36 +00:00
|
|
|
dontReinitGlobals = false,
|
2021-11-30 00:40:21 +00:00
|
|
|
writeAssembly = true,
|
|
|
|
slowCodegenWarnings = false,
|
|
|
|
quietAssembler = true,
|
2021-12-30 13:38:40 +00:00
|
|
|
asmListfile = false,
|
2022-02-05 20:25:19 +00:00
|
|
|
experimentalCodegen = false,
|
2021-11-30 00:40:21 +00:00
|
|
|
compilationTarget = target.name,
|
2022-07-06 21:40:36 +00:00
|
|
|
symbolDefs = emptyMap(),
|
2022-06-26 16:51:03 +00:00
|
|
|
outputDir = outputDir
|
2021-11-30 00:40:21 +00:00
|
|
|
)
|
|
|
|
return compileProgram(args)
|
|
|
|
}
|
2021-11-07 23:16:58 +00:00
|
|
|
|
|
|
|
private fun prepareTestFiles(source: String, optimize: Boolean, target: ICompilationTarget): Pair<String, Path> {
|
|
|
|
val searchIn = mutableListOf(examplesDir)
|
2022-02-06 20:29:06 +00:00
|
|
|
if (target is Cx16Target) {
|
2022-06-26 16:51:03 +00:00
|
|
|
searchIn.add(0, assumeDirectory(examplesDir, "cx16"))
|
2021-06-28 16:42:05 +00:00
|
|
|
}
|
2022-01-10 22:15:24 +00:00
|
|
|
val filepath = searchIn.asSequence()
|
2021-11-07 23:16:58 +00:00
|
|
|
.map { it.resolve("$source.p8") }
|
|
|
|
.map { it.normalize().absolute() }
|
2022-06-26 16:51:03 +00:00
|
|
|
.map { workingDir.relativize(it) }
|
2021-11-07 23:16:58 +00:00
|
|
|
.first { it.exists() }
|
|
|
|
val displayName = "${examplesDir.relativize(filepath.absolute())}: ${target.name}, optimize=$optimize"
|
|
|
|
return Pair(displayName, filepath)
|
|
|
|
}
|
2021-06-28 16:42:05 +00:00
|
|
|
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
class TestCompilerOnExamplesC64: FunSpec({
|
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
val onlyC64 = cartesianProduct(
|
2021-11-07 23:16:58 +00:00
|
|
|
listOf(
|
2021-07-17 08:37:58 +00:00
|
|
|
"balloonflight",
|
|
|
|
"bdmusic",
|
|
|
|
"bdmusic-irq",
|
|
|
|
"charset",
|
|
|
|
"cube3d-sprites",
|
|
|
|
"plasma",
|
|
|
|
"sprites",
|
|
|
|
"turtle-gfx",
|
|
|
|
"wizzine",
|
|
|
|
),
|
2021-11-07 23:16:58 +00:00
|
|
|
listOf(false, true)
|
2021-07-17 08:37:58 +00:00
|
|
|
)
|
2021-06-28 16:42:05 +00:00
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
onlyC64.forEach {
|
|
|
|
val (source, optimize) = it
|
2022-02-06 20:29:06 +00:00
|
|
|
val target = C64Target()
|
|
|
|
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
|
2021-11-07 23:16:58 +00:00
|
|
|
test(displayName) {
|
2022-03-07 20:41:12 +00:00
|
|
|
compileTheThing(filepath, optimize, target) shouldNotBe null
|
2021-11-07 23:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
class TestCompilerOnExamplesCx16: FunSpec({
|
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
val onlyCx16 = cartesianProduct(
|
2021-11-07 23:16:58 +00:00
|
|
|
listOf(
|
2021-07-17 08:37:58 +00:00
|
|
|
"vtui/testvtui",
|
|
|
|
"amiga",
|
2022-07-09 13:40:56 +00:00
|
|
|
"bdmusic",
|
2021-07-17 08:37:58 +00:00
|
|
|
"bobs",
|
|
|
|
"cobramk3-gfx",
|
|
|
|
"colorbars",
|
|
|
|
"datetime",
|
|
|
|
"highresbitmap",
|
|
|
|
"kefrenbars",
|
2022-07-09 13:40:56 +00:00
|
|
|
"mandelbrot",
|
2021-07-17 08:37:58 +00:00
|
|
|
"mandelbrot-gfx-colors",
|
|
|
|
"multipalette",
|
2021-11-09 22:36:47 +00:00
|
|
|
"rasterbars",
|
|
|
|
"sincos",
|
|
|
|
"tehtriz",
|
2021-07-17 08:37:58 +00:00
|
|
|
"testgfx2",
|
|
|
|
),
|
2021-11-07 23:16:58 +00:00
|
|
|
listOf(false, true)
|
2021-07-17 08:37:58 +00:00
|
|
|
)
|
2021-11-07 23:16:58 +00:00
|
|
|
|
|
|
|
onlyCx16.forEach {
|
|
|
|
val (source, optimize) = it
|
2022-02-06 20:29:06 +00:00
|
|
|
val target = Cx16Target()
|
|
|
|
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
|
2021-11-07 23:16:58 +00:00
|
|
|
test(displayName) {
|
2022-03-07 20:41:12 +00:00
|
|
|
compileTheThing(filepath, optimize, target) shouldNotBe null
|
2021-11-07 23:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
class TestCompilerOnExamplesBothC64andCx16: FunSpec({
|
|
|
|
|
2022-06-26 16:51:03 +00:00
|
|
|
val bothCx16AndC64 = cartesianProduct(
|
2021-11-07 23:16:58 +00:00
|
|
|
listOf(
|
|
|
|
"animals",
|
|
|
|
"balls",
|
|
|
|
"cube3d",
|
|
|
|
"cube3d-float",
|
|
|
|
"cube3d-gfx",
|
|
|
|
"cxlogo",
|
|
|
|
"dirlist",
|
|
|
|
"fibonacci",
|
|
|
|
"line-circle-gfx",
|
|
|
|
"line-circle-txt",
|
2022-07-09 13:40:56 +00:00
|
|
|
"maze",
|
2021-11-07 23:16:58 +00:00
|
|
|
"mandelbrot",
|
|
|
|
"mandelbrot-gfx",
|
|
|
|
"numbergame",
|
|
|
|
"primes",
|
|
|
|
"rasterbars",
|
|
|
|
"screencodes",
|
|
|
|
"sorting",
|
|
|
|
"swirl",
|
|
|
|
"swirl-float",
|
|
|
|
"tehtriz",
|
|
|
|
"textelite",
|
|
|
|
),
|
|
|
|
listOf(false, true)
|
|
|
|
)
|
|
|
|
|
|
|
|
bothCx16AndC64.forEach {
|
|
|
|
val (source, optimize) = it
|
2022-02-06 20:29:06 +00:00
|
|
|
val c64target = C64Target()
|
|
|
|
val cx16target = Cx16Target()
|
|
|
|
val (displayNameC64, filepathC64) = prepareTestFiles(source, optimize, c64target)
|
|
|
|
val (displayNameCx16, filepathCx16) = prepareTestFiles(source, optimize, cx16target)
|
2021-11-07 23:16:58 +00:00
|
|
|
test(displayNameC64) {
|
2022-03-07 20:41:12 +00:00
|
|
|
compileTheThing(filepathC64, optimize, c64target) shouldNotBe null
|
2021-11-07 23:16:58 +00:00
|
|
|
}
|
|
|
|
test(displayNameCx16) {
|
2022-03-07 20:41:12 +00:00
|
|
|
compileTheThing(filepathCx16, optimize, cx16target) shouldNotBe null
|
2021-11-07 23:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|