From b2d2ba581129afe13bdecf62a5d61fc478ab9ef1 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 11 Sep 2019 17:56:03 +0200 Subject: [PATCH] Refactor test utils: don't add main-kts to the classpath... by default on running scripting tests via the call to K2JVMCompiler --- .../kotlin/mainKts/test/mainKtsIT.kt | 9 ++++++++- .../plugin/ScriptingWithCliCompilerTest.kt | 19 +++++++++++++------ .../scripting/compiler/plugin/testUtil.kt | 16 +++++++++++----- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsIT.kt b/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsIT.kt index 33794eabde0..d08937cd12e 100644 --- a/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsIT.kt +++ b/libraries/tools/kotlin-main-kts-test/test/org/jetbrains/kotlin/mainKts/test/mainKtsIT.kt @@ -20,7 +20,14 @@ class MainKtsIT { @Test fun testImport() { - runWithK2JVMCompiler("$TEST_DATA_ROOT/import-test.main.kts", listOf("Hi from common", "Hi from middle", "sharedVar == 5")) + 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()) + + runWithK2JVMCompiler( + "$TEST_DATA_ROOT/import-test.main.kts", + listOf("Hi from common", "Hi from middle", "sharedVar == 5"), + classpath = listOf(mainKtsJar) + ) } @Test diff --git a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt index 1ac3453a84f..61f84a3b36f 100644 --- a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt +++ b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt @@ -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 { + 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()) + } ) } } diff --git a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/testUtil.kt b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/testUtil.kt index 065fa153648..5ca69dd93c2 100644 --- a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/testUtil.kt +++ b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/testUtil.kt @@ -98,15 +98,21 @@ fun runWithKotlinc( fun runWithK2JVMCompiler( scriptPath: String, expectedOutPatterns: List = emptyList(), - expectedExitCode: Int = 0 + expectedExitCode: Int = 0, + classpath: List = 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 {