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:
+8
-1
@@ -20,7 +20,14 @@ class MainKtsIT {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testImport() {
|
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
|
@Test
|
||||||
|
|||||||
+13
-6
@@ -27,18 +27,25 @@ class ScriptingWithCliCompilerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testStandardScriptWithDeps() {
|
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
|
@Test
|
||||||
fun testStandardScriptWithDepsViaKotlinc() {
|
fun testStandardScriptWithDepsViaKotlinc() {
|
||||||
runWithKotlinc(
|
runWithKotlinc(
|
||||||
"$TEST_DATA_DIR/integration/withDependencyOnCompileClassPath.kts", listOf("Hello from standard kts!"),
|
"$TEST_DATA_DIR/integration/withDependencyOnCompileClassPath.kts", listOf("Hello from standard kts!"),
|
||||||
classpath = listOf(
|
classpath = getMainKtsClassPath()
|
||||||
File("dist/kotlinc/lib/kotlin-main-kts.jar").also {
|
)
|
||||||
Assert.assertTrue("kotlin-main-kts.jar not found, run dist task: ${it.absolutePath}", it.exists())
|
}
|
||||||
}
|
|
||||||
)
|
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())
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -98,15 +98,21 @@ fun runWithKotlinc(
|
|||||||
fun runWithK2JVMCompiler(
|
fun runWithK2JVMCompiler(
|
||||||
scriptPath: String,
|
scriptPath: String,
|
||||||
expectedOutPatterns: List<String> = emptyList(),
|
expectedOutPatterns: List<String> = emptyList(),
|
||||||
expectedExitCode: Int = 0
|
expectedExitCode: Int = 0,
|
||||||
|
classpath: List<File> = emptyList()
|
||||||
) {
|
) {
|
||||||
val mainKtsJar = File("dist/kotlinc/lib/kotlin-main-kts.jar")
|
val args = arrayListOf("-kotlin-home", "dist/kotlinc").apply {
|
||||||
Assert.assertTrue("kotlin-main-kts.jar not found, run dist task: ${mainKtsJar.absolutePath}", mainKtsJar.exists())
|
if (classpath.isNotEmpty()) {
|
||||||
|
add("-cp")
|
||||||
|
add(classpath.joinToString(File.pathSeparator))
|
||||||
|
}
|
||||||
|
add("-script")
|
||||||
|
add(scriptPath)
|
||||||
|
}
|
||||||
val (out, err, ret) = captureOutErrRet {
|
val (out, err, ret) = captureOutErrRet {
|
||||||
CLITool.doMainNoExit(
|
CLITool.doMainNoExit(
|
||||||
K2JVMCompiler(),
|
K2JVMCompiler(),
|
||||||
arrayOf("-kotlin-home", "dist/kotlinc", "-cp", mainKtsJar.absolutePath, "-script", scriptPath)
|
args.toTypedArray()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user