diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index e4d9a2254..0caa4d08c 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -32,8 +32,12 @@ class TestCompilerOnExamples { if (platform == Cx16Target) { searchIn.add(0, assumeDirectory(examplesDir, "cx16")) } - val filepath = searchIn.map { it.resolve("$name.p8") }.first { it.exists() } - val displayName = "${examplesDir.relativize(filepath)}: ${platform.name}, optimize=$optimize" + val filepath = searchIn + .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) { compileProgram( filepath, diff --git a/compiler/test/TestCompilerOptionLibdirs.kt b/compiler/test/TestCompilerOptionLibdirs.kt new file mode 100644 index 000000000..4e577a085 --- /dev/null +++ b/compiler/test/TestCompilerOptionLibdirs.kt @@ -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) = + 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() + } + +} diff --git a/compiler/test/fixtures/simple_main.p8 b/compiler/test/fixtures/simple_main.p8 new file mode 100644 index 000000000..afaa79f93 --- /dev/null +++ b/compiler/test/fixtures/simple_main.p8 @@ -0,0 +1,4 @@ +main { + sub start() { + } +} diff --git a/compilerAst/test/helpers/paths.kt b/compilerAst/test/helpers/paths.kt index 0e005cde5..85b29fb26 100644 --- a/compilerAst/test/helpers/paths.kt +++ b/compilerAst/test/helpers/paths.kt @@ -46,6 +46,6 @@ fun assumeDirectory(path: Path, other: String): Path = assumeDirectory(path.div( @Deprecated("Directories are checked automatically at init.", ReplaceWith("/* nothing */")) -@Suppress("unused") +@Suppress("UNUSED_PARAMETER") fun sanityCheckDirectories(workingDirName: String? = null) { } \ No newline at end of file