Skip to content

Commit

Permalink
Switch to JUnit5 (but running multiple tests at once causes error)
Browse files Browse the repository at this point in the history
Duplicate registration for EP 'com.intellij.virtualFileManagerListener': first in FakeIdForTests, second in FakeIdForTests
  • Loading branch information
SerVB committed Oct 1, 2021
1 parent 73cea7c commit 236ab5c
Show file tree
Hide file tree
Showing 6 changed files with 6,908 additions and 3,219 deletions.
10 changes: 7 additions & 3 deletions python/box.tests/build.gradle.kts
Expand Up @@ -18,7 +18,9 @@ dependencies {
testRuntime(intellijDep())

testCompile(protobufFull())
testCompile(projectTests(":compiler:tests-common"))
testImplementation(projectTests(":compiler:tests-common"))
testImplementation(projectTests(":compiler:test-infrastructure"))
testImplementation(projectTests(":compiler:tests-common-new"))
testCompileOnly(project(":compiler:frontend"))
testCompileOnly(project(":compiler:cli"))
testCompileOnly(project(":compiler:cli-js"))
Expand All @@ -35,7 +37,7 @@ dependencies {
testCompile(project(":js:js.dce"))
testCompile(project(":js:js.engines"))
testCompile(project(":compiler:incremental-compilation-impl"))
testCompile(commonDep("junit:junit"))
testApiJUnit5()
testCompile(projectTests(":kotlin-build-common"))
testCompile(projectTests(":generators:test-generator"))

Expand Down Expand Up @@ -67,12 +69,14 @@ sourceSets {
"test" { projectDefault() }
}

projectTest("pythonTest", parallel = true) {
projectTest("pythonTest", jUnit5Enabled = true) {
dependsOn(":dist")
workingDir = rootDir
jvmArgs!!.removeIf { it.contains("-Xmx") }
maxHeapSize = "3g"

useJUnitPlatform()

dependsOn(":kotlin-stdlib-js-ir:compileKotlinJs") // todo: remove js stuff
systemProperty("kotlin.js.full.stdlib.path", "libraries/stdlib/js-ir/build/classes/kotlin/js/main") // todo: remove js stuff
dependsOn(":kotlin-stdlib-js-ir-minimal-for-test:compileKotlinJs") // todo: remove js stuff
Expand Down
Expand Up @@ -5,17 +5,17 @@

package org.jetbrains.kotlin.generators.tests

import org.jetbrains.kotlin.generators.impl.generateTestGroupSuite
import org.jetbrains.kotlin.python.test.ir.semantics.AbstractIrPythonCodegenBoxErrorTest
import org.jetbrains.kotlin.python.test.ir.semantics.AbstractIrPythonCodegenBoxTest
import org.jetbrains.kotlin.python.test.ir.semantics.AbstractIrPythonCodegenInlineTest
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.test.generators.generateTestGroupSuiteWithJUnit5

fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")

generateTestGroupSuite(args) {
testGroup("python/box.tests/test", "compiler/testData", testRunnerMethodName = "runTest0") {
generateTestGroupSuiteWithJUnit5(args) {
testGroup("python/box.tests/test", "compiler/testData") {
testClass<AbstractIrPythonCodegenBoxTest> {
model("codegen/box", targetBackend = TargetBackend.PYTHON)
}
Expand Down
Expand Up @@ -5,6 +5,7 @@

package org.jetbrains.kotlin.python.test

import com.intellij.openapi.Disposable
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.openapi.vfs.VirtualFileManager
Expand Down Expand Up @@ -48,6 +49,9 @@ import org.jetbrains.kotlin.test.util.KtTestUtil
import org.jetbrains.kotlin.utils.DFS
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
import org.jetbrains.kotlin.utils.addToStdlib.measureTimeMillisWithResult
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.TestInfo
import java.io.Closeable
import java.io.File
import java.lang.Boolean.getBoolean
Expand All @@ -63,12 +67,30 @@ abstract class BasicIrBoxTest(
private val pathToTestDir: String,
testGroupOutputDirPrefix: String,
pathToRootOutputDir: String = TEST_DATA_DIR_PATH,
) : KotlinTestWithEnvironment() {
) {
private val pythonBackend = TargetBackend.PYTHON

private val testGroupOutputDirForCompilation = File(pathToRootOutputDir + "out/" + testGroupOutputDirPrefix)

fun doTest(filePath: String) {
private val myTestRootDisposable: Disposable = TestDisposable()

private var environment: KotlinCoreEnvironment? = null
private lateinit var testInfo: TestInfo

@BeforeEach
fun setUp(testInfo: TestInfo) {
environment = createEnvironment()
this.testInfo = testInfo
}

@AfterEach
fun tearDown() {
environment = null
}

private val project get() = environment!!.project

protected fun runTest(filePath: String) {
val pars = MainCallParameters.noCall()
doTest(filePath, "OK", pars)
}
Expand Down Expand Up @@ -190,7 +212,7 @@ abstract class BasicIrBoxTest(
}

private fun outputFileSimpleName(): String {
return getTestName(true)
return testInfo.displayName
}

private fun outputFileName(directory: File) = directory.absolutePath + "/" + outputFileSimpleName()
Expand Down Expand Up @@ -250,7 +272,7 @@ abstract class BasicIrBoxTest(
sourceDirs: List<String>, module: TestModule, dependencies: List<String>, allDependencies: List<String>, friends: List<String>,
multiModule: Boolean, tmpDir: File, expectActualLinker: Boolean, errorIgnorancePolicy: ErrorTolerancePolicy
): JsConfig {
val configuration = environment.configuration.copy()
val configuration = environment!!.configuration.copy()

configuration.put(CommonConfigurationKeys.DISABLE_INLINE, module.inliningDisabled)
module.languageVersionSettings?.let { languageVersionSettings ->
Expand Down Expand Up @@ -379,8 +401,8 @@ abstract class BasicIrBoxTest(
val hasFilesToRecompile get() = files.any { it.recompile }
}

override fun createEnvironment() =
KotlinCoreEnvironment.createForTests(testRootDisposable, CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES)
private fun createEnvironment() =
KotlinCoreEnvironment.createForTests(myTestRootDisposable, CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES)

private fun translateFiles(
units: List<TranslationUnit>,
Expand Down Expand Up @@ -512,6 +534,10 @@ abstract class BasicIrBoxTest(
}

companion object {
init {
System.setProperty("java.awt.headless", "true")
}

val METADATA_CACHE = (JsConfig.JS_STDLIB + JsConfig.JS_KOTLIN_TEST).flatMap { path ->
KotlinJavascriptMetadataUtils.loadMetadata(path).map { metadata ->
val parts = KotlinJavascriptSerializationUtil.readModuleAsProto(metadata.body, metadata.version)
Expand Down Expand Up @@ -549,4 +575,14 @@ abstract class BasicIrBoxTest(
private const val TEST_FUNCTION = "box"
private const val OLD_MODULE_SUFFIX = "-old"
}

protected class TestDisposable : Disposable {
@Volatile
var isDisposed = false
private set

override fun dispose() {
isDisposed = true
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 236ab5c

Please sign in to comment.