Add the support checking lookups after modifications
Original commit: cc3c76ae67
This commit is contained in:
@@ -56,7 +56,6 @@ import java.util.*
|
|||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.fail
|
|
||||||
|
|
||||||
public abstract class AbstractIncrementalJpsTest(
|
public abstract class AbstractIncrementalJpsTest(
|
||||||
private val allowNoFilesWithSuffixInTestData: Boolean = false,
|
private val allowNoFilesWithSuffixInTestData: Boolean = false,
|
||||||
@@ -109,10 +108,10 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
|
|
||||||
protected open fun createLookupTracker(): LookupTracker = LookupTracker.DO_NOTHING
|
protected open fun createLookupTracker(): LookupTracker = LookupTracker.DO_NOTHING
|
||||||
|
|
||||||
protected open fun checkLookups(@Suppress("UNUSED_PARAMETER") lookupTracker: LookupTracker) {
|
protected open fun checkLookups(modifications: List<Modification>, @Suppress("UNUSED_PARAMETER") lookupTracker: LookupTracker) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun build(scope: CompileScopeTestBuilder = CompileScopeTestBuilder.make().all()): MakeResult {
|
private fun build(scope: CompileScopeTestBuilder = CompileScopeTestBuilder.make().all(), modifications: List<Modification>, checkLookups: Boolean = true): MakeResult {
|
||||||
val workDirPath = FileUtil.toSystemIndependentName(workDir.absolutePath)
|
val workDirPath = FileUtil.toSystemIndependentName(workDir.absolutePath)
|
||||||
val logger = MyLogger(workDirPath)
|
val logger = MyLogger(workDirPath)
|
||||||
projectDescriptor = createProjectDescriptor(BuildLoggingManager(logger))
|
projectDescriptor = createProjectDescriptor(BuildLoggingManager(logger))
|
||||||
@@ -127,7 +126,9 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
builder.addMessageHandler(buildResult)
|
builder.addMessageHandler(buildResult)
|
||||||
builder.build(scope.build(), false)
|
builder.build(scope.build(), false)
|
||||||
|
|
||||||
checkLookups(lookupTracker)
|
if (checkLookups) {
|
||||||
|
checkLookups(modifications, lookupTracker)
|
||||||
|
}
|
||||||
|
|
||||||
if (!buildResult.isSuccessful) {
|
if (!buildResult.isSuccessful) {
|
||||||
val errorMessages =
|
val errorMessages =
|
||||||
@@ -149,17 +150,17 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initialMake(): MakeResult {
|
private fun initialMake(): MakeResult {
|
||||||
val makeResult = build()
|
val makeResult = build(modifications = emptyList())
|
||||||
assertFalse(makeResult.makeFailed, "Initial make failed:\n$makeResult")
|
assertFalse(makeResult.makeFailed, "Initial make failed:\n$makeResult")
|
||||||
return makeResult
|
return makeResult
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun make(): MakeResult {
|
private fun make(modifications: List<Modification>): MakeResult {
|
||||||
return build()
|
return build(modifications = modifications)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun rebuild(): MakeResult {
|
private fun rebuild(): MakeResult {
|
||||||
return build(CompileScopeTestBuilder.rebuild().allModules())
|
return build(CompileScopeTestBuilder.rebuild().allModules(), emptyList(), checkLookups = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getModificationsToPerform(moduleNames: Collection<String>?): List<List<Modification>> {
|
private fun getModificationsToPerform(moduleNames: Collection<String>?): List<List<Modification>> {
|
||||||
@@ -346,7 +347,14 @@ public abstract class AbstractIncrementalJpsTest(
|
|||||||
for (step in modifications) {
|
for (step in modifications) {
|
||||||
step.forEach { it.perform(workDir) }
|
step.forEach { it.perform(workDir) }
|
||||||
performAdditionalModifications(step)
|
performAdditionalModifications(step)
|
||||||
results.add(make())
|
if (moduleNames == null) {
|
||||||
|
preProcessSources(File(workDir, "src"))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
moduleNames.forEach { preProcessSources(File(workDir, "$it/src")) }
|
||||||
|
}
|
||||||
|
|
||||||
|
results.add(make(step))
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,23 +35,22 @@ abstract class AbstractLookupTrackerTest : AbstractIncrementalJpsTest(
|
|||||||
|
|
||||||
override fun createLookupTracker(): LookupTracker = TestLookupTracker()
|
override fun createLookupTracker(): LookupTracker = TestLookupTracker()
|
||||||
|
|
||||||
override fun checkLookups(lookupTracker: LookupTracker) {
|
override fun checkLookups(modifications: List<Modification>, lookupTracker: LookupTracker) {
|
||||||
if (lookupTracker !is TestLookupTracker) throw AssertionError("Expected TestLookupTracker, but: ${lookupTracker.javaClass}")
|
if (lookupTracker !is TestLookupTracker) throw AssertionError("Expected TestLookupTracker, but: ${lookupTracker.javaClass}")
|
||||||
|
|
||||||
val fileToLookups = lookupTracker.lookups.groupBy { it.lookupContainingFile }
|
val fileToLookups = lookupTracker.lookups.groupBy { it.lookupContainingFile }
|
||||||
val workSrcDir = File(workDir, "src")
|
val workSrcDir = File(workDir, "src")
|
||||||
|
|
||||||
for (file in workSrcDir.walkTopDown()) {
|
fun checkLookupsInFile(expectedFile: File, actualFile: File) {
|
||||||
if (!file.isFile) continue
|
|
||||||
|
|
||||||
val independentFilePath = FileUtil.toSystemIndependentName(file.path)
|
val independentFilePath = FileUtil.toSystemIndependentName(actualFile.path)
|
||||||
val lookupsFromFile = fileToLookups[independentFilePath] ?: continue
|
val lookupsFromFile = fileToLookups[independentFilePath] ?: return
|
||||||
|
|
||||||
val text = file.readText()
|
val text = actualFile.readText()
|
||||||
|
|
||||||
val matchResult = COMMENT_WITH_LOOKUP_INFO.find(text)
|
val matchResult = COMMENT_WITH_LOOKUP_INFO.find(text)
|
||||||
if (matchResult != null) {
|
if (matchResult != null) {
|
||||||
fail("File $file unexpectedly contains multiline comments. In range ${matchResult.range} found: ${matchResult.value} in $text")
|
fail("File $actualFile unexpectedly contains multiline comments. In range ${matchResult.range} found: ${matchResult.value} in $text")
|
||||||
}
|
}
|
||||||
|
|
||||||
val lines = text.lines().toArrayList()
|
val lines = text.lines().toArrayList()
|
||||||
@@ -93,7 +92,28 @@ abstract class AbstractLookupTrackerTest : AbstractIncrementalJpsTest(
|
|||||||
|
|
||||||
val actual = lines.joinToString("\n")
|
val actual = lines.joinToString("\n")
|
||||||
|
|
||||||
JetTestUtils.assertEqualsToFile(File(testDataDir, independentFilePath.replace(".*/src/".toRegex(), "")), actual)
|
JetTestUtils.assertEqualsToFile(expectedFile, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modifications.isNotEmpty()) {
|
||||||
|
for (modification in modifications) {
|
||||||
|
if (modification !is ModifyContent) continue
|
||||||
|
|
||||||
|
val expectedFile = modification.dataFile
|
||||||
|
val actualFile = File(workDir, modification.path)
|
||||||
|
|
||||||
|
checkLookupsInFile(expectedFile, actualFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (actualFile in workSrcDir.walkTopDown()) {
|
||||||
|
if (!actualFile.isFile) continue
|
||||||
|
|
||||||
|
val independentFilePath = FileUtil.toSystemIndependentName(actualFile.path)
|
||||||
|
val expectedFile = File(testDataDir, independentFilePath.replace(".*/src/".toRegex(), ""))
|
||||||
|
|
||||||
|
checkLookupsInFile(expectedFile, actualFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +122,13 @@ abstract class AbstractLookupTrackerTest : AbstractIncrementalJpsTest(
|
|||||||
private fun dropBlockComments(workSrcDir: File) {
|
private fun dropBlockComments(workSrcDir: File) {
|
||||||
for (file in workSrcDir.walkTopDown()) {
|
for (file in workSrcDir.walkTopDown()) {
|
||||||
if (!file.isFile) continue
|
if (!file.isFile) continue
|
||||||
file.writeText(file.readText().replace(COMMENT_WITH_LOOKUP_INFO, ""))
|
|
||||||
|
val original = file.readText()
|
||||||
|
val modified = original.replace(COMMENT_WITH_LOOKUP_INFO, "")
|
||||||
|
|
||||||
|
if (original != modified) {
|
||||||
|
file.writeText(modified)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user