[minor] Implement in-process test for main.kts cache

mainly to ease debugging
This commit is contained in:
Ilya Chernikov
2020-12-17 13:59:18 +01:00
parent 4dc228a0a3
commit 83da5f61fd
@@ -94,6 +94,33 @@ class MainKtsIT {
}
}
@OptIn(ExperimentalPathApi::class)
@Test
fun testCacheInProcess() {
val script = File("$TEST_DATA_ROOT/import-test.main.kts").absolutePath
val cache = createTempDirectory("main.kts.test")
try {
Assert.assertTrue(cache.exists() && cache.listDirectoryEntries("*.jar").isEmpty())
runWithK2JVMCompilerAndMainKts(script, OUT_FROM_IMPORT_TEST, cacheDir = cache)
val cacheFile = cache.listDirectoryEntries("*.jar").firstOrNull()
Assert.assertTrue(cacheFile != null && cacheFile.exists())
// run generated jar with java
val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java")
val args = listOf(javaExecutable.absolutePath, "-jar", cacheFile!!.toString())
runAndCheckResults(
args, OUT_FROM_IMPORT_TEST,
additionalEnvVars = listOf(COMPILED_SCRIPTS_CACHE_DIR_ENV_VAR to cache.toAbsolutePath().toString())
)
// this run should use the cached script
runWithK2JVMCompilerAndMainKts(script, OUT_FROM_IMPORT_TEST, cacheDir = cache)
} finally {
cache.toFile().deleteRecursively()
}
}
@Test
fun testHelloSerialization() {
val paths = PathUtil.kotlinPathsForDistDirectory