[FIR] add RawFirBuilder test for script
^KT-60728 ^KT-60519
This commit is contained in:
committed by
Space Team
parent
2c932c9e1d
commit
a2dc6ca8f2
+3
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar
|
||||
import org.jetbrains.kotlin.fir.extensions.FirExtensionService
|
||||
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment
|
||||
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectFileSearchScope
|
||||
@@ -115,6 +116,8 @@ object FirSessionFactoryHelper {
|
||||
get() = stub()
|
||||
}
|
||||
))
|
||||
|
||||
register(FirExtensionService::class, FirExtensionService(this))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
class Builder {
|
||||
var version: String = ""
|
||||
|
||||
fun execute() {
|
||||
println(version)
|
||||
}
|
||||
|
||||
class Nested {
|
||||
fun foo() {}
|
||||
fun boo() {}
|
||||
}
|
||||
}
|
||||
|
||||
fun build(action: Builder.() -> Unit) = Builder().apply(action)
|
||||
fun build2(action: Builder.() -> Unit): Builder = Builder().apply(action)
|
||||
|
||||
build {
|
||||
version = "123"
|
||||
class A {
|
||||
fun doo() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
execute()
|
||||
}
|
||||
|
||||
version += 123
|
||||
|
||||
val builder = build {
|
||||
version = "321"
|
||||
}
|
||||
|
||||
println()
|
||||
builder.version = ""
|
||||
builder.execute()
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
FILE: script.kts
|
||||
SCRIPT:
|
||||
|
||||
public? final? class Builder : R|kotlin/Any| {
|
||||
public? constructor(): R|Builder| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? var version: String = LAZY_EXPRESSION
|
||||
public? get(): String
|
||||
public? set(value: String): R|kotlin/Unit|
|
||||
|
||||
public? final? fun execute(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
public? final? class Nested : R|kotlin/Any| {
|
||||
public? constructor(): R|Builder.Nested| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
public? final? fun foo(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
public? final? fun boo(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public? final? fun build(action: ( Builder.() -> Unit )): <implicit> { LAZY_BLOCK }
|
||||
|
||||
public? final? fun build2(action: ( Builder.() -> Unit )): Builder { LAZY_BLOCK }
|
||||
|
||||
build#(<L> = LAZY_EXPRESSION)
|
||||
+=(version#, IntegerLiteral(123))
|
||||
public? final? val builder: <implicit> = LAZY_EXPRESSION
|
||||
public? get(): <implicit>
|
||||
|
||||
println#()
|
||||
builder#.version# = String()
|
||||
builder#.execute#()
|
||||
@@ -0,0 +1,64 @@
|
||||
FILE: script.kts
|
||||
SCRIPT:
|
||||
|
||||
public? final? class Builder : R|kotlin/Any| {
|
||||
public? [ContainingClassKey=Builder] constructor(): R|Builder| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public? final? var version: String = String()
|
||||
public? [ContainingClassKey=Builder] get(): String
|
||||
public? [ContainingClassKey=Builder] set(value: String): R|kotlin/Unit|
|
||||
|
||||
public? final? fun execute(): R|kotlin/Unit| {
|
||||
println#(version#)
|
||||
}
|
||||
|
||||
public? final? class Nested : R|kotlin/Any| {
|
||||
public? [ContainingClassKey=Nested] constructor(): R|Builder.Nested| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public? final? fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
public? final? fun boo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public? final? fun build(action: ( Builder.() -> Unit )): <implicit> {
|
||||
^build Builder#().apply#(action#)
|
||||
}
|
||||
|
||||
public? final? fun build2(action: ( Builder.() -> Unit )): Builder {
|
||||
^build2 Builder#().apply#(action#)
|
||||
}
|
||||
|
||||
build#(<L> = build@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
|
||||
version# = String(123)
|
||||
local final? class A : R|kotlin/Any| {
|
||||
public? [ContainingClassKey=A] constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public? final? fun doo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
execute#()
|
||||
}
|
||||
)
|
||||
+=(version#, IntegerLiteral(123))
|
||||
public? final? val builder: <implicit> = build#(<L> = build@fun <implicit>.<anonymous>(): <implicit> <inline=Unknown> {
|
||||
version# = String(321)
|
||||
}
|
||||
)
|
||||
public? get(): <implicit>
|
||||
|
||||
println#()
|
||||
builder#.version# = String()
|
||||
builder#.execute#()
|
||||
+12
-7
@@ -26,7 +26,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations")
|
||||
@@ -38,7 +38,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("annotation.kt")
|
||||
@@ -201,6 +201,11 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingFieldDifferentTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("script.kts")
|
||||
public void testScript() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.kts");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt");
|
||||
@@ -255,7 +260,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax")
|
||||
@@ -267,7 +272,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("functionWithBothOldAndNewSyntaxContractDescription.kt")
|
||||
@@ -295,7 +300,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("contractDescription.kt")
|
||||
@@ -314,7 +319,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("noParameterTypRefInCatch.kt")
|
||||
@@ -368,7 +373,7 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("annotated.kt")
|
||||
|
||||
+12
-7
@@ -26,7 +26,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations")
|
||||
@@ -38,7 +38,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("annotation.kt")
|
||||
@@ -201,6 +201,11 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingFieldDifferentTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("script.kts")
|
||||
public void testScript() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/script.kts");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt");
|
||||
@@ -255,7 +260,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/contracts/newSyntax")
|
||||
@@ -267,7 +272,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("functionWithBothOldAndNewSyntaxContractDescription.kt")
|
||||
@@ -295,7 +300,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("contractDescription.kt")
|
||||
@@ -314,7 +319,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("noParameterTypRefInCatch.kt")
|
||||
@@ -368,7 +373,7 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
}
|
||||
|
||||
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|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("annotated.kt")
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ abstract class AbstractRawFirBuilderLazyBodiesTestCase : AbstractRawFirBuilderTe
|
||||
val file = createKtFile(filePath)
|
||||
val firFile = file.toFirFile(BodyBuildingMode.LAZY_BODIES)
|
||||
val firFileDump = FirRenderer().renderElementAsString(firFile)
|
||||
val expectedPath = filePath.replace(".kt", ".lazyBodies.txt")
|
||||
val expectedPath = filePath.replace(".${myFileExt}", ".lazyBodies.txt")
|
||||
KotlinTestUtils.assertEqualsToFile(File(expectedPath), firFileDump)
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -66,7 +66,7 @@ abstract class AbstractRawFirBuilderTestCase : KtParsingTestCase(
|
||||
val file = createKtFile(filePath)
|
||||
val firFile = file.toFirFile(BodyBuildingMode.NORMAL)
|
||||
val firFileDump = FirRenderer.withDeclarationAttributes().renderElementAsString(firFile)
|
||||
val expectedPath = filePath.replace(".kt", ".txt")
|
||||
val expectedPath = filePath.replace(".${myFileExt}", ".txt")
|
||||
KotlinTestUtils.assertEqualsToFile(File(expectedPath), firFileDump)
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.java.AbstractFirTypeEnhancementTest
|
||||
import org.jetbrains.kotlin.fir.java.AbstractOwnFirTypeEnhancementTest
|
||||
import org.jetbrains.kotlin.fir.lightTree.AbstractLightTree2FirConverterTestCase
|
||||
import org.jetbrains.kotlin.generators.impl.generateTestGroupSuite
|
||||
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil
|
||||
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_OR_KTS_WITHOUT_DOTS_IN_NAME
|
||||
import org.jetbrains.kotlin.generators.util.TestGeneratorUtil.KT_WITHOUT_DOTS_IN_NAME
|
||||
import org.jetbrains.kotlin.integration.AbstractAntTaskTest
|
||||
@@ -403,11 +404,11 @@ fun generateJUnit3CompilerTests(args: Array<String>) {
|
||||
|
||||
testGroup("compiler/fir/raw-fir/psi2fir/tests-gen", "compiler/fir/raw-fir/psi2fir/testData") {
|
||||
testClass<AbstractRawFirBuilderTestCase> {
|
||||
model("rawBuilder", testMethod = "doRawFirTest")
|
||||
model("rawBuilder", testMethod = "doRawFirTest", pattern = TestGeneratorUtil.KT_OR_KTS)
|
||||
}
|
||||
|
||||
testClass<AbstractRawFirBuilderLazyBodiesTestCase> {
|
||||
model("rawBuilder", testMethod = "doRawFirTest")
|
||||
model("rawBuilder", testMethod = "doRawFirTest", pattern = TestGeneratorUtil.KT_OR_KTS)
|
||||
}
|
||||
|
||||
testClass<AbstractRawFirBuilderSourceElementMappingTestCase> {
|
||||
|
||||
Reference in New Issue
Block a user