From 82db5fa443ee3566f177f65746e15d0b184371f0 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Wed, 17 Nov 2021 18:43:13 +0100 Subject: [PATCH] Analysis API: refactor test generation dsl --- .../analysis/api/GenerateAnalysisApiTests.kt | 274 +----------------- .../tests/analysis/api/analysisApi.kt | 181 ++++++++++++ .../generators/tests/analysis/api/dsl.kt | 71 +++++ .../tests/analysis/api/firLowLevel.kt | 110 +++++++ .../kotlin/generators/TestGenerationDSL.kt | 2 +- 5 files changed, 370 insertions(+), 268 deletions(-) create mode 100644 generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/analysisApi.kt create mode 100644 generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/dsl.kt create mode 100644 generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/firLowLevel.kt diff --git a/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/GenerateAnalysisApiTests.kt b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/GenerateAnalysisApiTests.kt index b4660fb5c34..f802716fdb0 100644 --- a/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/GenerateAnalysisApiTests.kt +++ b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/GenerateAnalysisApiTests.kt @@ -5,277 +5,17 @@ package org.jetbrains.kotlin.generators.tests.analysis.api -import org.jetbrains.kotlin.analysis.api.descriptors.test.AbstractKtFe10ResolveCallTest -import org.jetbrains.kotlin.analysis.api.descriptors.test.components.* -import org.jetbrains.kotlin.analysis.api.descriptors.test.symbols.AbstractKtFe10CompileTimeConstantEvaluatorTest -import org.jetbrains.kotlin.analysis.api.descriptors.test.symbols.AbstractKtFe10SymbolByFqNameTest -import org.jetbrains.kotlin.analysis.api.descriptors.test.symbols.AbstractKtFe10SymbolByPsiTest -import org.jetbrains.kotlin.analysis.api.descriptors.test.symbols.AbstractKtFe10SymbolByReferenceTest -import org.jetbrains.kotlin.analysis.api.fir.AbstractFirReferenceResolveTest -import org.jetbrains.kotlin.analysis.api.fir.components.* -import org.jetbrains.kotlin.analysis.api.fir.scopes.AbstractFirDelegateMemberScopeTest -import org.jetbrains.kotlin.analysis.api.fir.scopes.AbstractFirFileScopeTest -import org.jetbrains.kotlin.analysis.api.fir.scopes.AbstractFirMemberScopeByFqNameTest -import org.jetbrains.kotlin.analysis.api.fir.symbols.AbstractFirSymbolByFqNameTest -import org.jetbrains.kotlin.analysis.api.fir.symbols.AbstractFirSymbolByPsiTest -import org.jetbrains.kotlin.analysis.api.fir.symbols.AbstractFirSymbolByReferenceTest -import org.jetbrains.kotlin.analysis.low.level.api.fir.* -import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.AbstractDiagnosticTraversalCounterTest -import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.AbstractFirContextCollectionTest -import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.AbstractDiagnosisCompilerTestDataSpecTest -import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.AbstractDiagnosisCompilerTestDataTest -import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.AbstractFileStructureTest -import org.jetbrains.kotlin.analysis.low.level.api.fir.resolve.AbstractInnerDeclarationsResolvePhaseTest +import org.jetbrains.kotlin.generators.TestGroupSuite import org.jetbrains.kotlin.generators.generateTestGroupSuiteWithJUnit5 -import org.jetbrains.kotlin.generators.util.TestGeneratorUtil -import org.jetbrains.kotlin.spec.utils.GeneralConfiguration -import org.jetbrains.kotlin.spec.utils.tasks.detectDirsWithTestsMapFileOnly -import org.jetbrains.kotlin.test.runners.AbstractFirDiagnosticTestSpec fun main(args: Array) { System.setProperty("java.awt.headless", "true") - - val excludedFirTestdataPattern = "^(.+)\\.fir\\.kts?\$" - - generateTestGroupSuiteWithJUnit5(args) { - testGroup("analysis/analysis-api-fir/tests", "analysis/analysis-api/testData") { - testClass { - model("analysisSession/resolveCall") - } - - testClass { - model("scopes/memberScopeByFqName") - } - - testClass { - model("scopes/fileScopeTest", extension = "kt") - } - - testClass { - model("scopes/delegatedMemberScope") - } - - testClass { - model("symbols/symbolByPsi") - } - - testClass { - model("symbols/symbolByFqName") - } - - testClass { - model("symbols/symbolByReference") - } - - testClass { - model("components/compileTimeConstantEvaluator") - } - - testClass { - model("components/expectedExpressionType") - } - - testClass { - model("components/functionClassKind") - } - - testClass { - model("components/overriddenDeclarations") - } - - testClass { - model("components/expressionType") - } - - testClass { - model("components/declarationRenderer") - } - - testClass { - model("referenceResolve", pattern = TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME) - } - - testClass { - model("components/importOptimizer", pattern = TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME) - } - - testClass { - model("components/hasCommonSubtype") - } - - testClass { - model("components/getSuperTypes") - } - - testClass { - model("components/psiTypeProvider") - } - - testClass { - model("components/expressionPsiType") - } - - testClass { - model("components/smartCastInfo") - } - - testClass { - model("components/whenMissingCases") - } - } - - testGroup("analysis/analysis-api-fe10/tests", "analysis/analysis-api/testData") { - testClass { - model("analysisSession/resolveCall") - } - -// testClass { -// model("scopes/memberScopeByFqName") -// } - -// testClass { -// model("scopes/fileScopeTest", extension = "kt") -// } - - testClass { - model("symbols/symbolByPsi") - } - - testClass { - model("components/compileTimeConstantEvaluator") - } - - testClass { - model("symbols/symbolByFqName") - } - - testClass { - model("symbols/symbolByReference") - } - - testClass { - model("components/expectedExpressionType") - } - -// testClass { -// model("components/functionClassKind") -// } - - testClass { - model("components/overriddenDeclarations") - } - - testClass { - model("components/expressionType") - } - - testClass { - model("components/declarationRenderer") - } - -// testClass { -// model("referenceResolve", pattern = TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME) -// } - - testClass { - model("components/hasCommonSubtype") - } - - testClass { - model("components/smartCastInfo") - } - - testClass { - model("components/whenMissingCases") - } - } - - testGroup("analysis/low-level-api-fir/tests", "compiler/fir/raw-fir/psi2fir/testData") { - testClass { - model("rawBuilder", testMethod = "doTest") - } - } - - testGroup("analysis/low-level-api-fir/tests", "analysis/low-level-api-fir/testdata") { - testClass { - model("onAirResolve") - } - - testClass { - model("lazyResolve") - } - - testClass { - model("fileStructure") - } - - testClass { - model("fileStructure") - } - - testClass { - model("diagnosticTraversalCounter") - } - - testClass { - model("innerDeclarationsResolve") - } - - testClass { - model("partialRawBuilder", testMethod = "doRawFirTest") - } - - testClass { - model("getOrBuildFir") - } - } - - testGroup( - "analysis/low-level-api-fir/tests", - "compiler/fir/analysis-tests/testData", - ) { - testClass(suiteTestClassName = "DiagnosisCompilerFirTestdataTestGenerated") { - model("resolve", pattern = TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME) - model("resolveWithStdlib", pattern = TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME) - } - } - - testGroup( - "analysis/low-level-api-fir/tests", - "compiler/testData", - ) { - testClass(suiteTestClassName = "DiagnosisCompilerTestFE10TestdataTestGenerated") { - model( - "diagnostics/tests", - excludedPattern = excludedFirTestdataPattern, - ) - model( - "diagnostics/testsWithStdLib", - excludedPattern = excludedFirTestdataPattern, - excludeDirs = listOf("native") - ) - } - } - - - testGroup("analysis/low-level-api-fir/tests", testDataRoot = GeneralConfiguration.SPEC_TESTDATA_PATH) { - testClass(suiteTestClassName = "FirIdeSpecTest") { - model( - "diagnostics", - excludeDirs = listOf("helpers") + detectDirsWithTestsMapFileOnly("diagnostics"), - excludedPattern = excludedFirTestdataPattern, - ) - } - } - testGroup(testsRoot = "compiler/fir/analysis-tests/tests-gen", testDataRoot = GeneralConfiguration.SPEC_TESTDATA_PATH) { - testClass { - model( - "diagnostics", - excludeDirs = listOf("helpers") + detectDirsWithTestsMapFileOnly("diagnostics"), - excludedPattern = excludedFirTestdataPattern - ) - } - } + generateTests() } } + +private fun TestGroupSuite.generateTests() { + generateAnalysisApiTests() + generateFirLowLevelApiTests() +} diff --git a/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/analysisApi.kt b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/analysisApi.kt new file mode 100644 index 00000000000..01d530b08e4 --- /dev/null +++ b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/analysisApi.kt @@ -0,0 +1,181 @@ +/* + * 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.generators.tests.analysis.api + +import org.jetbrains.kotlin.analysis.api.descriptors.test.AbstractKtFe10ResolveCallTest +import org.jetbrains.kotlin.analysis.api.descriptors.test.components.* +import org.jetbrains.kotlin.analysis.api.descriptors.test.symbols.AbstractKtFe10CompileTimeConstantEvaluatorTest +import org.jetbrains.kotlin.analysis.api.descriptors.test.symbols.AbstractKtFe10SymbolByFqNameTest +import org.jetbrains.kotlin.analysis.api.descriptors.test.symbols.AbstractKtFe10SymbolByPsiTest +import org.jetbrains.kotlin.analysis.api.descriptors.test.symbols.AbstractKtFe10SymbolByReferenceTest +import org.jetbrains.kotlin.analysis.api.fir.AbstractFirReferenceResolveTest +import org.jetbrains.kotlin.analysis.api.fir.components.* +import org.jetbrains.kotlin.analysis.api.fir.scopes.AbstractFirDelegateMemberScopeTest +import org.jetbrains.kotlin.analysis.api.fir.scopes.AbstractFirFileScopeTest +import org.jetbrains.kotlin.analysis.api.fir.scopes.AbstractFirMemberScopeByFqNameTest +import org.jetbrains.kotlin.analysis.api.fir.symbols.AbstractFirSymbolByFqNameTest +import org.jetbrains.kotlin.analysis.api.fir.symbols.AbstractFirSymbolByPsiTest +import org.jetbrains.kotlin.analysis.api.fir.symbols.AbstractFirSymbolByReferenceTest +import org.jetbrains.kotlin.generators.TestGroupSuite +import org.jetbrains.kotlin.generators.util.TestGeneratorUtil + +fun TestGroupSuite.generateAnalysisApiTests() { + generateAnalysisApiComponentsTests() + generateAnalysisApiNonComponentsTests() +} + +private fun TestGroupSuite.generateAnalysisApiNonComponentsTests() { + test( + fir = AbstractFirReferenceResolveTest::class, fe10 = null, + ) { + model("referenceResolve", pattern = TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME) + } + + group("scopes") { + test( + fir = AbstractFirMemberScopeByFqNameTest::class, + fe10 = null, + ) { + model("memberScopeByFqName") + } + + test( + fir = AbstractFirFileScopeTest::class, + fe10 = null, + ) { + model("fileScopeTest", extension = "kt") + } + + test( + fir = AbstractFirDelegateMemberScopeTest::class, + fe10 = null, + ) { + model("delegatedMemberScope") + } + } + + group("symbols") { + test( + fir = AbstractFirSymbolByPsiTest::class, + fe10 = AbstractKtFe10SymbolByPsiTest::class, + ) { + model("symbolByPsi") + } + + test( + fir = AbstractFirSymbolByFqNameTest::class, + fe10 = AbstractKtFe10SymbolByFqNameTest::class, + ) { + model("symbolByFqName") + } + + test( + fir = AbstractFirSymbolByReferenceTest::class, + fe10 = AbstractKtFe10SymbolByReferenceTest::class, + ) { + model("symbolByReference") + } + } +} + + +private fun TestGroupSuite.generateAnalysisApiComponentsTests() { + component("callResolver") { + test( + fir = AbstractFirResolveCallTest::class, fe10 = AbstractKtFe10ResolveCallTest::class, + ) { + model("resolveCall") + } + } + + component("compileTimeConstantProvider") { + test( + fir = AbstractFirCompileTimeConstantEvaluatorTest::class, fe10 = AbstractKtFe10CompileTimeConstantEvaluatorTest::class, + ) { + model("evaluate") + } + } + + component("expressionInfoProvider") { + test( + fir = AbstractFirWhenMissingCasesTest::class, fe10 = AbstractKtFe10WhenMissingCasesTest::class + ) { + model("whenMissingCases") + } + + test( + fir = null /*TODO*/, fe10 = null + ) { + model("returnExpressionTargetSymbol") + } + } + + component("expressionTypeProvider") { + test( + fir = AbstractFirExpectedExpressionTypeTest::class, fe10 = AbstractKtFe10ExpectedExpressionTypeTest::class + ) { + model("expectedExpressionType") + } + + test( + fir = AbstractFirHLExpressionTypeTest::class, fe10 = AbstractKtFe10HLExpressionTypeTest::class + ) { + model("expressionType") + } + } + + component("importOptimizer") { + test( + fir = AbstractHLImportOptimizerTest::class, + fe10 = null, + ) { + model("analyseImports", pattern = TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME) + } + } + + component("psiTypeProvider") { + test(fir = AbstractPsiTypeProviderTest::class, fe10 = null) { + model("psiType/forDeclaration") + } + + test(fir = AbstractExpressionPsiTypeProviderTest::class, fe10 = null) { + model("psiType/forExpression") + } + } + + component("smartCastProvider") { + test(fir = AbstractFirHLSmartCastInfoTest::class, fe10 = AbstractKtFe10HLSmartCastInfoTest::class) { + model("smartCastInfo") + } + } + + component("symbolDeclarationOverridesProvider") { + test(fir = AbstractFirOverriddenDeclarationProviderTest::class, fe10 = AbstractKtFe10OverriddenDeclarationProviderTest::class) { + model("overriddenSymbols") + } + } + + component("symbolDeclarationRenderer") { + test(fir = AbstractFirRendererTest::class, fe10 = AbstractKtFe10RendererTest::class) { + model("renderDeclaration") + } + } + + component("typeInfoProvider") { + test(fir = AbstractFirFunctionClassKindTest::class, fe10 = null) { + model("functionClassKind") + } + test(fir = AbstractFirGetSuperTypesTest::class, fe10 = null) { + model("superTypes") + } + } + + component("typeProvider") { + test(fir = AbstractFirHasCommonSubtypeTest::class, fe10 = AbstractKtFe10HasCommonSubtypeTest::class) { + model("haveCommonSubtype") + } + } +} diff --git a/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/dsl.kt b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/dsl.kt new file mode 100644 index 00000000000..d38d9c6841e --- /dev/null +++ b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/dsl.kt @@ -0,0 +1,71 @@ +/* + * 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.generators.tests.analysis.api + +import org.jetbrains.kotlin.generators.TestGroup +import org.jetbrains.kotlin.generators.TestGroupSuite +import kotlin.reflect.KClass + +internal class FirAndFe10TestGroup( + val suite: TestGroupSuite, + val directory: String? +) + +internal fun FirAndFe10TestGroup.test( + fir: KClass<*>?, + fe10: KClass<*>?, + init: TestGroup.TestClass.() -> Unit, +) { + if (fir != null) { + analysisApiTest("analysis/analysis-api-fir/tests", fir, init) + } + + if (fe10 != null) { + analysisApiTest("analysis/analysis-api-fe10/tests", fe10, init) + } +} + +internal fun TestGroupSuite.test( + fir: KClass<*>?, + fe10: KClass<*>?, + init: TestGroup.TestClass.() -> Unit, +) { + FirAndFe10TestGroup(this, directory = null).test(fir, fe10, init) +} + + +internal fun TestGroupSuite.group( + directory: String, + init: FirAndFe10TestGroup.() -> Unit, +) { + FirAndFe10TestGroup(this, directory).init() +} + + +internal fun TestGroupSuite.component( + directory: String, + init: FirAndFe10TestGroup.() -> Unit, +) { + group("components/$directory", init) +} + +private fun FirAndFe10TestGroup.analysisApiTest( + testRoot: String, + testClass: KClass<*>, + init: TestGroup.TestClass.() -> Unit, +) { + with(suite) { + val fullTestPath = "analysis/analysis-api/testData" + directory?.let { "/$it" }.orEmpty() + testGroup(testRoot, fullTestPath) { + testClass(testClass, useJunit4 = false) { + init() + } + } + } +} + + + diff --git a/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/firLowLevel.kt b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/firLowLevel.kt new file mode 100644 index 00000000000..d9f2185ea7f --- /dev/null +++ b/generators/analysis-api-generator/tests/org/jetbrains/kotlin/generators/tests/analysis/api/firLowLevel.kt @@ -0,0 +1,110 @@ +/* + * 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.generators.tests.analysis.api + +import org.jetbrains.kotlin.analysis.low.level.api.fir.* +import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.AbstractDiagnosticTraversalCounterTest +import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.AbstractFirContextCollectionTest +import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.AbstractDiagnosisCompilerTestDataSpecTest +import org.jetbrains.kotlin.analysis.low.level.api.fir.diagnostic.compiler.based.AbstractDiagnosisCompilerTestDataTest +import org.jetbrains.kotlin.analysis.low.level.api.fir.file.structure.AbstractFileStructureTest +import org.jetbrains.kotlin.analysis.low.level.api.fir.resolve.AbstractInnerDeclarationsResolvePhaseTest +import org.jetbrains.kotlin.generators.TestGroupSuite +import org.jetbrains.kotlin.generators.util.TestGeneratorUtil +import org.jetbrains.kotlin.spec.utils.GeneralConfiguration +import org.jetbrains.kotlin.spec.utils.tasks.detectDirsWithTestsMapFileOnly +import org.jetbrains.kotlin.test.runners.AbstractFirDiagnosticTestSpec + +private const val excludedFirTestdataPattern = "^(.+)\\.fir\\.kts?\$" + +internal fun TestGroupSuite.generateFirLowLevelApiTests() { + testGroup("analysis/low-level-api-fir/tests", "compiler/fir/raw-fir/psi2fir/testData") { + testClass { + model("rawBuilder", testMethod = "doTest") + } + } + + testGroup("analysis/low-level-api-fir/tests", "analysis/low-level-api-fir/testdata") { + testClass { + model("onAirResolve") + } + + testClass { + model("lazyResolve") + } + + testClass { + model("fileStructure") + } + + testClass { + model("fileStructure") + } + + testClass { + model("diagnosticTraversalCounter") + } + + testClass { + model("innerDeclarationsResolve") + } + + testClass { + model("partialRawBuilder", testMethod = "doRawFirTest") + } + + testClass { + model("getOrBuildFir") + } + } + + testGroup( + "analysis/low-level-api-fir/tests", + "compiler/fir/analysis-tests/testData", + ) { + testClass(suiteTestClassName = "DiagnosisCompilerFirTestdataTestGenerated") { + model("resolve", pattern = TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME) + model("resolveWithStdlib", pattern = TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME) + } + } + + testGroup( + "analysis/low-level-api-fir/tests", + "compiler/testData", + ) { + testClass(suiteTestClassName = "DiagnosisCompilerTestFE10TestdataTestGenerated") { + model( + "diagnostics/tests", + excludedPattern = excludedFirTestdataPattern, + ) + model( + "diagnostics/testsWithStdLib", + excludedPattern = excludedFirTestdataPattern, + excludeDirs = listOf("native") + ) + } + } + + + testGroup("analysis/low-level-api-fir/tests", testDataRoot = GeneralConfiguration.SPEC_TESTDATA_PATH) { + testClass(suiteTestClassName = "FirIdeSpecTest") { + model( + "diagnostics", + excludeDirs = listOf("helpers") + detectDirsWithTestsMapFileOnly("diagnostics"), + excludedPattern = excludedFirTestdataPattern, + ) + } + } + testGroup(testsRoot = "compiler/fir/analysis-tests/tests-gen", testDataRoot = GeneralConfiguration.SPEC_TESTDATA_PATH) { + testClass { + model( + "diagnostics", + excludeDirs = listOf("helpers") + detectDirsWithTestsMapFileOnly("diagnostics"), + excludedPattern = excludedFirTestdataPattern + ) + } + } +} \ No newline at end of file diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/TestGenerationDSL.kt b/generators/test-generator/tests/org/jetbrains/kotlin/generators/TestGenerationDSL.kt index 52c9815e273..cc7c8d44585 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/TestGenerationDSL.kt +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/TestGenerationDSL.kt @@ -66,7 +66,7 @@ class TestGroup( fun testClass( testKClass: KClass<*>, - baseTestClassName: String, + baseTestClassName: String = testKClass.java.name, suiteTestClassName: String = getDefaultSuiteTestClassName(baseTestClassName.substringAfterLast('.')), useJunit4: Boolean, annotations: List = emptyList(),