+ TestCompilerOptionLibdirs.kt: libdirs option doesn't seem to work

This commit is contained in:
meisl 2021-08-01 10:11:29 +02:00
parent 1b451180c1
commit c914f7bbcf
4 changed files with 105 additions and 3 deletions

View File

@ -32,8 +32,12 @@ class TestCompilerOnExamples {
if (platform == Cx16Target) { if (platform == Cx16Target) {
searchIn.add(0, assumeDirectory(examplesDir, "cx16")) searchIn.add(0, assumeDirectory(examplesDir, "cx16"))
} }
val filepath = searchIn.map { it.resolve("$name.p8") }.first { it.exists() } val filepath = searchIn
val displayName = "${examplesDir.relativize(filepath)}: ${platform.name}, optimize=$optimize" .map { it.resolve("$name.p8") }
.map { it.normalize().absolute() }
.map { workingDir.relativize(it) }
.first { it.exists() }
val displayName = "${examplesDir.relativize(filepath.absolute())}: ${platform.name}, optimize=$optimize"
return dynamicTest(displayName) { return dynamicTest(displayName) {
compileProgram( compileProgram(
filepath, filepath,

View File

@ -0,0 +1,94 @@
package prog8tests
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.AfterAll
import prog8tests.helpers.*
import kotlin.io.path.*
import java.nio.file.Path
import prog8.compiler.compileProgram
import prog8.compiler.target.*
/**
* 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.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestCompilerOptionLibdirs {
private lateinit var tempFileInWorkingDir: Path
@BeforeAll
fun setUp() {
tempFileInWorkingDir = createTempFile(directory = workingDir, prefix = "tmp_", suffix = ".p8")
.also { it.writeText("""
main {
sub start() {
}
}
""")}
}
@AfterAll
fun tearDown() {
tempFileInWorkingDir.deleteExisting()
}
private fun compileFile(filePath: Path, libdirs: List<String>) =
compileProgram(
filepath = filePath,
optimize = false,
writeAssembly = true,
slowCodegenWarnings = false,
compilationTarget = Cx16Target.name,
libdirs,
outputDir
)
@Test
fun testAbsoluteFilePathInWorkingDir() {
val filepath = assumeReadableFile(tempFileInWorkingDir.absolute())
compileFile(filepath, listOf())
.assertSuccess()
}
@Test
fun testFilePathInWorkingDirRelativeToWorkingDir() {
val filepath = assumeReadableFile(workingDir.relativize(tempFileInWorkingDir.absolute()))
compileFile(filepath, listOf())
.assertSuccess()
}
@Test
fun testFilePathInWorkingDirRelativeTo1stInLibdirs() {
val filepath = assumeReadableFile(tempFileInWorkingDir)
compileFile(filepath.fileName, listOf(workingDir.toString()))
.assertSuccess()
}
@Test
fun testAbsoluteFilePathOutsideWorkingDir() {
val filepath = assumeReadableFile(fixturesDir, "simple_main.p8")
compileFile(filepath.absolute(), listOf())
.assertSuccess()
}
@Test
fun testFilePathOutsideWorkingDirRelativeToWorkingDir() {
val filepath = workingDir.relativize(assumeReadableFile(fixturesDir, "simple_main.p8").absolute())
compileFile(filepath, listOf())
.assertSuccess()
}
@Test
fun testFilePathOutsideWorkingDirRelativeTo1stInLibdirs() {
val filepath = assumeReadableFile(fixturesDir, "simple_main.p8")
val libdirs = listOf("$fixturesDir")
compileFile(filepath.fileName, libdirs)
.assertSuccess()
}
}

4
compiler/test/fixtures/simple_main.p8 vendored Normal file
View File

@ -0,0 +1,4 @@
main {
sub start() {
}
}

View File

@ -46,6 +46,6 @@ fun assumeDirectory(path: Path, other: String): Path = assumeDirectory(path.div(
@Deprecated("Directories are checked automatically at init.", @Deprecated("Directories are checked automatically at init.",
ReplaceWith("/* nothing */")) ReplaceWith("/* nothing */"))
@Suppress("unused") @Suppress("UNUSED_PARAMETER")
fun sanityCheckDirectories(workingDirName: String? = null) { fun sanityCheckDirectories(workingDirName: String? = null) {
} }