diff --git a/.idea/runConfigurations/Test__KMM.xml b/.idea/runConfigurations/Test__KMM.xml new file mode 100644 index 00000000000..7b1ccaa128b --- /dev/null +++ b/.idea/runConfigurations/Test__KMM.xml @@ -0,0 +1,20 @@ + + + + + + + + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 1feaebda77f..9973751bc43 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -827,6 +827,21 @@ tasks { } } + register("kmmTest", AggregateTest::class) { + dependsOn( + ":idea:idea-gradle:test", + ":idea:test", + ":compiler:test", + ":js:js.tests:test" + ) + if (Ide.IJ193.orHigher()) + dependsOn(":kotlin-gradle-plugin-integration-tests:test") + if (Ide.AS40.orHigher()) + dependsOn(":kotlin-ultimate:ide:android-studio-native:test") + + testPatternFile = file("tests/mpp/kmm-patterns.csv") + } + register("test") { doLast { throw GradleException("Don't use directly, use aggregate tasks *-check instead") diff --git a/buildSrc/src/main/kotlin/AggregateTest.kt b/buildSrc/src/main/kotlin/AggregateTest.kt new file mode 100644 index 00000000000..d46161f24ee --- /dev/null +++ b/buildSrc/src/main/kotlin/AggregateTest.kt @@ -0,0 +1,72 @@ +/* + * Copyright 2010-2020 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. + */ + +import org.gradle.api.GradleException +import org.gradle.api.tasks.* +import org.gradle.api.tasks.testing.Test +import java.io.File + +// You can see "How To" via link: https://jetbrains.quip.com/xQ2WAUy9bZmy/How-to-use-AggregateTest-task +open class AggregateTest : Test() { // Inherit from Test to see test results in IDEA Test viewer + private var patterns: MutableMap> = mutableMapOf() + + @InputFile + lateinit var testPatternFile: File + + init { + // Set empty FileCollection to avoid NPE when initializing a base 'Test' class + classpath = project.objects.fileCollection() + testClassesDirs = project.objects.fileCollection() + + project.gradle.taskGraph.whenReady { + if (allTasks.filterIsInstance().isNotEmpty()) { + initPatterns() + allTasks.filterIsInstance().forEach { testTask -> subTaskConfigure(testTask) } + + if (!project.gradle.startParameter.taskNames.all { project.tasks.findByPath(it) is AggregateTest }) { + logger.warn("Please, don't use AggregateTest and non-AggregateTest test tasks together. You can get incorrect results.") + } + } + } + } + + private fun initPatterns() { + if (!testPatternFile.exists()) + throw GradleException("File with test patterns is not found") + testPatternFile + .readLines() + .asSequence() + .filter { it.isNotEmpty() } + .forEach { line -> + // patternType is exclude or include value + val (pattern, patternType) = line.split(',').map { it.trim() } + patterns.getOrPut(patternType) { mutableListOf() }.add(pattern) + } + } + + private fun subTaskConfigure(testTask: Test) { + testTask.outputs.upToDateWhen { false } + testTask.ignoreFailures = true + testTask.filter { + isFailOnNoMatchingTests = false + patterns["include"]?.let { + it.forEach { pattern -> + includeTestsMatching(pattern) + } + } + patterns["exclude"]?.let { + it.forEach { pattern -> + excludeTestsMatching(pattern) + } + } + } + } + + @Override + @TaskAction + override fun executeTests() { + // Do nothing + } +} \ No newline at end of file diff --git a/tests/mpp/kmm-patterns.csv b/tests/mpp/kmm-patterns.csv new file mode 100644 index 00000000000..adab59c623e --- /dev/null +++ b/tests/mpp/kmm-patterns.csv @@ -0,0 +1,18 @@ +com.jetbrains.mpp.versions*, include +*GradleMultiplatformHighlightingTest*, include +*MultiplatformKaptProjectImportingTest*, include +*MultiplatformProjectImportingTest*, include +*DiagnosticsTestGenerated*, include +*DiagnosticsTestWithStdLibGenerated*, include +*HierarchicalMultiplatformProjectImportingTest*, include +*MultiplatformAnalysisTest*, include +*MultiPlatformIntegrationTestGenerated*, include +*LightAnalysisModeTestGenerated$Multiplatform*, include +*IrJsCodegenBoxTestGenerated$Multiplatform*, include +*IrJsCodegenBoxES6TestGenerated$Multiplatform*, include +*QuickFixMultiModuleTestGenerated*, include +*HierarchicalExpectActualTestGenerated*, include +*HierarchicalMppIT*, include +*MultiplatformGradleIT*, include +*KotlinProjectIT*, include +*NewMultiplatformIT*, include \ No newline at end of file