prog8/compiler/test/TestCompilerOptionLibdirs.kt

89 lines
3.1 KiB
Kotlin
Raw Normal View History

package prog8tests
import io.kotest.core.spec.style.FunSpec
2022-03-07 20:41:12 +00:00
import io.kotest.matchers.shouldNotBe
2022-03-11 19:35:25 +00:00
import prog8.code.target.Cx16Target
2021-11-30 00:40:21 +00:00
import prog8.compiler.CompilationResult
import prog8.compiler.CompilerArguments
2021-10-10 22:22:04 +00:00
import prog8.compiler.compileProgram
import prog8tests.helpers.Helpers
import java.nio.file.Path
2021-10-10 22:22:04 +00:00
import kotlin.io.path.absolute
import kotlin.io.path.createTempFile
import kotlin.io.path.deleteExisting
import kotlin.io.path.writeText
/**
* 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.
*/
class TestCompilerOptionSourcedirs: FunSpec({
lateinit var tempFileInWorkingDir: Path
beforeSpec {
tempFileInWorkingDir = createTempFile(directory = Helpers.workingDir, prefix = "tmp_", suffix = ".p8")
.also { it.writeText("""
main {
sub start() {
}
}
""")}
}
afterSpec {
tempFileInWorkingDir.deleteExisting()
}
2022-03-07 20:41:12 +00:00
fun compileFile(filePath: Path, sourceDirs: List<String>): CompilationResult? {
2021-11-30 00:40:21 +00:00
val args = CompilerArguments(
filepath = filePath,
optimize = false,
optimizeFloatExpressions = false,
2022-01-01 15:35:36 +00:00
dontReinitGlobals = false,
writeAssembly = true,
slowCodegenWarnings = false,
quietAssembler = true,
asmListfile = false,
experimentalCodegen = false,
compilationTarget = Cx16Target.NAME,
sourceDirs,
Helpers.outputDir
)
2021-11-30 00:40:21 +00:00
return compileProgram(args)
}
test("testAbsoluteFilePathInWorkingDir") {
val filepath = Helpers.assumeReadableFile(tempFileInWorkingDir.absolute())
2022-03-07 20:41:12 +00:00
compileFile(filepath, listOf()) shouldNotBe null
}
test("testFilePathInWorkingDirRelativeToWorkingDir") {
val filepath = Helpers.assumeReadableFile(Helpers.workingDir.relativize(tempFileInWorkingDir.absolute()))
2022-03-07 20:41:12 +00:00
compileFile(filepath, listOf()) shouldNotBe null
}
test("testFilePathInWorkingDirRelativeTo1stInSourcedirs") {
val filepath = Helpers.assumeReadableFile(tempFileInWorkingDir)
compileFile(filepath.fileName, listOf(Helpers.workingDir.toString())) shouldNotBe null
}
test("testAbsoluteFilePathOutsideWorkingDir") {
val filepath = Helpers.assumeReadableFile(Helpers.fixturesDir, "ast_simple_main.p8")
2022-03-07 20:41:12 +00:00
compileFile(filepath.absolute(), listOf()) shouldNotBe null
}
test("testFilePathOutsideWorkingDirRelativeToWorkingDir") {
val filepath = Helpers.workingDir.relativize(Helpers.assumeReadableFile(Helpers.fixturesDir, "ast_simple_main.p8").absolute())
2022-03-07 20:41:12 +00:00
compileFile(filepath, listOf()) shouldNotBe null
}
test("testFilePathOutsideWorkingDirRelativeTo1stInSourcedirs") {
val filepath = Helpers.assumeReadableFile(Helpers.fixturesDir, "ast_simple_main.p8")
val sourcedirs = listOf("${Helpers.fixturesDir}")
2022-03-07 20:41:12 +00:00
compileFile(filepath.fileName, sourcedirs) shouldNotBe null
}
})