diff --git a/.idea/runConfigurations/Generate_MPP_Tests.xml b/.idea/runConfigurations/Generate_MPP_Tests.xml
new file mode 100644
index 00000000000..7a5e9d6509e
--- /dev/null
+++ b/.idea/runConfigurations/Generate_MPP_Tests.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+ true
+ true
+ false
+
+
+
\ No newline at end of file
diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/NewTestGeneratorImpl.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/NewTestGeneratorImpl.kt
index 6a1ce23e19b..fbc2b6d1645 100644
--- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/NewTestGeneratorImpl.kt
+++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/NewTestGeneratorImpl.kt
@@ -30,7 +30,8 @@ private val METHOD_GENERATORS = listOf(
)
class NewTestGeneratorImpl(
- additionalMethodGenerators: List>
+ additionalMethodGenerators: List>,
+ private val generatorName: String = TEST_GENERATOR_NAME,
) : TestGenerator(METHOD_GENERATORS + additionalMethodGenerators) {
private val GENERATED_FILES = HashSet()
@@ -155,7 +156,7 @@ class NewTestGeneratorImpl(
p.println("import java.io.File;")
p.println("import java.util.regex.Pattern;")
p.println()
- p.println("/** This class is generated by {@link ", TEST_GENERATOR_NAME, "}. DO NOT MODIFY MANUALLY */")
+ p.println("/** This class is generated by {@link ", generatorName, "}. DO NOT MODIFY MANUALLY */")
p.generateSuppressAllWarnings()
diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts
index 7938a2ec320..4f9edc08b22 100644
--- a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts
+++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle.kts
@@ -10,6 +10,8 @@ pill {
variant = PillExtension.Variant.FULL
}
+testsJar()
+
val kotlinGradlePluginTest = project(":kotlin-gradle-plugin").sourceSets.named("test").map { it.output }
dependencies {
diff --git a/libraries/tools/kotlin-project-model-tests-generator/build.gradle.kts b/libraries/tools/kotlin-project-model-tests-generator/build.gradle.kts
new file mode 100644
index 00000000000..8c8fbeca467
--- /dev/null
+++ b/libraries/tools/kotlin-project-model-tests-generator/build.gradle.kts
@@ -0,0 +1,29 @@
+plugins {
+ kotlin("jvm")
+ id("jps-compatible")
+ id("java-test-fixtures")
+}
+
+dependencies {
+ testImplementation(kotlinStdlib())
+ testApi(projectTests(":compiler:cli"))
+ testApi(projectTests(":generators:test-generator"))
+ testApi(testFixtures(project(":kotlin-project-model")))
+ testApi(project(":kotlin-project-model"))
+ testApi(projectTests(":kotlin-gradle-plugin-integration-tests"))
+ testCompileOnly(project(":kotlin-reflect-api"))
+ testImplementation(project(":kotlin-reflect"))
+ testImplementation(projectTests(":compiler:test-infrastructure-utils"))
+ testImplementation(projectTests(":compiler:test-infrastructure"))
+ testImplementation(projectTests(":compiler:tests-common-new"))
+ testImplementation(projectTests(":js:js.tests"))
+ testApiJUnit5()
+
+ if (Ide.IJ()) {
+ testCompileOnly(jpsBuildTest())
+ testApi(jpsBuildTest())
+ }
+}
+
+val generateKpmTests by generator("org.jetbrains.kotlin.kpm.GenerateKpmTestsKt") {
+}
diff --git a/libraries/tools/kotlin-project-model-tests-generator/src/test/kotlin/org/jetbrains/kotlin/kpm/GenerateKpmTests.kt b/libraries/tools/kotlin-project-model-tests-generator/src/test/kotlin/org/jetbrains/kotlin/kpm/GenerateKpmTests.kt
new file mode 100644
index 00000000000..6f0c0489b31
--- /dev/null
+++ b/libraries/tools/kotlin-project-model-tests-generator/src/test/kotlin/org/jetbrains/kotlin/kpm/GenerateKpmTests.kt
@@ -0,0 +1,14 @@
+/*
+ * Copyright 2010-2022 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.kpm
+
+import org.jetbrains.kotlin.project.model.infra.generate.generateKpmTestCases
+
+fun main() {
+ generateKpmTestCases {
+ // Add generated tests here
+ }
+}
diff --git a/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/generate/KpmCoreCasesTestClassModel.kt b/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/generate/KpmCoreCasesTestClassModel.kt
index dbe74547ab2..ac7bffcef0c 100644
--- a/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/generate/KpmCoreCasesTestClassModel.kt
+++ b/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/generate/KpmCoreCasesTestClassModel.kt
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.project.model.infra.generate
import org.jetbrains.kotlin.generators.model.AnnotationModel
import org.jetbrains.kotlin.generators.model.MethodModel
import org.jetbrains.kotlin.generators.model.TestClassModel
-import org.jetbrains.kotlin.project.model.coreCases.KpmCoreCase
+import org.jetbrains.kotlin.project.model.coreCases.KpmTestCaseDescriptor
import org.jetbrains.kotlin.project.model.infra.KpmTestCase
import org.jetbrains.kotlin.project.model.infra.generateTemplateCanonicalFileStructure
import org.jetbrains.kotlin.test.util.KtTestUtil
@@ -55,7 +55,7 @@ class KpmCoreCasesTestClassModel(
get() = emptyList() // Don't need to annotate with `@ExtendWith`, because we inherit [KpmCoreCasesTestRunner]
private fun doCollectMethods(): Collection {
- val allCoreCasesNames: Set = KpmCoreCase.allCasesNames
+ val allCoreCasesNames: Set = KpmTestCaseDescriptor.allCasesNames
val allAdditionalTestdata: Set = additionalTestDataRoot.listFiles().orEmpty().toSet()
val methodModelsForCoreCasesWithExistingTestData = allAdditionalTestdata.map { testDataForCase ->
@@ -83,9 +83,9 @@ class KpmCoreCasesTestClassModel(
val methodModelsForCoreCasesWithoutTestData = coreCasesNamesWithoutTestData.map {
val expectedTestDataPath = additionalTestDataRoot.resolve(it)
- val kpmCoreCase = KpmCoreCase.allCasesByNames[it]!!
+ val kpmTestCaseDescriptor = KpmTestCaseDescriptor.allCaseDescriptorsByNames[it]!!
println("Generating template sources testdata for uncovered KPM Core Case $it at ${additionalTestDataRoot.path}")
- kpmCoreCase.case.generateTemplateCanonicalFileStructure(expectedTestDataPath)
+ kpmTestCaseDescriptor.generateTemplateCanonicalFileStructure(expectedTestDataPath)
KpmCoreCaseTestMethodModel(it, additionalTestDataRoot, expectedTestDataPath)
}
diff --git a/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/generate/generateTestMethods.kt b/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/generate/generateTestMethods.kt
new file mode 100644
index 00000000000..33f7458b073
--- /dev/null
+++ b/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/generate/generateTestMethods.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2010-2022 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.project.model.infra.generate
+
+import org.jetbrains.kotlin.generators.*
+import org.jetbrains.kotlin.generators.model.*
+import org.jetbrains.kotlin.project.model.infra.KpmCoreCasesTestRunner
+import java.io.File
+
+fun generateKpmTestCases(
+ dryRun: Boolean = false,
+ init: TestGroupSuite.() -> Unit
+) {
+ val suite = TestGroupSuite(DefaultTargetBackendComputer).apply {
+ init()
+ }
+ for (testGroup in suite.testGroups) {
+ for (testClass in testGroup.testClasses) {
+ val (changed, testSourceFilePath) = NewTestGeneratorImpl(
+ listOf(KpmCoreCaseTestMethodGenerator),
+ generatorName = "GenerateKpmTests.kt"
+ ).generateAndSave(testClass, dryRun)
+ if (changed) {
+ InconsistencyChecker.inconsistencyChecker(dryRun).add(testSourceFilePath)
+ }
+ }
+ }
+}
+
+// NB: [testRunnersSourceRoot] is a root-folder against which will be resolved a usual java-like folder structure
+// based on packages of T
+// E.g.: testRunnersSourceRoot = "foo/bar", T == "org.jetbrains.kotlin.AbstractMyClass"
+// Then the resulting file will be created at "foo/bar/org/jetbrains/kotlin"
+inline fun TestGroupSuite.kpmRunnerWithSources(testRunnersSourceRoot: String, testSourcesPath: String) {
+ testGroup(testRunnersSourceRoot, testSourcesPath) {
+ testClass {
+ testModels += KpmCoreCasesTestClassModel(File(testSourcesPath))
+ }
+ }
+}
+
+internal fun generateTestMethodsTemplateForCases(cases: Set, generateTestMethodBody: (String) -> String = { "TODO()" }): String {
+ return buildString {
+ for (case in cases) {
+ append(
+ """
+ fun test$case(case: KpmTestCase) {
+ ${generateTestMethodBody(case)}
+ }
+
+ """.trimIndent()
+ )
+ }
+ }
+}
diff --git a/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/sources.kt b/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/sources.kt
index fb3b3d2025a..a128d52a2c1 100644
--- a/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/sources.kt
+++ b/libraries/tools/kotlin-project-model/src/testFixtures/kotlin/org/jetbrains/kotlin/project/model/infra/sources.kt
@@ -99,7 +99,7 @@ private fun TestKpmFragment.canonicalSourceFolderRelative(): File {
fragmentName
)
- return File(pathParts.joinToString(separator = "/"))
+ return File(pathParts.joinToString(separator = File.separator))
}
private val PLACEHOLDER_SOURCES_TEXT = """
diff --git a/settings.gradle b/settings.gradle
index 82a072161a1..252412d3574 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -243,6 +243,7 @@ include ":kotlin-imports-dumper-compiler-plugin",
":generators:test-generator",
":tools:kotlinp",
":kotlin-project-model",
+ ":kotlin-project-model-tests-generator",
":kotlin-gradle-plugin-api",
":kotlin-gradle-plugin-idea",
":kotlin-gradle-plugin-idea-proto",
@@ -733,6 +734,7 @@ project(':kotlin-sam-with-receiver-compiler-plugin.cli').projectDir = "$rootDir/
project(':tools:kotlinp').projectDir = "$rootDir/libraries/tools/kotlinp" as File
project(':kotlin-project-model').projectDir = "$rootDir/libraries/tools/kotlin-project-model" as File
+project(':kotlin-project-model-tests-generator').projectDir = "$rootDir/libraries/tools/kotlin-project-model-tests-generator" as File
project(':kotlin-gradle-plugin-api').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-api" as File
project(':kotlin-gradle-plugin-idea').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-idea" as File
project(':kotlin-gradle-plugin-idea-proto').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-idea-proto" as File