IC tests: add infrastructure for K1/K2 lookups comparison
Adapt lookup tests to allow running K1 and K2 on the same testdata and compare the lookups recorded.
This commit is contained in:
committed by
Space Team
parent
684d0b8690
commit
1989e8f094
@@ -90,6 +90,9 @@ fun main(args: Array<String>) {
|
||||
testClass<AbstractJvmLookupTrackerTest> {
|
||||
model("incremental/lookupTracker/jvm", extension = null, recursive = false)
|
||||
}
|
||||
testClass<AbstractK1JvmLookupTrackerTest> {
|
||||
model("incremental/lookupTracker/jvm", extension = null, recursive = false)
|
||||
}
|
||||
testClass<AbstractJsKlibLookupTrackerTest> {
|
||||
// todo: investigate why lookups are different from non-klib js
|
||||
model("incremental/lookupTracker/jsKlib", extension = null, recursive = false)
|
||||
|
||||
+4
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.jps.build
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.incremental.testingUtils.BuildLogFinder
|
||||
|
||||
abstract class AbstractIncrementalK1JvmJpsTest(
|
||||
allowNoFilesWithSuffixInTestData: Boolean = false
|
||||
@@ -17,4 +18,7 @@ abstract class AbstractIncrementalK1JvmJpsTest(
|
||||
}
|
||||
super.updateCommandLineArguments(arguments)
|
||||
}
|
||||
|
||||
override val buildLogFinder: BuildLogFinder
|
||||
get() = super.buildLogFinder.copy(isFirEnabled = false)
|
||||
}
|
||||
|
||||
+65
-23
@@ -21,14 +21,16 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.incremental.isKotlinFile
|
||||
import org.jetbrains.kotlin.incremental.js.*
|
||||
import org.jetbrains.kotlin.incremental.makeModuleFile
|
||||
import org.jetbrains.kotlin.incremental.testingUtils.TouchPolicy
|
||||
import org.jetbrains.kotlin.incremental.testingUtils.copyTestSources
|
||||
import org.jetbrains.kotlin.incremental.testingUtils.getModificationsToPerform
|
||||
import org.jetbrains.kotlin.incremental.testingUtils.*
|
||||
import org.jetbrains.kotlin.incremental.utils.TestLookupTracker
|
||||
import org.jetbrains.kotlin.incremental.utils.TestMessageCollector
|
||||
import org.jetbrains.kotlin.jps.build.fixtures.EnableICFixture
|
||||
import org.jetbrains.kotlin.jps.incremental.createTestingCompilerEnvironment
|
||||
import org.jetbrains.kotlin.jps.incremental.runJSCompiler
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.kotlinPathsForDistDirectoryForTests
|
||||
import org.jetbrains.kotlin.utils.JsMetadataVersion
|
||||
@@ -66,6 +68,10 @@ abstract class AbstractJvmLookupTrackerTest : AbstractLookupTrackerTest() {
|
||||
}
|
||||
}
|
||||
|
||||
open fun configureAdditionalArgs(args: K2JVMCompilerArguments) {
|
||||
args.useFirLT = false
|
||||
}
|
||||
|
||||
override fun runCompiler(filesToCompile: Iterable<File>, env: JpsCompilerEnvironment): Any? {
|
||||
val moduleFile = makeModuleFile(
|
||||
name = "test",
|
||||
@@ -82,8 +88,8 @@ abstract class AbstractJvmLookupTrackerTest : AbstractLookupTrackerTest() {
|
||||
disableDefaultScriptingPlugin = true
|
||||
buildFile = moduleFile.canonicalPath
|
||||
reportOutputFiles = true
|
||||
useFirLT = false
|
||||
}
|
||||
configureAdditionalArgs(args)
|
||||
val argsArray = ArgumentUtils.convertArgumentsToStringList(args).toTypedArray()
|
||||
|
||||
try {
|
||||
@@ -100,6 +106,24 @@ abstract class AbstractJvmLookupTrackerTest : AbstractLookupTrackerTest() {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractK1JvmLookupTrackerTest : AbstractJvmLookupTrackerTest() {
|
||||
|
||||
override var filterBuiltins = true
|
||||
override var distinguishPackageAndClassLookups = false
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
optionalVariantSuffix = OptionalVariantSuffix.K1
|
||||
}
|
||||
|
||||
override fun configureAdditionalArgs(args: K2JVMCompilerArguments) {
|
||||
args.languageVersion = "1.9"
|
||||
}
|
||||
|
||||
override val buildLogFinder: BuildLogFinder
|
||||
get() = BuildLogFinder(isGradleEnabled = false, isFirEnabled = false)
|
||||
}
|
||||
|
||||
abstract class AbstractJsKlibLookupTrackerTest : AbstractJsLookupTrackerTest() {
|
||||
override fun configureAdditionalArgs(args: K2JSCompilerArguments) {
|
||||
args.irProduceKlibDir = true
|
||||
@@ -181,6 +205,9 @@ abstract class AbstractLookupTrackerTest : TestWithWorkingDir() {
|
||||
protected lateinit var srcDir: File
|
||||
protected lateinit var outDir: File
|
||||
private val enableICFixture = EnableICFixture()
|
||||
protected var optionalVariantSuffix: OptionalVariantSuffix = OptionalVariantSuffix.K2
|
||||
protected open var filterBuiltins = false
|
||||
protected open var distinguishPackageAndClassLookups = true
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
@@ -200,6 +227,9 @@ abstract class AbstractLookupTrackerTest : TestWithWorkingDir() {
|
||||
protected abstract fun processCompilationResults(outputItemsCollector: OutputItemsCollectorImpl, services: Services)
|
||||
protected abstract fun runCompiler(filesToCompile: Iterable<File>, env: JpsCompilerEnvironment): Any?
|
||||
|
||||
protected open val buildLogFinder: BuildLogFinder
|
||||
get() = BuildLogFinder(isGradleEnabled = false)
|
||||
|
||||
fun doTest(path: String) {
|
||||
val sb = StringBuilder()
|
||||
fun StringBuilder.indentln(string: String) {
|
||||
@@ -228,13 +258,14 @@ abstract class AbstractLookupTrackerTest : TestWithWorkingDir() {
|
||||
}
|
||||
|
||||
val testDir = File(path)
|
||||
val workToOriginalFileMap = HashMap(copyTestSources(testDir, srcDir, filePrefix = ""))
|
||||
val workToOriginalFileMap = HashMap(copyTestSources(testDir, srcDir, filePrefix = "", optionalVariantSuffix = optionalVariantSuffix))
|
||||
var dirtyFiles = srcDir.walk().filterTo(HashSet()) { it.isKotlinFile(setOf("kt", "kts")) }
|
||||
val steps = getModificationsToPerform(
|
||||
testDir,
|
||||
moduleNames = null,
|
||||
allowNoFilesWithSuffixInTestData = true,
|
||||
touchPolicy = TouchPolicy.CHECKSUM
|
||||
touchPolicy = TouchPolicy.CHECKSUM,
|
||||
optionalVariantSuffix = optionalVariantSuffix
|
||||
)
|
||||
.filter { it.isNotEmpty() }
|
||||
|
||||
@@ -255,8 +286,9 @@ abstract class AbstractLookupTrackerTest : TestWithWorkingDir() {
|
||||
}
|
||||
}
|
||||
|
||||
val expectedBuildLog = File(testDir, "build.log")
|
||||
UsefulTestCase.assertSameLinesWithFile(expectedBuildLog.canonicalPath, sb.toString())
|
||||
buildLogFinder.findBuildLog(testDir)?.let { expectedBuildLog ->
|
||||
UsefulTestCase.assertSameLinesWithFile(expectedBuildLog.canonicalPath, sb.toString())
|
||||
}
|
||||
|
||||
assertEquals(steps.size + 1, filesToLookups.size)
|
||||
for ((i, lookupsAtStepI) in filesToLookups.withIndex()) {
|
||||
@@ -317,23 +349,33 @@ abstract class AbstractLookupTrackerTest : TestWithWorkingDir() {
|
||||
val end = column - 1
|
||||
parts.add(lineContent.subSequence(start, end))
|
||||
|
||||
val lookups = lookupsFromColumn.mapTo(sortedSetOf()) { lookupInfo ->
|
||||
val rest = lineContent.substring(end)
|
||||
lookupsFromColumn.mapNotNullTo(sortedSetOf()) { lookupInfo ->
|
||||
if (filterBuiltins &&
|
||||
ClassId(FqName(lookupInfo.scopeFqName), Name.identifier(lookupInfo.name)) in StandardClassIds.allBuiltinTypes
|
||||
) {
|
||||
null
|
||||
} else {
|
||||
val rest = lineContent.substring(end)
|
||||
|
||||
val name =
|
||||
when {
|
||||
rest.startsWith(lookupInfo.name) || // same name
|
||||
rest.startsWith("$" + lookupInfo.name) || // backing field
|
||||
DECLARATION_STARTS_WITH.any { rest.startsWith(it) } // it's declaration
|
||||
-> ""
|
||||
else -> "(" + lookupInfo.name + ")"
|
||||
}
|
||||
val name =
|
||||
when {
|
||||
rest.startsWith(lookupInfo.name) || // same name
|
||||
rest.startsWith("$" + lookupInfo.name) || // backing field
|
||||
DECLARATION_STARTS_WITH.any { rest.startsWith(it) } // it's declaration
|
||||
-> ""
|
||||
else -> "(" + lookupInfo.name + ")"
|
||||
}
|
||||
|
||||
lookupInfo.scopeKind.toString()[0].lowercaseChar()
|
||||
.toString() + ":" + lookupInfo.scopeFqName.let { it.ifEmpty { "<root>" } } + name
|
||||
}.joinToString(separator = " ", prefix = "/*", postfix = "*/")
|
||||
|
||||
parts.add(lookups)
|
||||
val prefix =
|
||||
if (distinguishPackageAndClassLookups) lookupInfo.scopeKind.toString()[0].lowercaseChar().toString()
|
||||
else "p"
|
||||
prefix + ":" + lookupInfo.scopeFqName.let { it.ifEmpty { "<root>" } } + name
|
||||
}
|
||||
}.takeIf { it.isNotEmpty() }
|
||||
?.joinToString(separator = " ", prefix = "/*", postfix = "*/")
|
||||
?.also {
|
||||
parts.add(it)
|
||||
}
|
||||
|
||||
start = end
|
||||
}
|
||||
|
||||
Generated
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.jps.build;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
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.jps.GenerateJpsPluginTestsKt}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("jps/jps-plugin/testData/incremental/lookupTracker/jvm")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class K1JvmLookupTrackerTestGenerated extends AbstractK1JvmLookupTrackerTest {
|
||||
private void runTest(String testDataFilePath) {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJvm() {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps/jps-plugin/testData/incremental/lookupTracker/jvm"), Pattern.compile("^([^\\.]+)$"), null, false);
|
||||
}
|
||||
|
||||
@TestMetadata("classifierMembers")
|
||||
public void testClassifierMembers() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/classifierMembers/");
|
||||
}
|
||||
|
||||
@TestMetadata("conventions")
|
||||
public void testConventions() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/conventions/");
|
||||
}
|
||||
|
||||
@TestMetadata("expressionType")
|
||||
public void testExpressionType() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/expressionType/");
|
||||
}
|
||||
|
||||
@TestMetadata("java")
|
||||
public void testJava() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/java/");
|
||||
}
|
||||
|
||||
@TestMetadata("jvmNameChanged")
|
||||
public void testJvmNameChanged() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/jvmNameChanged/");
|
||||
}
|
||||
|
||||
@TestMetadata("localDeclarations")
|
||||
public void testLocalDeclarations() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/localDeclarations/");
|
||||
}
|
||||
|
||||
@TestMetadata("packageDeclarations")
|
||||
public void testPackageDeclarations() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/packageDeclarations/");
|
||||
}
|
||||
|
||||
@TestMetadata("SAM")
|
||||
public void testSAM() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/SAM/");
|
||||
}
|
||||
|
||||
@TestMetadata("simple")
|
||||
public void testSimple() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/simple/");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticProperties")
|
||||
public void testSyntheticProperties() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/syntheticProperties/");
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasAndUsage")
|
||||
public void testTypeAliasAndUsage() {
|
||||
runTest("jps/jps-plugin/testData/incremental/lookupTracker/jvm/typeAliasAndUsage/");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user