Use JUnit 3 + KtUsefulTestCase instead of JUnit 4 in compiler tests
This is needed because KtUsefulTestCase performs useful cleanup at the end of the test (namely, resets ApplicationManager#ourApplication to null)
This commit is contained in:
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.jvm.repl
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
||||
@@ -29,7 +26,6 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.GenericReplCompiler
|
||||
import org.jetbrains.kotlin.cli.jvm.repl.KOTLIN_REPL_JVM_TARGET_PROPERTY
|
||||
import org.jetbrains.kotlin.codegen.CompilationException
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
@@ -39,18 +35,15 @@ import org.jetbrains.kotlin.script.StandardScriptDefinition
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
private const val library = "inline fun<T> foo(fn: () -> T): T = fn()"
|
||||
private const val script = "import foo\nval x = foo { 0 }"
|
||||
|
||||
class ReplCompilerJava8Test : TestCase() {
|
||||
|
||||
var tmpdir : File? = null
|
||||
|
||||
private var disposable: Disposable? = null
|
||||
class ReplCompilerJava8Test : KtUsefulTestCase() {
|
||||
private var tmpdir: File? = null
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
@@ -58,8 +51,6 @@ class ReplCompilerJava8Test : TestCase() {
|
||||
|
||||
File(tmpdir, "library.kt").writeText(library)
|
||||
|
||||
disposable = Disposer.newDisposable()
|
||||
|
||||
val configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.FULL_JDK).apply {
|
||||
put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, PrintingMessageCollector(System.out, MessageRenderer.WITHOUT_PATHS, false))
|
||||
addKotlinSourceRoot(tmpdir!!.absolutePath)
|
||||
@@ -67,19 +58,14 @@ class ReplCompilerJava8Test : TestCase() {
|
||||
put(JVMConfigurationKeys.JVM_TARGET, JvmTarget.JVM_1_8)
|
||||
}
|
||||
|
||||
val environment = KotlinCoreEnvironment.createForProduction(disposable!!, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
val environment =
|
||||
KotlinCoreEnvironment.createForProduction(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
|
||||
val res = KotlinToJVMBytecodeCompiler.compileBunchOfSources(environment)
|
||||
Assert.assertTrue(res)
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
Disposer.dispose(disposable!!)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIncompatibleScriptJvmTargetConfig() {
|
||||
|
||||
val configuration = makeConfiguration().apply {
|
||||
put(JVMConfigurationKeys.JVM_TARGET, JvmTarget.JVM_1_6)
|
||||
}
|
||||
@@ -89,9 +75,7 @@ class ReplCompilerJava8Test : TestCase() {
|
||||
Assert.assertTrue((result as ReplCompileResult.Error).message.contains("error: cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIncompatibleScriptJvmTargetProperty() {
|
||||
|
||||
val configuration = makeConfiguration()
|
||||
System.setProperty(KOTLIN_REPL_JVM_TARGET_PROPERTY, "1.6")
|
||||
try {
|
||||
@@ -104,17 +88,13 @@ class ReplCompilerJava8Test : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompatibleScriptJvmTargetJavaVersionDetect() {
|
||||
|
||||
val configuration = makeConfiguration()
|
||||
val result = runTest(configuration)
|
||||
Assert.assertTrue(result is ReplCompileResult.CompiledClasses)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompatibleScriptJvmTargetProperty() {
|
||||
|
||||
val configuration = makeConfiguration()
|
||||
System.setProperty(KOTLIN_REPL_JVM_TARGET_PROPERTY, "1.8")
|
||||
try {
|
||||
@@ -125,10 +105,13 @@ class ReplCompilerJava8Test : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun makeConfiguration() = KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.FULL_JDK, File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-stdlib.jar"), tmpdir)
|
||||
private fun makeConfiguration() = KotlinTestUtils.newConfiguration(
|
||||
ConfigurationKind.ALL, TestJdkKind.FULL_JDK, File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-stdlib.jar"), tmpdir
|
||||
)
|
||||
|
||||
private fun runTest(configuration: CompilerConfiguration): ReplCompileResult {
|
||||
val replCompiler = GenericReplCompiler(disposable!!, StandardScriptDefinition, configuration, PrintingMessageCollector(System.out, MessageRenderer.WITHOUT_PATHS, false))
|
||||
val collector = PrintingMessageCollector(System.out, MessageRenderer.WITHOUT_PATHS, false)
|
||||
val replCompiler = GenericReplCompiler(testRootDisposable, StandardScriptDefinition, configuration, collector)
|
||||
val state = replCompiler.createState()
|
||||
|
||||
return replCompiler.compile(state, ReplCodeLine(0, 0, script))
|
||||
|
||||
@@ -31,17 +31,15 @@ import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase.resetApplicationToNull
|
||||
import org.junit.Test
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
|
||||
class GenericReplTest : TestCase() {
|
||||
|
||||
@Test
|
||||
class GenericReplTest : KtUsefulTestCase() {
|
||||
fun testReplBasics() {
|
||||
TestRepl().use { repl ->
|
||||
val state = repl.createState()
|
||||
@@ -80,7 +78,6 @@ class GenericReplTest : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReplErrors() {
|
||||
TestRepl().use { repl ->
|
||||
val state = repl.createState()
|
||||
@@ -94,7 +91,6 @@ class GenericReplTest : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReplCodeFormat() {
|
||||
TestRepl().use { repl ->
|
||||
val state = repl.createState()
|
||||
@@ -106,7 +102,6 @@ class GenericReplTest : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRepPackage() {
|
||||
TestRepl().use { repl ->
|
||||
val state = repl.createState()
|
||||
@@ -133,7 +128,6 @@ class GenericReplTest : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompilingReplEvaluator() {
|
||||
TestRepl().use { replBase ->
|
||||
val repl = GenericReplCompilingEvaluator(replBase.replCompiler, replBase.baseClasspath, fallbackScriptArgs = replBase.emptyScriptArgs)
|
||||
@@ -148,7 +142,6 @@ class GenericReplTest : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test256Evals() {
|
||||
TestRepl().use { repl ->
|
||||
val state = repl.createState()
|
||||
|
||||
@@ -33,10 +33,8 @@ import org.jetbrains.kotlin.types.TypeConstructorSubstitution
|
||||
import org.jetbrains.kotlin.types.lowerIfFlexible
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.types.upperIfFlexible
|
||||
import org.junit.Test
|
||||
|
||||
class MemoryOptimizationsTest : KtUsefulTestCase() {
|
||||
@Test
|
||||
fun testBasicFlexibleTypeCase() {
|
||||
val moduleDescriptor = JvmResolveUtil.analyze(
|
||||
KotlinTestUtils.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(myTestRootDisposable, ConfigurationKind.ALL, TestJdkKind.FULL_JDK)
|
||||
@@ -61,7 +59,6 @@ class MemoryOptimizationsTest : KtUsefulTestCase() {
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
fun testSubstitutorDoNotRecreateUnchangedDescriptor() {
|
||||
val text =
|
||||
"""
|
||||
|
||||
@@ -34,10 +34,10 @@ import org.jetbrains.kotlin.script.tryConstructClassFromStringArgs
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import org.jetbrains.kotlin.util.KotlinFrontEndException
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.io.OutputStream
|
||||
import java.io.PrintStream
|
||||
@@ -50,7 +50,6 @@ import kotlin.reflect.KClass
|
||||
import kotlin.script.dependencies.*
|
||||
import kotlin.script.experimental.dependencies.*
|
||||
import kotlin.script.experimental.dependencies.DependenciesResolver.ResolveResult
|
||||
import kotlin.script.experimental.dependencies.AsyncDependenciesResolver
|
||||
import kotlin.script.templates.AcceptedAnnotations
|
||||
import kotlin.script.templates.ScriptTemplateDefinition
|
||||
import kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||
@@ -58,8 +57,7 @@ import kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||
// TODO: the contetnts of this file should go into ScriptTest.kt and replace appropriate xml-based functionality,
|
||||
// as soon as the the latter is removed from the codebase
|
||||
|
||||
class ScriptTemplateTest {
|
||||
@Test
|
||||
class ScriptTemplateTest : KtUsefulTestCase() {
|
||||
fun testScriptWithParam() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib.kts", ScriptWithIntParam::class, null, messageCollector = messageCollector)
|
||||
@@ -70,7 +68,6 @@ class ScriptTemplateTest {
|
||||
assertEqualsTrimmed(NUM_4_LINE + FIB_SCRIPT_OUTPUT_TAIL, out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithClassParameter() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib_cp.kts", ScriptWithClassParam::class, null, runIsolated = false, messageCollector = messageCollector)
|
||||
@@ -81,7 +78,6 @@ class ScriptTemplateTest {
|
||||
assertEqualsTrimmed(NUM_4_LINE + FIB_SCRIPT_OUTPUT_TAIL, out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithBaseClassWithParam() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib_dsl.kts", ScriptWithBaseClass::class, null, runIsolated = false, messageCollector = messageCollector)
|
||||
@@ -92,7 +88,6 @@ class ScriptTemplateTest {
|
||||
assertEqualsTrimmed(NUM_4_LINE + FIB_SCRIPT_OUTPUT_TAIL, out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithDependsAnn() {
|
||||
Assert.assertNull(compileScript("fib_ext_ann.kts", ScriptWithIntParamAndDummyResolver::class, null, includeKotlinRuntime = false))
|
||||
|
||||
@@ -105,7 +100,6 @@ class ScriptTemplateTest {
|
||||
assertEqualsTrimmed(NUM_4_LINE + FIB_SCRIPT_OUTPUT_TAIL, out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithDependsAnn2() {
|
||||
val savedErr = System.err
|
||||
try {
|
||||
@@ -125,7 +119,6 @@ class ScriptTemplateTest {
|
||||
assertEqualsTrimmed(NUM_4_LINE + FIB_SCRIPT_OUTPUT_TAIL, out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithoutParams() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("without_params.kts", ScriptWithoutParams::class, null, messageCollector = messageCollector)
|
||||
@@ -136,7 +129,6 @@ class ScriptTemplateTest {
|
||||
assertEqualsTrimmed("10", out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithOverriddenParam() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("overridden_parameter.kts", ScriptBaseClassWithOverriddenProperty::class, null, messageCollector = messageCollector)
|
||||
@@ -147,7 +139,6 @@ class ScriptTemplateTest {
|
||||
assertEqualsTrimmed("14", out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithArrayParam() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("array_parameter.kts", ScriptWithArrayParam::class, null, messageCollector = messageCollector)
|
||||
@@ -159,7 +150,6 @@ class ScriptTemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithNullableParam() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("nullable_parameter.kts", ScriptWithNullableParam::class, null, messageCollector = messageCollector)
|
||||
@@ -171,7 +161,6 @@ class ScriptTemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptVarianceParams() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("variance_parameters.kts", ScriptVarianceParams::class, null, messageCollector = messageCollector)
|
||||
@@ -183,7 +172,6 @@ class ScriptTemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithNullableProjection() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("nullable_projection.kts", ScriptWithNullableProjection::class, null, messageCollector = messageCollector)
|
||||
@@ -195,7 +183,6 @@ class ScriptTemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithArray2DParam() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("array2d_param.kts", ScriptWithArray2DParam::class, null, messageCollector = messageCollector)
|
||||
@@ -207,7 +194,6 @@ class ScriptTemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithStandardTemplate() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib_std.kts", ScriptTemplateWithArgs::class, runIsolated = false, messageCollector = messageCollector)
|
||||
@@ -219,7 +205,6 @@ class ScriptTemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithPackage() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib.pkg.kts", ScriptWithIntParam::class, messageCollector = messageCollector)
|
||||
@@ -231,7 +216,6 @@ class ScriptTemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithScriptDefinition() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib.kts", ScriptWithIntParam::class, messageCollector = messageCollector)
|
||||
@@ -243,7 +227,6 @@ class ScriptTemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithParamConversion() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib.kts", ScriptWithIntParam::class, messageCollector = messageCollector)
|
||||
@@ -256,7 +239,6 @@ class ScriptTemplateTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptErrorReporting() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
compileScript("fib.kts", ScriptReportingErrors::class, messageCollector = messageCollector)
|
||||
@@ -267,7 +249,6 @@ class ScriptTemplateTest {
|
||||
messageCollector.assertHasMessage("debug", desiredSeverity = CompilerMessageSeverity.LOGGING)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAsyncResolver() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib.kts", ScriptWithAsyncResolver::class, null, messageCollector = messageCollector)
|
||||
@@ -278,42 +259,36 @@ class ScriptTemplateTest {
|
||||
assertEqualsTrimmed(NUM_4_LINE + FIB_SCRIPT_OUTPUT_TAIL, out)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAcceptedAnnotationsSync() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("acceptedAnnotations.kts", ScriptWithAcceptedAnnotationsSyncResolver::class, null, messageCollector = messageCollector)
|
||||
Assert.assertNotNull("Compilation failed:\n$messageCollector", aClass)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAcceptedAnnotationsAsync() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("acceptedAnnotations.kts", ScriptWithAcceptedAnnotationsAsyncResolver::class, null, messageCollector = messageCollector)
|
||||
Assert.assertNotNull("Compilation failed:\n$messageCollector", aClass)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAcceptedAnnotationsLegacy() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("acceptedAnnotations.kts", ScriptWithAcceptedAnnotationsLegacyResolver::class, null, messageCollector = messageCollector)
|
||||
Assert.assertNotNull("Compilation failed:\n$messageCollector", aClass)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSeveralConstructors() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib.kts", ScriptWithSeveralConstructorsResolver::class, null, messageCollector = messageCollector)
|
||||
Assert.assertNotNull("Compilation failed:\n$messageCollector", aClass)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConstructorWithDefaultArgs() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("fib.kts", ScriptWithDefaultArgsResolver::class, null, messageCollector = messageCollector)
|
||||
Assert.assertNotNull("Compilation failed:\n$messageCollector", aClass)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testThrowing() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
compileScript("fib.kts", ScriptWithThrowingResolver::class, null, messageCollector = messageCollector)
|
||||
@@ -321,7 +296,6 @@ class ScriptTemplateTest {
|
||||
messageCollector.assertHasMessage("Exception from resolver", desiredSeverity = CompilerMessageSeverity.ERROR)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSmokeScriptException() {
|
||||
val messageCollector = TestMessageCollector()
|
||||
val aClass = compileScript("smoke_exception.kts", ScriptWithArrayParam::class, messageCollector = messageCollector)
|
||||
@@ -337,7 +311,6 @@ class ScriptTemplateTest {
|
||||
Assert.assertTrue(exceptionThrown)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testScriptWithNoMatchingTemplate() {
|
||||
try {
|
||||
compileScript("fib.kts", ScriptWithDifferentFileNamePattern::class, null)
|
||||
|
||||
Reference in New Issue
Block a user