[LL FIR] add lazy body calculation tests for scripts

After KT-65344 we can effectively calculate lazy bodies in scripts,
so we can safely add the test

^KT-62840
This commit is contained in:
Dmitrii Gridin
2024-02-09 17:27:24 +01:00
committed by Space Team
parent f77c08a821
commit 898c8c002e
6 changed files with 144 additions and 31 deletions
@@ -12,6 +12,7 @@ import kotlinx.collections.immutable.toPersistentList
import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignation
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.withFirDesignationEntry
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.forEachDeclaration
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.builder.PsiRawFirBuilder
import org.jetbrains.kotlin.fir.contracts.FirRawContractDescription
@@ -762,20 +763,13 @@ private abstract class FirLazyAnnotationTransformer : FirTransformer<FirLazyAnno
}
private object FirAllLazyBodiesCalculatorTransformer : FirLazyBodiesCalculatorTransformer() {
override fun transformFile(file: FirFile, data: PersistentList<FirDeclaration>): FirFile {
file.declarations.forEach {
it.transformSingle(this, data)
}
return file
}
override fun <E : FirElement> transformElement(element: E, data: PersistentList<FirDeclaration>): E {
if (element is FirRegularClass) {
val newList = data.add(element)
element.declarations.forEach {
if (element is FirFile || element is FirScript || element is FirRegularClass) {
val newList = data.add(element as FirDeclaration)
element.forEachDeclaration {
it.transformSingle(this, newList)
}
element.transformChildren(this, newList)
}
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir
import junit.framework.TestCase
import org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve.FirLazyBodiesCalculator
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirOutOfContentRootTestConfigurator
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirScriptTestConfigurator
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.configurators.AnalysisApiFirSourceTestConfigurator
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedTest
import org.jetbrains.kotlin.fir.FirElement
@@ -44,6 +45,7 @@ abstract class AbstractFirLazyBodiesCalculatorTest : AbstractAnalysisApiBasedTes
FirLazyBodiesCalculator.calculateAllLazyExpressionsInFile(laziedFirFile)
laziedFirFile.accept(lazyChecker)
val laziedFirFileDump = FirRenderer().renderElementAsString(laziedFirFile)
val fullFirFile = PsiRawFirBuilder(
session,
@@ -51,10 +53,9 @@ abstract class AbstractFirLazyBodiesCalculatorTest : AbstractAnalysisApiBasedTes
bodyBuildingMode = BodyBuildingMode.NORMAL
).buildFirFile(mainFile)
val laziedFirFileDump = FirRenderer().renderElementAsString(laziedFirFile)
val fullFirFileDump = FirRenderer().renderElementAsString(fullFirFile)
TestCase.assertEquals(laziedFirFileDump, fullFirFileDump)
TestCase.assertEquals(/* expected = */ fullFirFileDump, /* actual = */ laziedFirFileDump)
}
}
}
@@ -65,4 +66,8 @@ abstract class AbstractFirSourceLazyBodiesCalculatorTest : AbstractFirLazyBodies
abstract class AbstractFirOutOfContentRootLazyBodiesCalculatorTest : AbstractFirLazyBodiesCalculatorTest() {
override val configurator = AnalysisApiFirOutOfContentRootTestConfigurator
}
}
abstract class AbstractFirScriptLazyBodiesCalculatorTest : AbstractFirLazyBodiesCalculatorTest() {
override val configurator = AnalysisApiFirScriptTestConfigurator(analyseInDependentSession = false)
}
@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
public class FirOutOfContentRootLazyBodiesCalculatorTestGenerated extends AbstractFirOutOfContentRootLazyBodiesCalculatorTest {
@Test
public void testAllFilesPresentInRawBuilder() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Nested
@@ -30,7 +30,7 @@ public class FirOutOfContentRootLazyBodiesCalculatorTestGenerated extends Abstra
public class Declarations {
@Test
public void testAllFilesPresentInDeclarations() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -465,7 +465,7 @@ public class FirOutOfContentRootLazyBodiesCalculatorTestGenerated extends Abstra
public class Contracts {
@Test
public void testAllFilesPresentInContracts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Nested
@@ -474,7 +474,7 @@ public class FirOutOfContentRootLazyBodiesCalculatorTestGenerated extends Abstra
public class NewSyntax {
@Test
public void testAllFilesPresentInNewSyntax() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -502,7 +502,7 @@ public class FirOutOfContentRootLazyBodiesCalculatorTestGenerated extends Abstra
public class OldSyntax {
@Test
public void testAllFilesPresentInOldSyntax() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -519,7 +519,7 @@ public class FirOutOfContentRootLazyBodiesCalculatorTestGenerated extends Abstra
public class NoParameterType {
@Test
public void testAllFilesPresentInNoParameterType() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -602,7 +602,7 @@ public class FirOutOfContentRootLazyBodiesCalculatorTestGenerated extends Abstra
public class Expressions {
@Test
public void testAllFilesPresentInExpressions() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -0,0 +1,110 @@
/*
* Copyright 2010-2024 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.analysis.low.level.api.fir;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder")
@TestDataPath("$PROJECT_ROOT")
public class FirScriptLazyBodiesCalculatorTestGenerated extends AbstractFirScriptLazyBodiesCalculatorTest {
@Test
public void testAllFilesPresentInRawBuilder() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.(kts)$"), null, true);
}
@Nested
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations")
@TestDataPath("$PROJECT_ROOT")
public class Declarations {
@Test
public void testAllFilesPresentInDeclarations() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.(kts)$"), null, true);
}
@Test
@TestMetadata("script.kts")
public void testScript() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.kts");
}
@Test
@TestMetadata("scriptLevelDestructuringWithAnnotation.kts")
public void testScriptLevelDestructuringWithAnnotation() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/scriptLevelDestructuringWithAnnotation.kts");
}
@Test
@TestMetadata("scriptStatementLevelDestructuringWithAnnotation.kts")
public void testScriptStatementLevelDestructuringWithAnnotation() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/scriptStatementLevelDestructuringWithAnnotation.kts");
}
@Test
@TestMetadata("scriptStatementLevelDestructuringWithAnnotationAsLastStatement.kts")
public void testScriptStatementLevelDestructuringWithAnnotationAsLastStatement() throws Exception {
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/scriptStatementLevelDestructuringWithAnnotationAsLastStatement.kts");
}
@Nested
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts")
@TestDataPath("$PROJECT_ROOT")
public class Contracts {
@Test
public void testAllFilesPresentInContracts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.(kts)$"), null, true);
}
@Nested
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax")
@TestDataPath("$PROJECT_ROOT")
public class NewSyntax {
@Test
public void testAllFilesPresentInNewSyntax() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.(kts)$"), null, true);
}
}
@Nested
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax")
@TestDataPath("$PROJECT_ROOT")
public class OldSyntax {
@Test
public void testAllFilesPresentInOldSyntax() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.(kts)$"), null, true);
}
}
}
@Nested
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType")
@TestDataPath("$PROJECT_ROOT")
public class NoParameterType {
@Test
public void testAllFilesPresentInNoParameterType() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType"), Pattern.compile("^(.+)\\.(kts)$"), null, true);
}
}
}
@Nested
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions")
@TestDataPath("$PROJECT_ROOT")
public class Expressions {
@Test
public void testAllFilesPresentInExpressions() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.(kts)$"), null, true);
}
}
}
@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
public class FirSourceLazyBodiesCalculatorTestGenerated extends AbstractFirSourceLazyBodiesCalculatorTest {
@Test
public void testAllFilesPresentInRawBuilder() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Nested
@@ -30,7 +30,7 @@ public class FirSourceLazyBodiesCalculatorTestGenerated extends AbstractFirSourc
public class Declarations {
@Test
public void testAllFilesPresentInDeclarations() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -465,7 +465,7 @@ public class FirSourceLazyBodiesCalculatorTestGenerated extends AbstractFirSourc
public class Contracts {
@Test
public void testAllFilesPresentInContracts() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Nested
@@ -474,7 +474,7 @@ public class FirSourceLazyBodiesCalculatorTestGenerated extends AbstractFirSourc
public class NewSyntax {
@Test
public void testAllFilesPresentInNewSyntax() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -502,7 +502,7 @@ public class FirSourceLazyBodiesCalculatorTestGenerated extends AbstractFirSourc
public class OldSyntax {
@Test
public void testAllFilesPresentInOldSyntax() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/oldSyntax"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -519,7 +519,7 @@ public class FirSourceLazyBodiesCalculatorTestGenerated extends AbstractFirSourc
public class NoParameterType {
@Test
public void testAllFilesPresentInNoParameterType() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noParameterType"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -602,7 +602,7 @@ public class FirSourceLazyBodiesCalculatorTestGenerated extends AbstractFirSourc
public class Expressions {
@Test
public void testAllFilesPresentInExpressions() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.kt$"), null, true);
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.(kt)$"), null, true);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 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.
*/
@@ -36,11 +36,15 @@ import org.jetbrains.kotlin.test.utils.CUSTOM_TEST_DATA_EXTENSION_PATTERN
internal fun TestGroupSuite.generateFirLowLevelApiTests() {
testGroup("analysis/low-level-api-fir/tests", "compiler/fir/raw-fir/psi2fir/testData") {
testClass<AbstractFirSourceLazyBodiesCalculatorTest> {
model("rawBuilder", testMethod = "doTest")
model("rawBuilder", pattern = TestGeneratorUtil.KT)
}
testClass<AbstractFirOutOfContentRootLazyBodiesCalculatorTest> {
model("rawBuilder", testMethod = "doTest")
model("rawBuilder", pattern = TestGeneratorUtil.KT)
}
testClass<AbstractFirScriptLazyBodiesCalculatorTest> {
model("rawBuilder", pattern = TestGeneratorUtil.KTS)
}
}