Add test infrastructure to check the tracking lookups

Added simple test to verify infrastructure.
This commit is contained in:
Zalim Bashorov
2015-08-07 15:01:30 +03:00
parent 36f69d9fd6
commit 7e250ab2ca
7 changed files with 133 additions and 21 deletions
+1
View File
@@ -2,6 +2,7 @@
<dictionary name="bashor">
<words>
<w>ctor</w>
<w>lookups</w>
</words>
</dictionary>
</component>
@@ -95,6 +95,7 @@ import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterForWebDemoTest
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterMultiFileTest
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterSingleFileTest
import org.jetbrains.kotlin.jps.build.AbstractIncrementalJpsTest
import org.jetbrains.kotlin.jps.build.AbstractLookupTrackerTest
import org.jetbrains.kotlin.jps.build.android.AbstractAndroidJpsTestCase
import org.jetbrains.kotlin.js.test.semantics.*
import org.jetbrains.kotlin.jvm.compiler.*
@@ -796,6 +797,9 @@ fun main(args: Array<String>) {
model("incremental/pureKotlin", extension = null, excludeParentDirs = true)
model("incremental/withJava", extension = null, excludeParentDirs = true)
}
testClass(javaClass<AbstractLookupTrackerTest>()) {
model("incremental/lookupTracker", extension = null, excludeParentDirs = true)
}
}
testGroup("plugins/android-compiler-plugin/tests", "plugins/android-compiler-plugin/testData") {
@@ -38,9 +38,12 @@ import org.jetbrains.jps.cmdline.ProjectDescriptor
import org.jetbrains.jps.incremental.BuilderRegistry
import org.jetbrains.jps.incremental.IncProjectBuilder
import org.jetbrains.jps.incremental.messages.BuildMessage
import org.jetbrains.jps.model.JpsElementFactory
import org.jetbrains.jps.model.JpsModuleRootModificationUtil
import org.jetbrains.jps.model.java.JpsJavaExtensionService
import org.jetbrains.jps.util.JpsPathUtil
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.jps.build.classFilesComparison.assertEqualDirectories
import org.jetbrains.kotlin.jps.incremental.getKotlinCache
import org.jetbrains.kotlin.test.JetTestUtils
@@ -58,7 +61,9 @@ import kotlin.test.fail
public abstract class AbstractIncrementalJpsTest(
private val allowNoFilesWithSuffixInTestData: Boolean = false,
private val checkDumpsCaseInsensitively: Boolean = false
private val checkDumpsCaseInsensitively: Boolean = false,
private val allowNoBuildLogFileInTestData: Boolean = false,
private val allowNoLookupsFileInTestData: Boolean = true
) : JpsBuildTestCase() {
companion object {
val COMPILATION_FAILED = "COMPILATION FAILED"
@@ -106,6 +111,11 @@ public abstract class AbstractIncrementalJpsTest(
val workDirPath = FileUtil.toSystemIndependentName(workDir.getAbsolutePath())
val logger = MyLogger(workDirPath)
val descriptor = createProjectDescriptor(BuildLoggingManager(logger))
val lookupTracker = TestLookupTracker(workDirPath)
val dataContainer = JpsElementFactory.getInstance().createSimpleElement(lookupTracker)
descriptor.project.container.setChild(KotlinBuilder.LOOKUP_TRACKER, dataContainer)
try {
val builder = IncProjectBuilder(descriptor, BuilderRegistry.getInstance(), myBuildParams, CanceledStatus.NULL, mockConstantSearch, true)
val buildResult = BuildResult()
@@ -119,19 +129,20 @@ public abstract class AbstractIncrementalJpsTest(
.map { it.getMessageText() }
.map { it.replace("^.+:\\d+:\\s+".toRegex(), "").trim() }
.joinToString("\n")
return MakeResult(logger.log + "$COMPILATION_FAILED\n" + errorMessages + "\n", true, null)
return MakeResult(logger.log + "$COMPILATION_FAILED\n" + errorMessages + "\n", true, null, lookupTracker.lookups)
}
else {
return MakeResult(logger.log, false, createMappingsDump(descriptor))
return MakeResult(logger.log, false, createMappingsDump(descriptor), lookupTracker.lookups)
}
} finally {
descriptor.release()
}
}
private fun initialMake() {
private fun initialMake(): MakeResult {
val makeResult = build()
assertFalse(makeResult.makeFailed, "Initial make failed:\n$makeResult")
return makeResult
}
private fun make(): MakeResult {
@@ -252,13 +263,26 @@ public abstract class AbstractIncrementalJpsTest(
workDir = FileUtilRt.createTempDirectory(TEMP_DIRECTORY_TO_USE, "jps-build", null)
val moduleNames = configureModules()
initialMake()
val initialMakeResult = initialMake()
val makeOverallResult = performModificationsAndMake(moduleNames)
UsefulTestCase.assertSameLinesWithFile(File(testDataDir, "build.log").getAbsolutePath(), makeOverallResult.log)
val otherMakeResults = performModificationsAndMake(moduleNames)
rebuildAndCheckOutput(makeOverallResult)
clearCachesRebuildAndCheckOutput(makeOverallResult)
val buildLogFile = File(testDataDir, "build.log")
if (buildLogFile.exists() || !allowNoBuildLogFileInTestData) {
val logs = otherMakeResults.joinToString("\n\n") { it.log }
UsefulTestCase.assertSameLinesWithFile(buildLogFile.absolutePath, logs)
}
val lookupsFile = File(testDataDir, "lookups.txt")
if (lookupsFile.exists() || !allowNoLookupsFileInTestData) {
val allActualLookups = otherMakeResults.mapTo(arrayListOf(initialMakeResult.lookups), MakeResult::lookups.getter)
val actualLookups = allActualLookups.joinToString("\n\n") { it.toSortedList().join("\n") } + "\n"
UsefulTestCase.assertSameLinesWithFile(lookupsFile.absolutePath, actualLookups)
}
val lastMakeResult = otherMakeResults.last()
rebuildAndCheckOutput(lastMakeResult)
clearCachesRebuildAndCheckOutput(lastMakeResult)
}
private fun createMappingsDump(project: ProjectDescriptor) =
@@ -312,25 +336,18 @@ public abstract class AbstractIncrementalJpsTest(
return byteArrayOutputStream.toString()
}
private data class MakeResult(val log: String, val makeFailed: Boolean, val mappingsDump: String?)
private data class MakeResult(val log: String, val makeFailed: Boolean, val mappingsDump: String?, val lookups: List<String>)
private fun performModificationsAndMake(moduleNames: Set<String>?): MakeResult {
val logs = ArrayList<String>()
private fun performModificationsAndMake(moduleNames: Set<String>?): List<MakeResult> {
val results = arrayListOf<MakeResult>()
val modifications = getModificationsToPerform(moduleNames)
var lastCompilationFailed = false
var lastMappingsDump: String? = null
for (step in modifications) {
step.forEach { it.perform(workDir) }
performAdditionalModifications()
val makeResult = make()
logs.add(makeResult.log)
lastCompilationFailed = makeResult.makeFailed
lastMappingsDump = makeResult.mappingsDump
results.add(make())
}
return MakeResult(logs.join("\n\n"), lastCompilationFailed, lastMappingsDump)
return results
}
protected open fun performAdditionalModifications() {
@@ -377,6 +394,18 @@ public abstract class AbstractIncrementalJpsTest(
override fun doGetProjectDir(): File? = workDir
private class TestLookupTracker(val rootPath: String) : LookupTracker {
val lookups = arrayListOf<String>()
override val verbose: Boolean
get() = true
override fun record(lookupLocation: String, scopeFqName: String, scopeContainingFile: String?, scopeKind: ScopeKind, name: String) {
val s = """from "$lookupLocation" by "$name" in $scopeKind scope "$scopeFqName" in file ${scopeContainingFile?.let { "$it" } ?: null}"""
lookups.add(s.replace(rootPath, "\$TEST_DIR$"))
}
}
private class MyLogger(val rootPath: String) : ProjectBuilderLoggerBase() {
private val logBuf = StringBuilder()
public val log: String
@@ -0,0 +1,23 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.jps.build
abstract class AbstractLookupTrackerTest : AbstractIncrementalJpsTest(
allowNoFilesWithSuffixInTestData = true,
allowNoBuildLogFileInTestData = true,
allowNoLookupsFileInTestData = false
)
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.jps.build;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.JetTestUtils;
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("jps-plugin/testData/incremental/lookupTracker")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class LookupTrackerTestGenerated extends AbstractLookupTrackerTest {
public void testAllFilesPresentInLookupTracker() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("jps-plugin/testData/incremental/lookupTracker"), Pattern.compile("^([^\\.]+)$"), true);
}
@TestMetadata("simple")
public void testSimple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/lookupTracker/simple/");
doTest(fileName);
}
}
@@ -0,0 +1,5 @@
from "$TEST_DIR$/src/main.kt:3:16" by "Array" in PACKAGE scope "foo.bar" in file null
from "$TEST_DIR$/src/main.kt:3:22" by "String" in PACKAGE scope "foo.bar" in file null
from "$TEST_DIR$/src/main.kt:4:12" by "Array" in PACKAGE scope "foo.bar" in file null
from "$TEST_DIR$/src/main.kt:4:18" by "Int" in PACKAGE scope "foo.bar" in file null
from "$TEST_DIR$/src/main.kt:5:12" by "String" in PACKAGE scope "foo.bar" in file null
@@ -0,0 +1,6 @@
package foo.bar
fun main(args: Array<String>) {
val f: Array<Int>
val s: String
}