diff --git a/buildSrc/src/main/kotlin/sourceSets.kt b/buildSrc/src/main/kotlin/sourceSets.kt index 95f58858491..9991bbe3035 100644 --- a/buildSrc/src/main/kotlin/sourceSets.kt +++ b/buildSrc/src/main/kotlin/sourceSets.kt @@ -30,6 +30,7 @@ val SourceSet.projectDefault: Project.() -> Unit } "test" -> { java.srcDirs("test", "tests") + this@projectDefault.resources.srcDir("testResources") } } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt index 6c9c67719ae..2b1ba524c7e 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt @@ -476,11 +476,19 @@ class KotlinCoreEnvironment private constructor( fun getOrCreateApplicationEnvironmentForProduction( parentDisposable: Disposable, configuration: CompilerConfiguration + ): KotlinCoreApplicationEnvironment = getOrCreateApplicationEnvironment(parentDisposable, configuration, unitTestMode = false) + + fun getOrCreateApplicationEnvironmentForTests( + parentDisposable: Disposable, configuration: CompilerConfiguration + ): KotlinCoreApplicationEnvironment = getOrCreateApplicationEnvironment(parentDisposable, configuration, unitTestMode = true) + + private fun getOrCreateApplicationEnvironment( + parentDisposable: Disposable, configuration: CompilerConfiguration, unitTestMode: Boolean ): KotlinCoreApplicationEnvironment { synchronized(APPLICATION_LOCK) { if (ourApplicationEnvironment == null) { val disposable = Disposer.newDisposable() - ourApplicationEnvironment = createApplicationEnvironment(disposable, configuration, unitTestMode = false) + ourApplicationEnvironment = createApplicationEnvironment(disposable, configuration, unitTestMode) ourProjectCount = 0 Disposer.register(disposable, Disposable { synchronized(APPLICATION_LOCK) { diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt.as42 b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt.as42 index c1eeff31cc6..388d832775e 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt.as42 +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCoreEnvironment.kt.as42 @@ -475,11 +475,19 @@ class KotlinCoreEnvironment private constructor( fun getOrCreateApplicationEnvironmentForProduction( parentDisposable: Disposable, configuration: CompilerConfiguration + ): KotlinCoreApplicationEnvironment = getOrCreateApplicationEnvironment(parentDisposable, configuration, unitTestMode = false) + + fun getOrCreateApplicationEnvironmentForTests( + parentDisposable: Disposable, configuration: CompilerConfiguration + ): KotlinCoreApplicationEnvironment = getOrCreateApplicationEnvironment(parentDisposable, configuration, unitTestMode = true) + + private fun getOrCreateApplicationEnvironment( + parentDisposable: Disposable, configuration: CompilerConfiguration, unitTestMode: Boolean ): KotlinCoreApplicationEnvironment { synchronized(APPLICATION_LOCK) { if (ourApplicationEnvironment == null) { val disposable = Disposer.newDisposable() - ourApplicationEnvironment = createApplicationEnvironment(disposable, configuration, unitTestMode = false) + ourApplicationEnvironment = createApplicationEnvironment(disposable, configuration, unitTestMode) ourProjectCount = 0 Disposer.register(disposable, Disposable { synchronized(APPLICATION_LOCK) { diff --git a/compiler/fir/analysis-tests/build.gradle.kts b/compiler/fir/analysis-tests/build.gradle.kts index 580df37991f..867488761da 100644 --- a/compiler/fir/analysis-tests/build.gradle.kts +++ b/compiler/fir/analysis-tests/build.gradle.kts @@ -27,6 +27,7 @@ dependencies { testApi(platform("org.junit:junit-bom:5.7.0")) testApi("org.junit.jupiter:junit-jupiter") testApi("org.junit.platform:junit-platform-commons:1.7.0") + testApi("org.junit.platform:junit-platform-launcher:1.7.0") testCompileOnly(project(":kotlin-reflect-api")) testRuntimeOnly(project(":kotlin-reflect")) diff --git a/compiler/tests-common-new/build.gradle.kts b/compiler/tests-common-new/build.gradle.kts index 5bbcc3e4c49..c3164bb369d 100644 --- a/compiler/tests-common-new/build.gradle.kts +++ b/compiler/tests-common-new/build.gradle.kts @@ -21,6 +21,7 @@ dependencies { testApi(platform("org.junit:junit-bom:5.7.0")) testApi("org.junit.jupiter:junit-jupiter") testApi("org.junit.platform:junit-platform-commons:1.7.0") + testApi("org.junit.platform:junit-platform-launcher:1.7.0") testApi(projectTests(":compiler:test-infrastructure")) testApi(projectTests(":compiler:test-infrastructure-utils")) testApi(projectTests(":compiler:tests-compiler-utils")) diff --git a/compiler/tests-common-new/testResources/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/compiler/tests-common-new/testResources/META-INF/services/org.junit.platform.launcher.TestExecutionListener new file mode 100644 index 00000000000..81f29caff12 --- /dev/null +++ b/compiler/tests-common-new/testResources/META-INF/services/org.junit.platform.launcher.TestExecutionListener @@ -0,0 +1 @@ +org.jetbrains.kotlin.test.ApplicationEnvironmentDisposer diff --git a/compiler/tests-common-new/testResources/junit-platform.properties b/compiler/tests-common-new/testResources/junit-platform.properties new file mode 100644 index 00000000000..dd6225018bb --- /dev/null +++ b/compiler/tests-common-new/testResources/junit-platform.properties @@ -0,0 +1,2 @@ +junit.jupiter.execution.parallel.enabled=true +junit.jupiter.execution.parallel.mode.default=concurrent diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/ApplicationEnvironmentDisposer.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/ApplicationEnvironmentDisposer.kt new file mode 100644 index 00000000000..02f1230a327 --- /dev/null +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/ApplicationEnvironmentDisposer.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.test + +import com.intellij.openapi.Disposable +import com.intellij.openapi.util.Disposer +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.junit.platform.launcher.TestExecutionListener +import org.junit.platform.launcher.TestPlan + +class ApplicationEnvironmentDisposer : TestExecutionListener { + companion object { + val ROOT_DISPOSABLE: Disposable = Disposer.newDisposable() + } + + override fun testPlanExecutionFinished(testPlan: TestPlan) { + KotlinCoreEnvironment.disposeApplicationEnvironment() + Disposer.dispose(ROOT_DISPOSABLE) + } +} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/CompilerConfigurationProvider.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/CompilerConfigurationProvider.kt index cf9b0c9d140..6276856ba82 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/CompilerConfigurationProvider.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/CompilerConfigurationProvider.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.platform.js.isJs import org.jetbrains.kotlin.platform.jvm.isJvm import org.jetbrains.kotlin.platform.konan.isNative import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.test.ApplicationEnvironmentDisposer import org.jetbrains.kotlin.test.model.TestFile import org.jetbrains.kotlin.test.model.TestModule import java.io.File @@ -72,7 +73,11 @@ class CompilerConfigurationProviderImpl( platform.isCommon() -> EnvironmentConfigFiles.METADATA_CONFIG_FILES else -> error("Unknown platform: $platform") } - val projectEnv = KotlinCoreEnvironment.createProjectEnvironmentForTests(testRootDisposable, CompilerConfiguration()) + val applicationEnvironment = KotlinCoreEnvironment.getOrCreateApplicationEnvironmentForTests( + ApplicationEnvironmentDisposer.ROOT_DISPOSABLE, + CompilerConfiguration() + ) + val projectEnv = KotlinCoreEnvironment.ProjectEnvironment(testRootDisposable, applicationEnvironment) KotlinCoreEnvironment.createForTests( projectEnv, createCompilerConfiguration(module, projectEnv.project),