FIR UAST: add utils to clean up identical render/log files

This commit is contained in:
Jinseong Jeon
2021-05-05 23:29:31 -07:00
committed by Ilya Kirillov
parent 1385a4690e
commit ebbef484ad
14 changed files with 92 additions and 61 deletions
@@ -1,3 +0,0 @@
UFile (package = declaration)
UImportStatement (isOnDemand = true)
UImportStatement (isOnDemand = true)
@@ -1,3 +1,3 @@
UFile (package = declaration)
UImportStatement (isOnDemand = true)
UImportStatement (isOnDemand = true)
UImportStatement (isOnDemand = true)
@@ -1,4 +0,0 @@
package declaration
import java.lang.Thread
import java.util
@@ -1,4 +1,4 @@
package declaration
import java.lang.Thread
import java.util
import java.util
@@ -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
}
@@ -28,4 +28,4 @@ public final class C {
public final class C2 {
public fun C2() = UastEmptyExpression
}
}
@@ -1,7 +0,0 @@
UFile (package = )
UImportStatement (isOnDemand = false)
UImportStatement (isOnDemand = false)
UImportStatement (isOnDemand = false)
UImportStatement (isOnDemand = false)
UImportStatement (isOnDemand = false)
UImportStatement (isOnDemand = false)
@@ -4,4 +4,4 @@ UFile (package = )
UImportStatement (isOnDemand = false)
UImportStatement (isOnDemand = false)
UImportStatement (isOnDemand = false)
UImportStatement (isOnDemand = false)
UImportStatement (isOnDemand = false)
@@ -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
@@ -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
@@ -0,0 +1,4 @@
UFile (package = )
UClass (name = TypeAliasesKt)
UClass (name = A)
UMethod (name = A)
@@ -0,0 +1,6 @@
public final class TypeAliasesKt {
}
public final class A {
public fun A() = UastEmptyExpression
}
@@ -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
}
@@ -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()
)
}
}
}