Refactor test utils: don't add main-kts to the classpath...

by default on running scripting tests via the call to K2JVMCompiler
This commit is contained in:
Ilya Chernikov
2019-09-11 17:56:03 +02:00
parent 49003c9839
commit b2d2ba5811
3 changed files with 32 additions and 12 deletions
@@ -27,18 +27,25 @@ class ScriptingWithCliCompilerTest {
@Test
fun testStandardScriptWithDeps() {
runWithK2JVMCompiler("$TEST_DATA_DIR/integration/withDependencyOnCompileClassPath.kts", listOf("Hello from standard kts!"))
runWithK2JVMCompiler(
"$TEST_DATA_DIR/integration/withDependencyOnCompileClassPath.kts", listOf("Hello from standard kts!"),
classpath = getMainKtsClassPath()
)
}
@Test
fun testStandardScriptWithDepsViaKotlinc() {
runWithKotlinc(
"$TEST_DATA_DIR/integration/withDependencyOnCompileClassPath.kts", listOf("Hello from standard kts!"),
classpath = listOf(
File("dist/kotlinc/lib/kotlin-main-kts.jar").also {
Assert.assertTrue("kotlin-main-kts.jar not found, run dist task: ${it.absolutePath}", it.exists())
}
)
classpath = getMainKtsClassPath()
)
}
private fun getMainKtsClassPath(): List<File> {
return listOf(
File("dist/kotlinc/lib/kotlin-main-kts.jar").also {
Assert.assertTrue("kotlin-main-kts.jar not found, run dist task: ${it.absolutePath}", it.exists())
}
)
}
}
@@ -98,15 +98,21 @@ fun runWithKotlinc(
fun runWithK2JVMCompiler(
scriptPath: String,
expectedOutPatterns: List<String> = emptyList(),
expectedExitCode: Int = 0
expectedExitCode: Int = 0,
classpath: List<File> = emptyList()
) {
val mainKtsJar = File("dist/kotlinc/lib/kotlin-main-kts.jar")
Assert.assertTrue("kotlin-main-kts.jar not found, run dist task: ${mainKtsJar.absolutePath}", mainKtsJar.exists())
val args = arrayListOf("-kotlin-home", "dist/kotlinc").apply {
if (classpath.isNotEmpty()) {
add("-cp")
add(classpath.joinToString(File.pathSeparator))
}
add("-script")
add(scriptPath)
}
val (out, err, ret) = captureOutErrRet {
CLITool.doMainNoExit(
K2JVMCompiler(),
arrayOf("-kotlin-home", "dist/kotlinc", "-cp", mainKtsJar.absolutePath, "-script", scriptPath)
args.toTypedArray()
)
}
try {