prog8/compiler/test/TestCompilerOnExamples.kt

205 lines
5.9 KiB
Kotlin
Raw Normal View History

package prog8tests
import io.kotest.core.spec.style.FunSpec
2022-03-07 21:41:12 +01:00
import io.kotest.matchers.shouldNotBe
2022-03-11 19:54:30 +01:00
import prog8.code.core.ICompilationTarget
import prog8.code.target.*
2021-11-30 01:40:21 +01:00
import prog8.compiler.CompilationResult
import prog8.compiler.CompilerArguments
import prog8.compiler.compileProgram
import prog8tests.helpers.*
import java.nio.file.Path
2021-10-11 00:22:04 +02:00
import kotlin.io.path.absolute
import kotlin.io.path.exists
import kotlin.io.path.readText
/**
* 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.
*/
2022-06-26 18:51:03 +02:00
private val examplesDir = assumeDirectory(workingDir, "../examples")
2022-03-07 21:41:12 +01:00
private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilationTarget): CompilationResult? {
2021-11-30 01:40:21 +01:00
val args = CompilerArguments(
filepath,
optimize,
writeAssembly = true,
warnSymbolShadowing = false,
2021-11-30 01:40:21 +01:00
quietAssembler = true,
asmListfile = false,
includeSourcelines = false,
experimentalCodegen = false,
2023-06-27 00:27:34 +02:00
varsHighBank = null,
2021-11-30 01:40:21 +01:00
compilationTarget = target.name,
2023-05-30 19:08:34 +02:00
splitWordArrays = false,
2023-10-15 21:55:09 +02:00
breakpointCpuInstruction = false,
symbolDefs = emptyMap(),
2022-06-26 18:51:03 +02:00
outputDir = outputDir
2021-11-30 01:40:21 +01:00
)
return compileProgram(args)
}
private fun prepareTestFiles(source: String, optimize: Boolean, target: ICompilationTarget): Pair<String, Path> {
val searchIn = mutableListOf(examplesDir)
when (target) {
2023-06-03 21:39:34 +02:00
is C64Target -> searchIn.add(0, assumeDirectory(examplesDir, "c64"))
is Cx16Target -> searchIn.add(0, assumeDirectory(examplesDir, "cx16"))
is VMTarget -> searchIn.add(0, assumeDirectory(examplesDir, "vm"))
is C128Target -> searchIn.add(0, assumeDirectory(examplesDir, "c128"))
is AtariTarget -> searchIn.add(0, assumeDirectory(examplesDir, "atari"))
}
val filepath = searchIn.asSequence()
.map { it.resolve("$source.p8") }
.map { it.normalize().absolute() }
2022-06-26 18:51:03 +02:00
.map { workingDir.relativize(it) }
.first { it.exists() }
val displayName = "${examplesDir.relativize(filepath.absolute())}: ${target.name}, optimize=$optimize"
return Pair(displayName, filepath)
}
class TestCompilerOnExamplesC64: FunSpec({
2022-06-26 18:51:03 +02:00
val onlyC64 = cartesianProduct(
listOf(
"balloonflight",
"bdmusic",
"bdmusic-irq",
"charset",
2023-06-03 21:39:34 +02:00
"cube3d",
"cube3d-sprites",
"plasma",
2023-06-03 21:39:34 +02:00
"rasterbars",
"sprites",
2022-08-14 10:46:34 +02:00
"starfield",
2023-06-03 21:39:34 +02:00
"tehtriz",
"turtle-gfx",
"wizzine",
),
listOf(false, true)
)
onlyC64.forEach {
val (source, optimize) = it
val target = C64Target()
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
test(displayName) {
2022-03-07 21:41:12 +01:00
compileTheThing(filepath, optimize, target) shouldNotBe null
}
}
})
class TestCompilerOnExamplesCx16: FunSpec({
2022-06-26 18:51:03 +02:00
val onlyCx16 = cartesianProduct(
listOf(
2023-09-24 20:56:36 +02:00
"chunkedfile/demo",
"vtui/testvtui",
2023-06-03 21:39:34 +02:00
"pcmaudio/play-adpcm",
"pcmaudio/stream-wav",
"sprites/dragon",
"sprites/dragons",
"amiga",
2022-07-09 15:40:56 +02:00
"bdmusic",
"bobs",
2023-06-03 21:39:34 +02:00
"bubbleuniverse",
"circles",
"cobramk3-gfx",
"colorbars",
2022-11-14 17:55:55 +01:00
"cube3d",
2023-06-03 21:39:34 +02:00
"cxlogo",
2022-11-14 17:55:55 +01:00
"diskspeed",
"fileseek",
"highresbitmap",
"kefrenbars",
2022-11-14 17:55:55 +01:00
"keyboardhandler",
2022-07-09 15:40:56 +02:00
"mandelbrot",
2023-09-04 23:54:13 +02:00
"plasma",
"rasterbars",
2022-11-14 17:55:55 +01:00
"snow",
2023-06-18 12:49:22 +02:00
"spotlight",
"tehtriz",
"testgfx2",
"testmonogfx",
),
listOf(false, true)
)
onlyCx16.forEach {
val (source, optimize) = it
val target = Cx16Target()
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
test(displayName) {
2022-03-07 21:41:12 +01:00
compileTheThing(filepath, optimize, target) shouldNotBe null
}
}
})
class TestCompilerOnExamplesBothC64andCx16: FunSpec({
2022-06-26 18:51:03 +02:00
val bothCx16AndC64 = cartesianProduct(
listOf(
"animals",
"balls",
"cube3d",
"cube3d-float",
"cube3d-gfx",
"dirlist",
"fibonacci",
"line-circle-gfx",
"line-circle-txt",
2022-07-09 15:40:56 +02:00
"maze",
"mandelbrot",
"mandelbrot-gfx",
"numbergame",
"primes",
"screencodes",
"sincos",
"sorting",
"swirl",
"swirl-float",
"tehtriz",
"textelite",
),
listOf(false, true)
)
bothCx16AndC64.forEach {
val (source, optimize) = it
val c64target = C64Target()
val cx16target = Cx16Target()
val (displayNameC64, filepathC64) = prepareTestFiles(source, optimize, c64target)
val (displayNameCx16, filepathCx16) = prepareTestFiles(source, optimize, cx16target)
test(displayNameC64) {
2022-03-07 21:41:12 +01:00
compileTheThing(filepathC64, optimize, c64target) shouldNotBe null
}
test(displayNameCx16) {
2022-03-07 21:41:12 +01:00
compileTheThing(filepathCx16, optimize, cx16target) shouldNotBe null
}
}
})
class TestCompilerOnExamplesVirtual: FunSpec({
val onlyVirtual = listOf(
"bouncegfx",
"bsieve",
"pixelshader",
"sincos",
"textelite"
)
onlyVirtual.forEach {
val target = VMTarget()
val (displayName, filepath) = prepareTestFiles(it, false, target)
test(displayName) {
val src = filepath.readText()
2023-02-14 22:37:33 +01:00
compileText(target, true, src, writeAssembly = true) shouldNotBe null
compileText(target, true, src, writeAssembly = true) shouldNotBe null
}
}
})