Use KotlinCoreEnvironment.createForTests in test code
createForProduction creates and caches JavaCoreApplicationEnvironment instance, which can alter behavior of subsequent tests
This commit is contained in:
@@ -58,8 +58,7 @@ class ReplCompilerJava8Test : KtUsefulTestCase() {
|
|||||||
put(JVMConfigurationKeys.JVM_TARGET, JvmTarget.JVM_1_8)
|
put(JVMConfigurationKeys.JVM_TARGET, JvmTarget.JVM_1_8)
|
||||||
}
|
}
|
||||||
|
|
||||||
val environment =
|
val environment = KotlinCoreEnvironment.createForTests(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||||
KotlinCoreEnvironment.createForProduction(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
|
||||||
|
|
||||||
val res = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment)
|
val res = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment)
|
||||||
Assert.assertTrue(res)
|
Assert.assertTrue(res)
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ class ScriptTemplateTest : KtUsefulTestCase() {
|
|||||||
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, scriptDefinition)
|
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, scriptDefinition)
|
||||||
configuration.put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true)
|
configuration.put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true)
|
||||||
|
|
||||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
val environment = KotlinCoreEnvironment.createForTests(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return KotlinToJVMBytecodeCompiler.compileScript(environment, this::class.java.classLoader.takeUnless { runIsolated })
|
return KotlinToJVMBytecodeCompiler.compileScript(environment, this::class.java.classLoader.takeUnless { runIsolated })
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class ScriptTest : KtUsefulTestCase() {
|
|||||||
configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, saveClassesDir)
|
configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, saveClassesDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
val environment = KotlinCoreEnvironment.createForTests(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return KotlinToJVMBytecodeCompiler.compileScript(environment, this::class.java.classLoader.takeUnless { runIsolated })
|
return KotlinToJVMBytecodeCompiler.compileScript(environment, this::class.java.classLoader.takeUnless { runIsolated })
|
||||||
|
|||||||
+1
-7
@@ -145,7 +145,7 @@ done
|
|||||||
put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true)
|
put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
val environment = KotlinCoreEnvironment.createForTests(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return KotlinToJVMBytecodeCompiler.compileScript(environment)
|
return KotlinToJVMBytecodeCompiler.compileScript(environment)
|
||||||
@@ -166,12 +166,6 @@ done
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private inline fun <R> ifFailed(default: R, block: () -> R) = try {
|
|
||||||
block()
|
|
||||||
} catch (t: Throwable) {
|
|
||||||
default
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun String.linesSplitTrim() =
|
private fun String.linesSplitTrim() =
|
||||||
split('\n','\r').map(String::trim).filter(String::isNotBlank)
|
split('\n','\r').map(String::trim).filter(String::isNotBlank)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user