[FIR] Add generating of rawBuilder tests for light tree

This commit is contained in:
Dmitriy Novozhilov
2019-11-21 14:54:40 +03:00
parent 43e621530f
commit 841ba6ea11
8 changed files with 337 additions and 110 deletions
+1
View File
@@ -244,6 +244,7 @@ extra["compilerModules"] = arrayOf(
":compiler:fir:resolve",
":compiler:fir:tree",
":compiler:fir:psi2fir",
":compiler:fir:lightTree",
":compiler:fir:fir2ir",
":compiler:fir:java"
)
+1
View File
@@ -48,6 +48,7 @@ dependencies {
testCompile(projectTests(":compiler:fir:psi2fir"))
testCompile(projectTests(":compiler:fir:fir2ir"))
testCompile(projectTests(":compiler:fir:resolve"))
testCompile(projectTests(":compiler:fir:lightTree"))
testCompile(projectTests(":compiler:visualizer"))
testCompile(projectTests(":generators:test-generator"))
testCompile(project(":compiler:ir.ir2cfg"))
+7 -3
View File
@@ -16,9 +16,11 @@ repositories {
dependencies {
compileOnly(intellijCoreDep()) { includeJars("intellij-core", "guava", rootProject = rootProject) }
compile(project(":compiler:psi"))
compile("junit", "junit", "4.4")
compile(projectTests(":compiler:fir:psi2fir"))
compile(project(":compiler:fir:tree"))
compile(project(":compiler:fir:psi2fir"))
testCompile("junit", "junit", "4.4")
testCompile(projectTests(":compiler:fir:psi2fir"))
compile("org.openjdk.jmh", "jmh-core", jmhVersion)
compile("org.openjdk.jmh", "jmh-generator-bytecode", jmhVersion)
@@ -40,6 +42,8 @@ projectTest {
exclude("**/benchmark/**")
}
testsJar()
val compactClasspath by tasks.registering(Jar::class) {
archiveAppendix.set("classpath")
inputs.files(sourceSets["main"].runtimeClasspath + sourceSets["test"].runtimeClasspath)
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.fir.lightTree
import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilderTestCase
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
import java.nio.file.Paths
abstract class AbstractLightTree2FirConverterTestCase : AbstractRawFirBuilderTestCase() {
override fun doTest(filePath: String) {
val firFile = LightTree2Fir(stubMode = false, project = myProject).buildFirFile(Paths.get(filePath))
val firDump = firFile.render()
val expectedFile = File(filePath.replace(".kt", ".txt"))
KotlinTestUtils.assertEqualsToFile(expectedFile, firDump)
}
}
@@ -0,0 +1,296 @@
/*
* Copyright 2010-2019 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.fir.lightTree;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/fir/psi2fir/testData/rawBuilder")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class LightTree2FirConverterTestCaseGenerated extends AbstractLightTree2FirConverterTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInRawBuilder() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("compiler/fir/psi2fir/testData/rawBuilder/declarations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Declarations extends AbstractLightTree2FirConverterTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInDeclarations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("complexTypes.kt")
public void testComplexTypes() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/complexTypes.kt");
}
@TestMetadata("derivedClass.kt")
public void testDerivedClass() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/derivedClass.kt");
}
@TestMetadata("enums.kt")
public void testEnums() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/enums.kt");
}
@TestMetadata("enums2.kt")
public void testEnums2() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/enums2.kt");
}
@TestMetadata("expectActual.kt")
public void testExpectActual() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt");
}
@TestMetadata("F.kt")
public void testF() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/F.kt");
}
@TestMetadata("functionTypes.kt")
public void testFunctionTypes() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/functionTypes.kt");
}
@TestMetadata("genericFunctions.kt")
public void testGenericFunctions() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/genericFunctions.kt");
}
@TestMetadata("genericProperty.kt")
public void testGenericProperty() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/genericProperty.kt");
}
@TestMetadata("nestedClass.kt")
public void testNestedClass() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/nestedClass.kt");
}
@TestMetadata("NestedOfAliasedType.kt")
public void testNestedOfAliasedType() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/NestedOfAliasedType.kt");
}
@TestMetadata("NestedSuperType.kt")
public void testNestedSuperType() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/NestedSuperType.kt");
}
@TestMetadata("noPrimaryConstructor.kt")
public void testNoPrimaryConstructor() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.kt");
}
@TestMetadata("simpleClass.kt")
public void testSimpleClass() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt");
}
@TestMetadata("simpleFun.kt")
public void testSimpleFun() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleFun.kt");
}
@TestMetadata("simpleTypeAlias.kt")
public void testSimpleTypeAlias() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleTypeAlias.kt");
}
@TestMetadata("typeAliasWithGeneric.kt")
public void testTypeAliasWithGeneric() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeAliasWithGeneric.kt");
}
@TestMetadata("typeParameterVsNested.kt")
public void testTypeParameterVsNested() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameterVsNested.kt");
}
@TestMetadata("typeParameters.kt")
public void testTypeParameters() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameters.kt");
}
@TestMetadata("where.kt")
public void testWhere() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/where.kt");
}
}
@TestMetadata("compiler/fir/psi2fir/testData/rawBuilder/expressions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Expressions extends AbstractLightTree2FirConverterTestCase {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInExpressions() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("annotated.kt")
public void testAnnotated() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/annotated.kt");
}
@TestMetadata("arrayAccess.kt")
public void testArrayAccess() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAccess.kt");
}
@TestMetadata("arrayAssignment.kt")
public void testArrayAssignment() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAssignment.kt");
}
@TestMetadata("branches.kt")
public void testBranches() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/branches.kt");
}
@TestMetadata("callableReferences.kt")
public void testCallableReferences() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/callableReferences.kt");
}
@TestMetadata("calls.kt")
public void testCalls() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.kt");
}
@TestMetadata("classReference.kt")
public void testClassReference() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/classReference.kt");
}
@TestMetadata("collectionLiterals.kt")
public void testCollectionLiterals() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.kt");
}
@TestMetadata("destructuring.kt")
public void testDestructuring() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/destructuring.kt");
}
@TestMetadata("for.kt")
public void testFor() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/for.kt");
}
@TestMetadata("genericCalls.kt")
public void testGenericCalls() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/genericCalls.kt");
}
@TestMetadata("in.kt")
public void testIn() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/in.kt");
}
@TestMetadata("init.kt")
public void testInit() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt");
}
@TestMetadata("lambda.kt")
public void testLambda() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/lambda.kt");
}
@TestMetadata("lambdaAndAnonymousFunction.kt")
public void testLambdaAndAnonymousFunction() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/lambdaAndAnonymousFunction.kt");
}
@TestMetadata("locals.kt")
public void testLocals() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/locals.kt");
}
@TestMetadata("modifications.kt")
public void testModifications() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/modifications.kt");
}
@TestMetadata("namedArgument.kt")
public void testNamedArgument() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/namedArgument.kt");
}
@TestMetadata("nullability.kt")
public void testNullability() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/nullability.kt");
}
@TestMetadata("qualifierWithTypeArguments.kt")
public void testQualifierWithTypeArguments() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/qualifierWithTypeArguments.kt");
}
@TestMetadata("simpleReturns.kt")
public void testSimpleReturns() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/simpleReturns.kt");
}
@TestMetadata("super.kt")
public void testSuper() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/super.kt");
}
@TestMetadata("these.kt")
public void testThese() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/these.kt");
}
@TestMetadata("try.kt")
public void testTry() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/try.kt");
}
@TestMetadata("typeOperators.kt")
public void testTypeOperators() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/typeOperators.kt");
}
@TestMetadata("unary.kt")
public void testUnary() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/unary.kt");
}
@TestMetadata("variables.kt")
public void testVariables() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/variables.kt");
}
@TestMetadata("while.kt")
public void testWhile() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/while.kt");
}
}
}
@@ -1,107 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.fir.lightTree
import com.intellij.testFramework.TestDataPath
import junit.framework.TestCase
import org.jetbrains.kotlin.fir.FirRenderer
import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilderTestCase
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners
import org.junit.runner.RunWith
import java.nio.file.Paths
@TestDataPath("\$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners::class)
class LightTree2FirConverterTestCases : AbstractRawFirBuilderTestCase() {
private val testDirPath = "compiler/fir/psi2fir/testData/rawBuilder/declarations"
private fun executeTest(filePath: String) {
val lightTree2Fir = LightTree2Fir(stubMode = true, project = myProject).buildFirFile(Paths.get(filePath)).render()
val file = createKtFile(filePath)
val firFile = file.toFirFile(stubMode = true)
val firFileDump = StringBuilder().also { FirRenderer(it).visitFile(firFile) }.toString()
TestCase.assertEquals(firFileDump, lightTree2Fir)
}
fun testComplexTypes() {
executeTest("$testDirPath/complexTypes.kt")
}
fun testDerivedClass() {
executeTest("$testDirPath/derivedClass.kt")
}
fun testEnums() {
executeTest("$testDirPath/enums.kt")
}
fun testEnums2() {
executeTest("$testDirPath/enums2.kt")
}
fun testExpectActual() {
executeTest("$testDirPath/expectActual.kt")
}
fun testF() {
executeTest("$testDirPath/F.kt")
}
fun testFunctionTypes() {
executeTest("$testDirPath/functionTypes.kt")
}
fun testGenericFunctions() {
executeTest("$testDirPath/genericFunctions.kt")
}
fun testNestedClass() {
executeTest("$testDirPath/nestedClass.kt")
}
fun testNestedOfAliasedType() {
executeTest("$testDirPath/NestedOfAliasedType.kt")
}
fun testNestedSuperType() {
executeTest("$testDirPath/NestedSuperType.kt")
}
fun testNoPrimaryConstructor() {
executeTest("$testDirPath/noPrimaryConstructor.kt")
}
fun testSimpleClass() {
executeTest("$testDirPath/simpleClass.kt")
}
fun testSimpleFun() {
executeTest("$testDirPath/simpleFun.kt")
}
fun testSimpleTypeAlias() {
executeTest("$testDirPath/simpleTypeAlias.kt")
}
fun testTypeAliasWithGeneric() {
executeTest("$testDirPath/typeAliasWithGeneric.kt")
}
fun testTypeParameterVsNested() {
executeTest("$testDirPath/typeParameterVsNested.kt")
}
fun testTypeParameters() {
executeTest("$testDirPath/typeParameters.kt")
}
fun testWhere() {
executeTest("$testDirPath/where.kt")
}
}
+1
View File
@@ -13,6 +13,7 @@ dependencies {
testCompile(project(":compiler:backend"))
testCompile(project(":compiler:fir:tree"))
testCompile(project(":compiler:fir:psi2fir"))
testCompile(project(":compiler:fir:lightTree"))
testCompile(project(":compiler:fir:fir2ir"))
testCompile(project(":compiler:fir:cones"))
testCompile(project(":compiler:fir:resolve"))
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.codegen.flags.AbstractWriteFlagsTest
import org.jetbrains.kotlin.codegen.ir.*
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.builder.AbstractRawFirBuilderTestCase
import org.jetbrains.kotlin.fir.lightTree.AbstractLightTree2FirConverterTestCase
import org.jetbrains.kotlin.fir.java.AbstractFirLightClassesTest
import org.jetbrains.kotlin.fir.java.AbstractFirTypeEnhancementTest
import org.jetbrains.kotlin.fir.java.AbstractOwnFirTypeEnhancementTest
@@ -513,6 +514,12 @@ fun main(args: Array<String>) {
}
}
testGroup("compiler/fir/lightTree/tests", "compiler/fir/psi2fir/testData") {
testClass<AbstractLightTree2FirConverterTestCase> {
model("rawBuilder")
}
}
testGroup("compiler/fir/resolve/tests", "compiler/fir/resolve/testData") {
testClass<AbstractFirDiagnosticsTest> {
model("resolve", pattern = KT_WITHOUT_DOTS_IN_NAME, excludeDirs = listOf("stdlib", "cfg", "smartcasts"))