diff --git a/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.log.fir.txt b/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.log.fir.txt deleted file mode 100644 index 943ca2fb42d..00000000000 --- a/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.log.fir.txt +++ /dev/null @@ -1,3 +0,0 @@ -UFile (package = declaration) - UImportStatement (isOnDemand = true) - UImportStatement (isOnDemand = true) diff --git a/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.log.fe10.txt b/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.log.txt similarity index 63% rename from plugins/uast-kotlin-fir/testData/declaration/importOnDemand.log.fe10.txt rename to plugins/uast-kotlin-fir/testData/declaration/importOnDemand.log.txt index 943ca2fb42d..893b675a39f 100644 --- a/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.log.fe10.txt +++ b/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.log.txt @@ -1,3 +1,3 @@ UFile (package = declaration) UImportStatement (isOnDemand = true) - UImportStatement (isOnDemand = true) + UImportStatement (isOnDemand = true) \ No newline at end of file diff --git a/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.render.fir.txt b/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.render.fir.txt deleted file mode 100644 index 657a89721a8..00000000000 --- a/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.render.fir.txt +++ /dev/null @@ -1,4 +0,0 @@ -package declaration - -import java.lang.Thread -import java.util diff --git a/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.render.fe10.txt b/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.render.txt similarity index 72% rename from plugins/uast-kotlin-fir/testData/declaration/importOnDemand.render.fe10.txt rename to plugins/uast-kotlin-fir/testData/declaration/importOnDemand.render.txt index 657a89721a8..794d25c1110 100644 --- a/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.render.fe10.txt +++ b/plugins/uast-kotlin-fir/testData/declaration/importOnDemand.render.txt @@ -1,4 +1,4 @@ package declaration import java.lang.Thread -import java.util +import java.util \ No newline at end of file diff --git a/plugins/uast-kotlin-fir/testData/legacy/AnnotationComplex.render.fir.txt b/plugins/uast-kotlin-fir/testData/legacy/AnnotationComplex.render.fir.txt deleted file mode 100644 index 87b57fda535..00000000000 --- a/plugins/uast-kotlin-fir/testData/legacy/AnnotationComplex.render.fir.txt +++ /dev/null @@ -1,31 +0,0 @@ -public abstract annotation Annotation { - public abstract fun strings() : java.lang.String[] = UastEmptyExpression -} - -public final class A { - public fun A() = UastEmptyExpression -} - -public abstract annotation AnnotationInner { - public abstract fun value() : Annotation = UastEmptyExpression -} - -public final class B1 { - public fun B1() = UastEmptyExpression -} - -public final class B2 { - public fun B2() = UastEmptyExpression -} - -public abstract annotation AnnotationArray { - public abstract fun value() : Annotation[] = UastEmptyExpression -} - -public final class C { - public fun C() = UastEmptyExpression -} - -public final class C2 { - public fun C2() = UastEmptyExpression -} diff --git a/plugins/uast-kotlin-fir/testData/legacy/AnnotationComplex.render.fe10.txt b/plugins/uast-kotlin-fir/testData/legacy/AnnotationComplex.render.txt similarity index 99% rename from plugins/uast-kotlin-fir/testData/legacy/AnnotationComplex.render.fe10.txt rename to plugins/uast-kotlin-fir/testData/legacy/AnnotationComplex.render.txt index 87b57fda535..f1059e95011 100644 --- a/plugins/uast-kotlin-fir/testData/legacy/AnnotationComplex.render.fe10.txt +++ b/plugins/uast-kotlin-fir/testData/legacy/AnnotationComplex.render.txt @@ -28,4 +28,4 @@ public final class C { public final class C2 { public fun C2() = UastEmptyExpression -} +} \ No newline at end of file diff --git a/plugins/uast-kotlin-fir/testData/legacy/Imports.log.fir.txt b/plugins/uast-kotlin-fir/testData/legacy/Imports.log.fir.txt deleted file mode 100644 index b560126f9d2..00000000000 --- a/plugins/uast-kotlin-fir/testData/legacy/Imports.log.fir.txt +++ /dev/null @@ -1,7 +0,0 @@ -UFile (package = ) - UImportStatement (isOnDemand = false) - UImportStatement (isOnDemand = false) - UImportStatement (isOnDemand = false) - UImportStatement (isOnDemand = false) - UImportStatement (isOnDemand = false) - UImportStatement (isOnDemand = false) diff --git a/plugins/uast-kotlin-fir/testData/legacy/Imports.log.fe10.txt b/plugins/uast-kotlin-fir/testData/legacy/Imports.log.txt similarity index 84% rename from plugins/uast-kotlin-fir/testData/legacy/Imports.log.fe10.txt rename to plugins/uast-kotlin-fir/testData/legacy/Imports.log.txt index b560126f9d2..9a205978aab 100644 --- a/plugins/uast-kotlin-fir/testData/legacy/Imports.log.fe10.txt +++ b/plugins/uast-kotlin-fir/testData/legacy/Imports.log.txt @@ -4,4 +4,4 @@ UFile (package = ) UImportStatement (isOnDemand = false) UImportStatement (isOnDemand = false) UImportStatement (isOnDemand = false) - UImportStatement (isOnDemand = false) + UImportStatement (isOnDemand = false) \ No newline at end of file diff --git a/plugins/uast-kotlin-fir/testData/legacy/Imports.render.fir.txt b/plugins/uast-kotlin-fir/testData/legacy/Imports.render.fir.txt deleted file mode 100644 index 2a3a8414ad6..00000000000 --- a/plugins/uast-kotlin-fir/testData/legacy/Imports.render.fir.txt +++ /dev/null @@ -1,6 +0,0 @@ -import java.lang.Thread.currentThread -import java.lang.Thread.NORM_PRIORITY -import java.lang.Thread.UncaughtExceptionHandler -import java.lang.Thread.sleep -import kotlin.collections.emptyList -import kotlin.Int.Companion.SIZE_BYTES diff --git a/plugins/uast-kotlin-fir/testData/legacy/Imports.render.fe10.txt b/plugins/uast-kotlin-fir/testData/legacy/Imports.render.txt similarity index 83% rename from plugins/uast-kotlin-fir/testData/legacy/Imports.render.fe10.txt rename to plugins/uast-kotlin-fir/testData/legacy/Imports.render.txt index 2a3a8414ad6..d1220f72d3c 100644 --- a/plugins/uast-kotlin-fir/testData/legacy/Imports.render.fe10.txt +++ b/plugins/uast-kotlin-fir/testData/legacy/Imports.render.txt @@ -3,4 +3,4 @@ import java.lang.Thread.NORM_PRIORITY import java.lang.Thread.UncaughtExceptionHandler import java.lang.Thread.sleep import kotlin.collections.emptyList -import kotlin.Int.Companion.SIZE_BYTES +import kotlin.Int.Companion.SIZE_BYTES \ No newline at end of file diff --git a/plugins/uast-kotlin-fir/testData/legacy/TypeAliases.log.txt b/plugins/uast-kotlin-fir/testData/legacy/TypeAliases.log.txt new file mode 100644 index 00000000000..c3e4e9f7045 --- /dev/null +++ b/plugins/uast-kotlin-fir/testData/legacy/TypeAliases.log.txt @@ -0,0 +1,4 @@ +UFile (package = ) + UClass (name = TypeAliasesKt) + UClass (name = A) + UMethod (name = A) \ No newline at end of file diff --git a/plugins/uast-kotlin-fir/testData/legacy/TypeAliases.render.txt b/plugins/uast-kotlin-fir/testData/legacy/TypeAliases.render.txt new file mode 100644 index 00000000000..2903bb5edcd --- /dev/null +++ b/plugins/uast-kotlin-fir/testData/legacy/TypeAliases.render.txt @@ -0,0 +1,6 @@ +public final class TypeAliasesKt { +} + +public final class A { + public fun A() = UastEmptyExpression +} \ No newline at end of file diff --git a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/common/kotlin/FirUastPluginSelection.kt b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/common/kotlin/FirUastPluginSelection.kt index 7a421f6211e..4ee4c76274c 100644 --- a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/common/kotlin/FirUastPluginSelection.kt +++ b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/common/kotlin/FirUastPluginSelection.kt @@ -5,10 +5,16 @@ package org.jetbrains.uast.common.kotlin +private const val FE10_SUFFIX = ".fe10" +private const val FIR_SUFFIX = ".fir" + interface FirUastPluginSelection { // Whether this is FIR UAST plugin or FE 1.0 UAST plugin val isFirUastPlugin: Boolean val pluginSuffix: String - get() = if (isFirUastPlugin) ".fir" else ".fe10" + get() = if (isFirUastPlugin) FIR_SUFFIX else FE10_SUFFIX + + val counterpartSuffix: String + get() = if (isFirUastPlugin) FE10_SUFFIX else FIR_SUFFIX } diff --git a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/common/kotlin/FirUastRenderLogTestBase.kt b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/common/kotlin/FirUastRenderLogTestBase.kt index 9d88f5776d1..8da6ffd0875 100644 --- a/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/common/kotlin/FirUastRenderLogTestBase.kt +++ b/plugins/uast-kotlin-fir/tests/org/jetbrains/uast/common/kotlin/FirUastRenderLogTestBase.kt @@ -5,7 +5,10 @@ package org.jetbrains.uast.common.kotlin +import com.intellij.openapi.util.io.FileUtil import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.KtAssert +import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase import org.jetbrains.uast.UFile import org.jetbrains.uast.asRecursiveLogString import java.io.File @@ -15,14 +18,77 @@ interface FirUastRenderLogTestBase : FirUastPluginSelection { return File(filePath.removeSuffix(".kt") + '.' + ext) } - private fun getRenderFile(filePath: String) = getTestMetadataFileFromPath(filePath, "render$pluginSuffix.txt") - private fun getLogFile(filePath: String) = getTestMetadataFileFromPath(filePath, "log$pluginSuffix.txt") + private fun getRenderFile(filePath: String, suffix: String): File = getTestMetadataFileFromPath(filePath, "render$suffix") + private fun getLogFile(filePath: String, suffix: String): File = getTestMetadataFileFromPath(filePath, "log$suffix") + + private fun getIdenticalRenderFile(filePath: String): File = getRenderFile(filePath, ".txt") + private fun getIdenticalLogFile(filePath: String): File = getLogFile(filePath, ".txt") + + private fun getPluginRenderFile(filePath: String): File { + val identicalFile = getIdenticalRenderFile(filePath) + if (identicalFile.exists()) return identicalFile + return getRenderFile(filePath, "$pluginSuffix.txt") + } + + private fun getPluginLogFile(filePath: String): File { + val identicalFile = getIdenticalLogFile(filePath) + if (identicalFile.exists()) return identicalFile + return getLogFile(filePath, "$pluginSuffix.txt") + } fun check(filePath: String, file: UFile) { - val renderFile = getRenderFile(filePath) - val logFile = getLogFile(filePath) + val renderFile = getPluginRenderFile(filePath) + val logFile = getPluginLogFile(filePath) KotlinTestUtils.assertEqualsToFile(renderFile, file.asRenderString()) KotlinTestUtils.assertEqualsToFile(logFile, file.asRecursiveLogString()) + + cleanUpIdenticalFile( + renderFile, + getRenderFile(filePath, "$counterpartSuffix.txt"), + getIdenticalRenderFile(filePath), + kind = "render" + ) + cleanUpIdenticalFile( + logFile, + getLogFile(filePath, "$counterpartSuffix.txt"), + getIdenticalLogFile(filePath), + kind = "log" + ) + } + + private val isTeamCityBuild: Boolean + get() = System.getenv("TEAMCITY_VERSION") != null + || KtUsefulTestCase.IS_UNDER_TEAMCITY + + private fun cleanUpIdenticalFile( + currentFile: File, + counterpartFile: File, + identicalFile: File, + kind: String + ) { + // Already cleaned up + if (identicalFile.exists()) return + // Nothing to compare + if (!currentFile.exists() || !counterpartFile.exists()) return + + val content = currentFile.readText().trim() + if (content == counterpartFile.readText().trim()) { + val message = if (isTeamCityBuild) { + "Please remove .$kind.fir.txt dump and .$kind.fe10.txt dump" + } else { + currentFile.delete() + counterpartFile.delete() + FileUtil.writeToFile(identicalFile, content) + "Deleted .$kind.fir.txt dump and .$kind.fe10.txt dump, added .$kind.txt instead" + } + KtAssert.fail( + """ + Dump via FIR UAST & via FE10 UAST are the same. + $message + Please re-run the test now + """.trimIndent() + ) + } } }