Speed up LauncherScriptTest
Do not run kotlinc in a separate process in tests which check behavior of the `kotlin` launcher script. Locally, the test now runs for 37s instead of 51s.
This commit is contained in:
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.cli
|
|||||||
|
|
||||||
import com.intellij.openapi.util.SystemInfo
|
import com.intellij.openapi.util.SystemInfo
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||||
@@ -88,6 +90,11 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
|
|||||||
private val testDataDirectory: String
|
private val testDataDirectory: String
|
||||||
get() = KtTestUtil.getTestDataPathBase() + "/launcher"
|
get() = KtTestUtil.getTestDataPathBase() + "/launcher"
|
||||||
|
|
||||||
|
private fun kotlincInProcess(vararg args: String) {
|
||||||
|
val (output, exitCode) = AbstractCliTest.executeCompilerGrabOutput(K2JVMCompiler(), args.toList())
|
||||||
|
if (exitCode != ExitCode.OK) error("Failed to compile: ${args.joinToString(" ")}\nOutput:\n$output")
|
||||||
|
}
|
||||||
|
|
||||||
fun testKotlincSimple() {
|
fun testKotlincSimple() {
|
||||||
runProcess(
|
runProcess(
|
||||||
"kotlinc",
|
"kotlinc",
|
||||||
@@ -116,8 +123,7 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
|
|||||||
fun testKotlinJvmContextClassLoader() {
|
fun testKotlinJvmContextClassLoader() {
|
||||||
val kotlinTestJar = File(PathUtil.kotlinPathsForDistDirectory.homePath, "lib/kotlin-test.jar")
|
val kotlinTestJar = File(PathUtil.kotlinPathsForDistDirectory.homePath, "lib/kotlin-test.jar")
|
||||||
assertTrue("kotlin-main-kts.jar not found, run dist task: ${kotlinTestJar.absolutePath}", kotlinTestJar.exists())
|
assertTrue("kotlin-main-kts.jar not found, run dist task: ${kotlinTestJar.absolutePath}", kotlinTestJar.exists())
|
||||||
runProcess(
|
kotlincInProcess(
|
||||||
"kotlinc",
|
|
||||||
"-cp", kotlinTestJar.path,
|
"-cp", kotlinTestJar.path,
|
||||||
"$testDataDirectory/contextClassLoaderTester.kt",
|
"$testDataDirectory/contextClassLoaderTester.kt",
|
||||||
"-d", tmpdir.path
|
"-d", tmpdir.path
|
||||||
@@ -140,11 +146,7 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testKotlinNoReflect() {
|
fun testKotlinNoReflect() {
|
||||||
runProcess(
|
kotlincInProcess("$testDataDirectory/reflectionUsage.kt", "-d", tmpdir.path)
|
||||||
"kotlinc",
|
|
||||||
"$testDataDirectory/reflectionUsage.kt",
|
|
||||||
"-d", tmpdir.path
|
|
||||||
)
|
|
||||||
|
|
||||||
runProcess(
|
runProcess(
|
||||||
"kotlin",
|
"kotlin",
|
||||||
@@ -156,11 +158,7 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testDoNotAppendCurrentDirToNonEmptyClasspath() {
|
fun testDoNotAppendCurrentDirToNonEmptyClasspath() {
|
||||||
runProcess(
|
kotlincInProcess("$testDataDirectory/helloWorld.kt", "-d", tmpdir.path)
|
||||||
"kotlinc",
|
|
||||||
"$testDataDirectory/helloWorld.kt",
|
|
||||||
"-d", tmpdir.path
|
|
||||||
)
|
|
||||||
|
|
||||||
runProcess("kotlin", "test.HelloWorldKt", expectedStdout = "Hello!\n", workDirectory = tmpdir)
|
runProcess("kotlin", "test.HelloWorldKt", expectedStdout = "Hello!\n", workDirectory = tmpdir)
|
||||||
|
|
||||||
@@ -223,17 +221,11 @@ class LauncherScriptTest : TestCaseWithTmpdir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testLegacyAssert() {
|
fun testLegacyAssert() {
|
||||||
runProcess(
|
kotlincInProcess("$testDataDirectory/legacyAssertDisabled.kt", "-Xassertions=legacy", "-d", tmpdir.path)
|
||||||
"kotlinc",
|
|
||||||
"$testDataDirectory/legacyAssertDisabled.kt", "-Xassertions=legacy", "-d", tmpdir.path
|
|
||||||
)
|
|
||||||
|
|
||||||
runProcess("kotlin", "LegacyAssertDisabledKt", "-J-da:kotlin._Assertions", workDirectory = tmpdir)
|
runProcess("kotlin", "LegacyAssertDisabledKt", "-J-da:kotlin._Assertions", workDirectory = tmpdir)
|
||||||
|
|
||||||
runProcess(
|
kotlincInProcess("$testDataDirectory/legacyAssertEnabled.kt", "-Xassertions=legacy", "-d", tmpdir.path)
|
||||||
"kotlinc",
|
|
||||||
"$testDataDirectory/legacyAssertEnabled.kt", "-Xassertions=legacy", "-d", tmpdir.path
|
|
||||||
)
|
|
||||||
|
|
||||||
runProcess("kotlin", "LegacyAssertEnabledKt", "-J-ea:kotlin._Assertions", workDirectory = tmpdir)
|
runProcess("kotlin", "LegacyAssertEnabledKt", "-J-ea:kotlin._Assertions", workDirectory = tmpdir)
|
||||||
}
|
}
|
||||||
@@ -266,7 +258,7 @@ println(42)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testProperty() {
|
fun testProperty() {
|
||||||
runProcess("kotlinc", "$testDataDirectory/property.kt", "-d", tmpdir.path)
|
kotlincInProcess("$testDataDirectory/property.kt", "-d", tmpdir.path)
|
||||||
|
|
||||||
runProcess(
|
runProcess(
|
||||||
"kotlin", "PropertyKt", "-Dresult=OK",
|
"kotlin", "PropertyKt", "-Dresult=OK",
|
||||||
@@ -303,7 +295,8 @@ println(42)
|
|||||||
)
|
)
|
||||||
runProcess(
|
runProcess(
|
||||||
"kotlin", "-howtorun", "script", "$testDataDirectory/noInline.myscript",
|
"kotlin", "-howtorun", "script", "$testDataDirectory/noInline.myscript",
|
||||||
expectedExitCode = 1, expectedStderr = "error: unrecognized script type: noInline.myscript; Specify path to the script file as the first argument\n"
|
expectedExitCode = 1,
|
||||||
|
expectedStderr = "error: unrecognized script type: noInline.myscript; Specify path to the script file as the first argument\n"
|
||||||
)
|
)
|
||||||
runProcess(
|
runProcess(
|
||||||
"kotlin", "-howtorun", ".kts", "$testDataDirectory/noInline.myscript",
|
"kotlin", "-howtorun", ".kts", "$testDataDirectory/noInline.myscript",
|
||||||
@@ -322,7 +315,7 @@ compiler/testData/launcher/noInline.myscript:1:7: error: unresolved reference: C
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testHowToRunClassFile() {
|
fun testHowToRunClassFile() {
|
||||||
runProcess("kotlinc", "$testDataDirectory/helloWorld.kt", "-d", tmpdir.path)
|
kotlincInProcess("$testDataDirectory/helloWorld.kt", "-d", tmpdir.path)
|
||||||
|
|
||||||
runProcess(
|
runProcess(
|
||||||
"kotlin", "-howtorun", "jar", "test.HelloWorldKt", workDirectory = tmpdir,
|
"kotlin", "-howtorun", "jar", "test.HelloWorldKt", workDirectory = tmpdir,
|
||||||
@@ -358,7 +351,7 @@ compiler/testData/launcher/noInline.myscript:1:7: error: unresolved reference: C
|
|||||||
fun testNoClassDefFoundErrorWhenClassInDefaultPackage() {
|
fun testNoClassDefFoundErrorWhenClassInDefaultPackage() {
|
||||||
val testDir = File("$tmpdir/test")
|
val testDir = File("$tmpdir/test")
|
||||||
|
|
||||||
runProcess("kotlinc", "$testDataDirectory/defaultPackage.kt", "-d", testDir.path)
|
kotlincInProcess("$testDataDirectory/defaultPackage.kt", "-d", testDir.path)
|
||||||
assertExists(File("${testDir.path}/DefaultPackageKt.class"))
|
assertExists(File("${testDir.path}/DefaultPackageKt.class"))
|
||||||
|
|
||||||
runProcess(
|
runProcess(
|
||||||
@@ -374,7 +367,7 @@ compiler/testData/launcher/noInline.myscript:1:7: error: unresolved reference: C
|
|||||||
fun testNoClassDefFoundErrorWhenClassNotInDefaultPackage() {
|
fun testNoClassDefFoundErrorWhenClassNotInDefaultPackage() {
|
||||||
val testDir = File("$tmpdir/test")
|
val testDir = File("$tmpdir/test")
|
||||||
|
|
||||||
runProcess("kotlinc", "$testDataDirectory/helloWorld.kt", "-d", tmpdir.path)
|
kotlincInProcess("$testDataDirectory/helloWorld.kt", "-d", tmpdir.path)
|
||||||
assertExists(File("${testDir.path}/HelloWorldKt.class"))
|
assertExists(File("${testDir.path}/HelloWorldKt.class"))
|
||||||
|
|
||||||
runProcess(
|
runProcess(
|
||||||
@@ -394,7 +387,7 @@ compiler/testData/launcher/noInline.myscript:1:7: error: unresolved reference: C
|
|||||||
val subDir = File("$tmpdir/test/sub").apply { mkdirs() }
|
val subDir = File("$tmpdir/test/sub").apply { mkdirs() }
|
||||||
val testDir = File("$tmpdir/test")
|
val testDir = File("$tmpdir/test")
|
||||||
|
|
||||||
runProcess("kotlinc", "$testDataDirectory/defaultPackage.kt", "-d", testDir.path)
|
kotlincInProcess("$testDataDirectory/defaultPackage.kt", "-d", testDir.path)
|
||||||
assertExists(File("${testDir.path}/DefaultPackageKt.class"))
|
assertExists(File("${testDir.path}/DefaultPackageKt.class"))
|
||||||
|
|
||||||
runProcess(
|
runProcess(
|
||||||
@@ -422,7 +415,7 @@ compiler/testData/launcher/noInline.myscript:1:7: error: unresolved reference: C
|
|||||||
val subDir = File("$tmpdir/test/sub").apply { mkdirs() }
|
val subDir = File("$tmpdir/test/sub").apply { mkdirs() }
|
||||||
val testDir = File("$tmpdir/test")
|
val testDir = File("$tmpdir/test")
|
||||||
|
|
||||||
runProcess("kotlinc", "$testDataDirectory/helloWorld.kt", "-d", tmpdir.path)
|
kotlincInProcess("$testDataDirectory/helloWorld.kt", "-d", tmpdir.path)
|
||||||
assertExists(File("${testDir.path}/HelloWorldKt.class"))
|
assertExists(File("${testDir.path}/HelloWorldKt.class"))
|
||||||
|
|
||||||
runProcess("kotlin", "test/HelloWorldKt.class", expectedStdout = "Hello!\n", workDirectory = tmpdir)
|
runProcess("kotlin", "test/HelloWorldKt.class", expectedStdout = "Hello!\n", workDirectory = tmpdir)
|
||||||
|
|||||||
Reference in New Issue
Block a user