2021-09-12 16:16:24 +00:00
|
|
|
package prog8tests
|
|
|
|
|
2021-11-08 14:50:29 +00:00
|
|
|
import io.kotest.assertions.withClue
|
2021-11-07 23:16:58 +00:00
|
|
|
import io.kotest.core.spec.style.FunSpec
|
2021-11-08 14:50:29 +00:00
|
|
|
import io.kotest.matchers.shouldBe
|
|
|
|
import io.kotest.matchers.string.shouldStartWith
|
2022-03-10 22:08:41 +00:00
|
|
|
import prog8.code.core.ZeropageType
|
2022-03-21 00:01:21 +00:00
|
|
|
import prog8.code.core.internedStringsModuleName
|
2022-03-11 19:35:25 +00:00
|
|
|
import prog8.code.target.C64Target
|
2021-10-10 22:22:04 +00:00
|
|
|
import prog8.compiler.determineCompilationOptions
|
2023-02-28 19:08:11 +00:00
|
|
|
import prog8.compiler.parseMainModule
|
2021-10-29 14:46:56 +00:00
|
|
|
import prog8tests.helpers.ErrorReporterForTests
|
2021-10-10 22:22:04 +00:00
|
|
|
import prog8tests.helpers.compileText
|
2022-06-26 16:51:03 +00:00
|
|
|
import prog8tests.helpers.outputDir
|
2021-09-12 16:16:24 +00:00
|
|
|
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
class TestImportedModulesOrderAndOptions: FunSpec({
|
2021-09-12 16:16:24 +00:00
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testImportedModuleOrderAndMainModuleCorrect") {
|
2022-03-11 19:35:25 +00:00
|
|
|
val result = compileText(
|
|
|
|
C64Target(), false, """
|
2021-09-12 16:16:24 +00:00
|
|
|
%import textio
|
|
|
|
%import floats
|
|
|
|
|
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
; nothing
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2023-02-09 00:46:23 +00:00
|
|
|
result.compilerAst.toplevelModule.name shouldStartWith "on_the_fly_test"
|
2021-09-12 16:16:24 +00:00
|
|
|
|
2023-02-09 00:46:23 +00:00
|
|
|
val moduleNames = result.compilerAst.modules.map { it.name }
|
2021-11-08 14:50:29 +00:00
|
|
|
withClue("main module must be first") {
|
|
|
|
moduleNames[0] shouldStartWith "on_the_fly_test"
|
|
|
|
}
|
|
|
|
withClue("module order in parse tree") {
|
|
|
|
moduleNames.drop(1) shouldBe listOf(
|
2022-02-08 00:58:55 +00:00
|
|
|
internedStringsModuleName,
|
2021-11-08 14:50:29 +00:00
|
|
|
"textio",
|
|
|
|
"syslib",
|
|
|
|
"conv",
|
|
|
|
"floats",
|
2022-04-21 22:45:54 +00:00
|
|
|
"floats_functions",
|
2021-11-08 14:50:29 +00:00
|
|
|
"math",
|
|
|
|
"prog8_lib"
|
|
|
|
)
|
|
|
|
}
|
2023-02-09 00:46:23 +00:00
|
|
|
result.compilerAst.toplevelModule.name shouldStartWith "on_the_fly_test"
|
2021-09-12 16:16:24 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testCompilationOptionsCorrectFromMain") {
|
2022-03-11 19:35:25 +00:00
|
|
|
val result = compileText(
|
|
|
|
C64Target(), false, """
|
2021-09-12 16:16:24 +00:00
|
|
|
%import textio
|
|
|
|
%import floats
|
|
|
|
%zeropage dontuse
|
|
|
|
%option no_sysinit
|
|
|
|
|
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
; nothing
|
|
|
|
}
|
|
|
|
}
|
2022-03-07 20:41:12 +00:00
|
|
|
""")!!
|
2023-02-09 00:46:23 +00:00
|
|
|
result.compilerAst.toplevelModule.name shouldStartWith "on_the_fly_test"
|
|
|
|
val options = determineCompilationOptions(result.compilerAst, C64Target())
|
2021-11-08 14:50:29 +00:00
|
|
|
options.floats shouldBe true
|
|
|
|
options.zeropage shouldBe ZeropageType.DONTUSE
|
|
|
|
options.noSysInit shouldBe true
|
2021-09-12 16:16:24 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
test("testModuleOrderAndCompilationOptionsCorrectWithJustImports") {
|
2021-10-29 14:46:56 +00:00
|
|
|
val errors = ErrorReporterForTests()
|
2021-09-12 16:16:24 +00:00
|
|
|
val sourceText = """
|
|
|
|
%import textio
|
|
|
|
%import floats
|
|
|
|
%option no_sysinit
|
|
|
|
%zeropage dontuse
|
|
|
|
|
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
; nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
val filenameBase = "on_the_fly_test_" + sourceText.hashCode().toUInt().toString(16)
|
2022-06-26 16:51:03 +00:00
|
|
|
val filepath = outputDir.resolve("$filenameBase.p8")
|
2021-09-12 16:16:24 +00:00
|
|
|
filepath.toFile().writeText(sourceText)
|
2023-10-02 19:06:14 +00:00
|
|
|
val (program, options, importedfiles) = parseMainModule(filepath, errors, C64Target(), emptyList())
|
2021-09-12 16:16:24 +00:00
|
|
|
|
2021-11-08 14:50:29 +00:00
|
|
|
program.toplevelModule.name shouldBe filenameBase
|
|
|
|
withClue("all imports other than the test source must have been internal resources library files") {
|
|
|
|
importedfiles.size shouldBe 1
|
|
|
|
}
|
|
|
|
withClue("module order in parse tree") {
|
|
|
|
program.modules.map { it.name } shouldBe
|
|
|
|
listOf(
|
|
|
|
internedStringsModuleName,
|
|
|
|
filenameBase,
|
2022-04-21 22:45:54 +00:00
|
|
|
"textio", "syslib", "conv", "floats", "floats_functions", "math", "prog8_lib"
|
2021-11-08 14:50:29 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
options.floats shouldBe true
|
|
|
|
options.noSysInit shouldBe true
|
|
|
|
withClue("zeropage option must be correctly taken from main module, not from float module import logic") {
|
|
|
|
options.zeropage shouldBe ZeropageType.DONTUSE
|
|
|
|
}
|
2021-09-12 16:16:24 +00:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:16:58 +00:00
|
|
|
})
|