2024-09-08 14:03:57 +00:00
|
|
|
package prog8tests.compiler
|
2021-06-28 16:42:05 +00:00
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
import io.kotest.core.spec.style.FunSpec
|
2024-09-08 14:03:57 +00:00
|
|
|
import io.kotest.datatest.withData
|
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-09-25 09:00:04 +00:00
|
|
|
import prog8.code.target.*
|
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-09-25 09:00:04 +00:00
|
|
|
import prog8tests.helpers.*
|
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,
|
|
|
|
writeAssembly = true,
|
2023-07-30 15:10:54 +00:00
|
|
|
warnSymbolShadowing = false,
|
2021-11-30 00:40:21 +00:00
|
|
|
quietAssembler = true,
|
2021-12-30 13:38:40 +00:00
|
|
|
asmListfile = false,
|
2023-08-02 19:26:40 +00:00
|
|
|
includeSourcelines = false,
|
2022-02-05 20:25:19 +00:00
|
|
|
experimentalCodegen = false,
|
2024-02-10 17:42:31 +00:00
|
|
|
dumpVariables = false,
|
2024-04-09 16:30:56 +00:00
|
|
|
dumpSymbols = false,
|
2023-06-26 22:27:34 +00:00
|
|
|
varsHighBank = null,
|
2023-12-23 19:11:50 +00:00
|
|
|
varsGolden = false,
|
2023-12-23 19:45:30 +00:00
|
|
|
slabsHighBank = null,
|
|
|
|
slabsGolden = false,
|
2021-11-30 00:40:21 +00:00
|
|
|
compilationTarget = target.name,
|
2023-05-30 17:08:34 +00:00
|
|
|
splitWordArrays = false,
|
2024-10-27 12:49:00 +00:00
|
|
|
addMissingRts = false,
|
2024-01-22 20:07:51 +00:00
|
|
|
breakpointCpuInstruction = null,
|
2024-01-01 21:48:19 +00:00
|
|
|
printAst1 = false,
|
|
|
|
printAst2 = false,
|
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-09-25 09:00:04 +00:00
|
|
|
when (target) {
|
2023-06-03 19:39:34 +00:00
|
|
|
is C64Target -> searchIn.add(0, assumeDirectory(examplesDir, "c64"))
|
2022-09-25 09:00:04 +00:00
|
|
|
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"))
|
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",
|
2024-11-04 03:28:27 +00:00
|
|
|
"banking",
|
2021-07-17 08:37:58 +00:00
|
|
|
"bdmusic",
|
|
|
|
"bdmusic-irq",
|
|
|
|
"charset",
|
2023-06-03 19:39:34 +00:00
|
|
|
"cube3d",
|
2021-07-17 08:37:58 +00:00
|
|
|
"cube3d-sprites",
|
|
|
|
"plasma",
|
2023-06-03 19:39:34 +00:00
|
|
|
"rasterbars",
|
2021-07-17 08:37:58 +00:00
|
|
|
"sprites",
|
2022-08-14 08:46:34 +00:00
|
|
|
"starfield",
|
2023-06-03 19:39:34 +00:00
|
|
|
"tehtriz",
|
2021-07-17 08:37:58 +00:00
|
|
|
"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
|
|
|
|
2024-09-08 14:03:57 +00:00
|
|
|
val target = C64Target()
|
|
|
|
withData(
|
|
|
|
nameFn = { it.second.first },
|
|
|
|
onlyC64.map { it to prepareTestFiles(it.first, it.second, target) }
|
|
|
|
) { (params, prep) ->
|
|
|
|
val filepath = prep.second
|
|
|
|
val optimize = params.second
|
|
|
|
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(
|
2023-09-24 18:56:36 +00:00
|
|
|
"chunkedfile/demo",
|
2021-07-17 08:37:58 +00:00
|
|
|
"vtui/testvtui",
|
2023-06-03 19:39:34 +00:00
|
|
|
"pcmaudio/play-adpcm",
|
|
|
|
"pcmaudio/stream-wav",
|
2024-07-23 19:24:24 +00:00
|
|
|
"pcmaudio/stream-simple-aflow",
|
|
|
|
"pcmaudio/stream-simple-poll",
|
2024-04-16 20:11:26 +00:00
|
|
|
"pcmaudio/vumeter",
|
2023-09-01 14:56:46 +00:00
|
|
|
"sprites/dragon",
|
|
|
|
"sprites/dragons",
|
2024-11-01 22:13:43 +00:00
|
|
|
"zsmkit/demo1",
|
|
|
|
"zsmkit/demo2",
|
2024-11-04 03:28:27 +00:00
|
|
|
"banking/program",
|
2021-07-17 08:37:58 +00:00
|
|
|
"amiga",
|
2024-09-25 21:51:59 +00:00
|
|
|
"audioroutines",
|
2024-01-12 19:18:41 +00:00
|
|
|
"automatons",
|
2024-10-12 20:30:18 +00:00
|
|
|
"balloonflight",
|
2022-07-09 13:40:56 +00:00
|
|
|
"bdmusic",
|
2021-07-17 08:37:58 +00:00
|
|
|
"bobs",
|
2023-06-03 19:39:34 +00:00
|
|
|
"bubbleuniverse",
|
2024-04-07 17:32:44 +00:00
|
|
|
"charsets",
|
2022-07-17 13:04:15 +00:00
|
|
|
"circles",
|
2021-07-17 08:37:58 +00:00
|
|
|
"cobramk3-gfx",
|
|
|
|
"colorbars",
|
2022-11-14 16:55:55 +00:00
|
|
|
"cube3d",
|
2023-06-03 19:39:34 +00:00
|
|
|
"cxlogo",
|
2022-11-14 16:55:55 +00:00
|
|
|
"diskspeed",
|
2022-11-23 00:14:43 +00:00
|
|
|
"fileseek",
|
2021-07-17 08:37:58 +00:00
|
|
|
"kefrenbars",
|
2022-11-14 16:55:55 +00:00
|
|
|
"keyboardhandler",
|
2024-09-05 23:46:22 +00:00
|
|
|
"life",
|
2022-07-09 13:40:56 +00:00
|
|
|
"mandelbrot",
|
2023-11-22 19:03:21 +00:00
|
|
|
"multi-irq-old",
|
|
|
|
"multi-irq-new",
|
2023-09-04 21:54:13 +00:00
|
|
|
"plasma",
|
2021-11-09 22:36:47 +00:00
|
|
|
"rasterbars",
|
2023-11-24 20:26:34 +00:00
|
|
|
"showbmx",
|
2022-11-14 16:55:55 +00:00
|
|
|
"snow",
|
2023-06-18 10:49:22 +00:00
|
|
|
"spotlight",
|
2024-10-01 23:32:56 +00:00
|
|
|
"starszoom",
|
2021-11-09 22:36:47 +00:00
|
|
|
"tehtriz",
|
2024-10-30 21:21:07 +00:00
|
|
|
"test_gfx_lores",
|
|
|
|
"test_gfx_hires4",
|
2023-10-04 20:32:13 +00:00
|
|
|
"testmonogfx",
|
2021-07-17 08:37:58 +00:00
|
|
|
),
|
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
|
|
|
|
2024-09-08 14:03:57 +00:00
|
|
|
val target = Cx16Target()
|
|
|
|
withData(
|
|
|
|
nameFn = { it.second.first },
|
|
|
|
onlyCx16.map { it to prepareTestFiles(it.first, it.second, target) }
|
|
|
|
) { (params, prep) ->
|
|
|
|
val filepath = prep.second
|
|
|
|
val optimize = params.second
|
|
|
|
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",
|
|
|
|
"dirlist",
|
|
|
|
"fibonacci",
|
2024-09-30 21:10:10 +00:00
|
|
|
"fractal-tree",
|
2022-07-09 13:40:56 +00:00
|
|
|
"maze",
|
2021-11-07 23:16:58 +00:00
|
|
|
"mandelbrot",
|
|
|
|
"mandelbrot-gfx",
|
|
|
|
"numbergame",
|
|
|
|
"primes",
|
2024-06-19 21:57:43 +00:00
|
|
|
"queens",
|
2021-11-07 23:16:58 +00:00
|
|
|
"screencodes",
|
|
|
|
"swirl",
|
|
|
|
"swirl-float",
|
|
|
|
"tehtriz",
|
|
|
|
"textelite",
|
|
|
|
),
|
2024-09-08 14:03:57 +00:00
|
|
|
listOf(false, true),
|
|
|
|
listOf(C64Target(), Cx16Target())
|
2021-11-07 23:16:58 +00:00
|
|
|
)
|
|
|
|
|
2024-09-08 14:03:57 +00:00
|
|
|
withData(
|
|
|
|
nameFn = { it.third.first },
|
|
|
|
bothCx16AndC64.map { Triple(it.second, it.third, prepareTestFiles(it.first, it.second, it.third)) }
|
|
|
|
) { params ->
|
|
|
|
val filepath = params.third.second
|
|
|
|
val optimize = params.first
|
|
|
|
compileTheThing(filepath, optimize, params.second) shouldNotBe null
|
2021-11-07 23:16:58 +00:00
|
|
|
}
|
|
|
|
})
|
2022-09-25 09:00:04 +00:00
|
|
|
|
|
|
|
class TestCompilerOnExamplesVirtual: FunSpec({
|
|
|
|
|
2024-09-08 14:03:57 +00:00
|
|
|
val onlyVirtual = cartesianProduct(
|
|
|
|
listOf(
|
2022-09-25 09:00:04 +00:00
|
|
|
"bouncegfx",
|
|
|
|
"bsieve",
|
|
|
|
"pixelshader",
|
2024-03-16 15:47:40 +00:00
|
|
|
"sincos"
|
2024-09-08 14:03:57 +00:00
|
|
|
),
|
|
|
|
listOf(false, true)
|
|
|
|
)
|
|
|
|
|
|
|
|
val target = VMTarget()
|
|
|
|
withData(
|
|
|
|
nameFn = { it.second.first },
|
|
|
|
onlyVirtual.map { it to prepareTestFiles(it.first, it.second, target) }
|
|
|
|
) { (params, prep) ->
|
|
|
|
val filepath = prep.second
|
|
|
|
val optimize = params.second
|
|
|
|
compileTheThing(filepath, optimize, target) shouldNotBe null
|
2022-09-25 09:00:04 +00:00
|
|
|
}
|
|
|
|
})
|