Reformat incremental-compilation-impl tests

This commit is contained in:
Alexey Tsvetkov
2018-11-22 16:15:11 +03:00
parent db0d549f02
commit 201c16ecb0
11 changed files with 79 additions and 65 deletions
@@ -50,10 +50,12 @@ abstract class AbstractIncrementalCompilerRunnerTestBase<Args : CommonCompilerAr
// modifications // modifications
val buildLogFile = buildLogFinder.findBuildLog(testDir) ?: throw IllegalStateException("build log file not found in $workingDir") val buildLogFile = buildLogFinder.findBuildLog(testDir) ?: throw IllegalStateException("build log file not found in $workingDir")
val buildLogSteps = parseTestBuildLog(buildLogFile) val buildLogSteps = parseTestBuildLog(buildLogFile)
val modifications = getModificationsToPerform(testDir, val modifications = getModificationsToPerform(
testDir,
moduleNames = null, moduleNames = null,
allowNoFilesWithSuffixInTestData = false, allowNoFilesWithSuffixInTestData = false,
touchPolicy = TouchPolicy.CHECKSUM) touchPolicy = TouchPolicy.CHECKSUM
)
assert(modifications.size == buildLogSteps.size) { assert(modifications.size == buildLogSteps.size) {
"Modifications count (${modifications.size}) != expected build log steps count (${buildLogSteps.size})" "Modifications count (${modifications.size}) != expected build log steps count (${buildLogSteps.size})"
@@ -73,7 +75,14 @@ abstract class AbstractIncrementalCompilerRunnerTestBase<Args : CommonCompilerAr
val (_, compiledSources, compileErrors) = make(cacheDir, sourceRoots, args) val (_, compiledSources, compileErrors) = make(cacheDir, sourceRoots, args)
expectedSB.appendLine(stepLogAsString(step, buildLogStep.compiledKotlinFiles, buildLogStep.compileErrors)) expectedSB.appendLine(stepLogAsString(step, buildLogStep.compiledKotlinFiles, buildLogStep.compileErrors))
expectedSBWithoutErrors.appendLine(stepLogAsString(step, buildLogStep.compiledKotlinFiles, buildLogStep.compileErrors, includeErrors = false)) expectedSBWithoutErrors.appendLine(
stepLogAsString(
step,
buildLogStep.compiledKotlinFiles,
buildLogStep.compileErrors,
includeErrors = false
)
)
actualSB.appendLine(stepLogAsString(step, compiledSources.relativePaths(), compileErrors)) actualSB.appendLine(stepLogAsString(step, compiledSources.relativePaths(), compileErrors))
actualSBWithoutErrors.appendLine(stepLogAsString(step, compiledSources.relativePaths(), compileErrors, includeErrors = false)) actualSBWithoutErrors.appendLine(stepLogAsString(step, compiledSources.relativePaths(), compileErrors, includeErrors = false))
step++ step++
@@ -83,14 +92,13 @@ abstract class AbstractIncrementalCompilerRunnerTestBase<Args : CommonCompilerAr
if (BuildLogFinder.isJpsLogFile(buildLogFile)) { if (BuildLogFinder.isJpsLogFile(buildLogFile)) {
// JPS logs should be updated carefully, because standalone logs are a bit different (no removed classes, iterations, etc) // JPS logs should be updated carefully, because standalone logs are a bit different (no removed classes, iterations, etc)
Assert.assertEquals(expectedSB.toString(), actualSB.toString()) Assert.assertEquals(expectedSB.toString(), actualSB.toString())
} } else {
else {
UsefulTestCase.assertSameLinesWithFile(buildLogFile.canonicalPath, actualSB.toString(), false) UsefulTestCase.assertSameLinesWithFile(buildLogFile.canonicalPath, actualSB.toString(), false)
} }
} }
// todo: also compare caches // todo: also compare caches
run rebuildAndCompareOutput@ { run rebuildAndCompareOutput@{
val rebuildOutDir = File(workingDir, "rebuild-out").apply { mkdirs() } val rebuildOutDir = File(workingDir, "rebuild-out").apply { mkdirs() }
val rebuildCacheDir = File(workingDir, "rebuild-cache").apply { mkdirs() } val rebuildCacheDir = File(workingDir, "rebuild-cache").apply { mkdirs() }
val rebuildResult = make(rebuildCacheDir, sourceRoots, createCompilerArguments(rebuildOutDir, testDir)) val rebuildResult = make(rebuildCacheDir, sourceRoots, createCompilerArguments(rebuildOutDir, testDir))
@@ -57,7 +57,8 @@ abstract class AbstractIncrementalJvmCompilerRunnerTest : AbstractIncrementalCom
} }
val args = arrayOf("-cp", javaClasspath, val args = arrayOf("-cp", javaClasspath,
"-d", javaDestinationDir.canonicalPath, "-d", javaDestinationDir.canonicalPath,
*javaSources.map { it.canonicalPath }.toTypedArray()) *javaSources.map { it.canonicalPath }.toTypedArray()
)
val err = ByteArrayOutputStream() val err = ByteArrayOutputStream()
val javac = ToolProvider.getSystemJavaCompiler() val javac = ToolProvider.getSystemJavaCompiler()
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.incremental package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import java.io.File import java.io.File
abstract class AbstractIncrementalMultiplatformJsCompilerRunnerTest : AbstractIncrementalJsCompilerRunnerTest() { abstract class AbstractIncrementalMultiplatformJsCompilerRunnerTest : AbstractIncrementalJsCompilerRunnerTest() {
@@ -22,7 +22,6 @@ import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import java.io.File import java.io.File
import java.io.OutputStream
import java.util.* import java.util.*
class BuildDiffsStorageTest { class BuildDiffsStorageTest {
@@ -45,8 +44,10 @@ class BuildDiffsStorageTest {
val fqNames = listOf(FqName("fizz.Buzz")) val fqNames = listOf(FqName("fizz.Buzz"))
val diff = BuildDifference(100, true, DirtyData(lookupSymbols, fqNames)) val diff = BuildDifference(100, true, DirtyData(lookupSymbols, fqNames))
val diffs = BuildDiffsStorage(listOf(diff)) val diffs = BuildDiffsStorage(listOf(diff))
Assert.assertEquals("BuildDiffsStorage(buildDiffs=[BuildDifference(ts=100, isIncremental=true, dirtyData=DirtyData(dirtyLookupSymbols=[LookupSymbol(name=foo, scope=bar)], dirtyClassesFqNames=[fizz.Buzz]))])", Assert.assertEquals(
diffs.toString()) "BuildDiffsStorage(buildDiffs=[BuildDifference(ts=100, isIncremental=true, dirtyData=DirtyData(dirtyLookupSymbols=[LookupSymbol(name=foo, scope=bar)], dirtyClassesFqNames=[fizz.Buzz]))])",
diffs.toString()
)
} }
@Test @Test
@@ -87,8 +88,7 @@ class BuildDiffsStorageTest {
BuildDiffsStorage.CURRENT_VERSION++ BuildDiffsStorage.CURRENT_VERSION++
val diffsDeserialized = BuildDiffsStorage.readFromFile(storageFile, reporter = null) val diffsDeserialized = BuildDiffsStorage.readFromFile(storageFile, reporter = null)
Assert.assertEquals(null, diffsDeserialized) Assert.assertEquals(null, diffsDeserialized)
} } finally {
finally {
BuildDiffsStorage.CURRENT_VERSION = versionBackup BuildDiffsStorage.CURRENT_VERSION = versionBackup
} }
} }
@@ -2,7 +2,7 @@ package org.jetbrains.kotlin.incremental.snapshots
import org.jetbrains.kotlin.TestWithWorkingDir import org.jetbrains.kotlin.TestWithWorkingDir
import org.junit.After import org.junit.After
import org.junit.Assert.* import org.junit.Assert.assertArrayEquals
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import java.io.File import java.io.File
@@ -37,12 +37,16 @@ class FileSnapshotMapTest : TestWithWorkingDir() {
val diff1 = snapshotMap.compareAndUpdate(src.filesWithExt("txt")) val diff1 = snapshotMap.compareAndUpdate(src.filesWithExt("txt"))
assertArrayEquals("diff1.removed", assertArrayEquals(
"diff1.removed",
diff1.removed.toSortedPaths(), diff1.removed.toSortedPaths(),
emptyArray<String>()) emptyArray<String>()
assertArrayEquals("diff1.newOrModified", )
assertArrayEquals(
"diff1.newOrModified",
diff1.modified.toSortedPaths(), diff1.modified.toSortedPaths(),
listOf(removedTxt, unchangedTxt, changedTxt).toSortedPaths()) listOf(removedTxt, unchangedTxt, changedTxt).toSortedPaths()
)
removedTxt.delete() removedTxt.delete()
unchangedTxt.writeText("unchanged") unchangedTxt.writeText("unchanged")
@@ -50,12 +54,16 @@ class FileSnapshotMapTest : TestWithWorkingDir() {
val newTxt = File(foo, "new.txt").apply { writeText("new") } val newTxt = File(foo, "new.txt").apply { writeText("new") }
val diff2 = snapshotMap.compareAndUpdate(src.filesWithExt("txt")) val diff2 = snapshotMap.compareAndUpdate(src.filesWithExt("txt"))
assertArrayEquals("diff2.removed", assertArrayEquals(
"diff2.removed",
diff2.removed.toSortedPaths(), diff2.removed.toSortedPaths(),
listOf(removedTxt).toSortedPaths()) listOf(removedTxt).toSortedPaths()
assertArrayEquals("diff2.newOrModified", )
assertArrayEquals(
"diff2.newOrModified",
diff2.modified.toSortedPaths(), diff2.modified.toSortedPaths(),
listOf(newTxt, changedTxt).toSortedPaths()) listOf(newTxt, changedTxt).toSortedPaths()
)
} }
private fun Iterable<File>.toSortedPaths(): Array<String> = private fun Iterable<File>.toSortedPaths(): Array<String> =
@@ -1,7 +1,7 @@
package org.jetbrains.kotlin.incremental.snapshots package org.jetbrains.kotlin.incremental.snapshots
import org.jetbrains.kotlin.TestWithWorkingDir import org.jetbrains.kotlin.TestWithWorkingDir
import org.junit.Assert.* import org.junit.Assert.assertNotEquals
import org.junit.Test import org.junit.Test
import java.io.* import java.io.*
@@ -69,11 +69,9 @@ fun parseTestBuildLog(file: File): List<BuildStep> {
if (path.endsWith(".kt")) { if (path.endsWith(".kt")) {
compiledKotlinFiles.add(path) compiledKotlinFiles.add(path)
} } else if (path.endsWith(".java")) {
else if (path.endsWith(".java")) {
compiledJavaFiles.add(path) compiledJavaFiles.add(path)
} } else {
else {
throw IllegalStateException("Expected .kt or .java file, got: $path") throw IllegalStateException("Expected .kt or .java file, got: $path")
} }
} }
@@ -109,7 +107,7 @@ fun dumpBuildLog(buildSteps: Iterable<BuildStep>): String {
sb.appendln() sb.appendln()
} }
sb.appendln("================ Step #${i+1} =================") sb.appendln("================ Step #${i + 1} =================")
sb.appendln() sb.appendln()
sb.appendln(BEGIN_COMPILED_FILES) sb.appendln(BEGIN_COMPILED_FILES)
step.compiledKotlinFiles.sorted().forEach { sb.appendln(it) } step.compiledKotlinFiles.sorted().forEach { sb.appendln(it) }
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.incremental.utils
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import java.util.ArrayList import java.util.*
class TestMessageCollector : MessageCollector { class TestMessageCollector : MessageCollector {
val errors = ArrayList<String>() val errors = ArrayList<String>()