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
@@ -32,7 +32,7 @@ abstract class AbstractIncrementalCompilerRunnerTestBase<Args : CommonCompilerAr
val testDir = File(path) val testDir = File(path)
fun Iterable<File>.relativePaths() = fun Iterable<File>.relativePaths() =
map { it.relativeTo(workingDir).path.replace('\\', '/') } map { it.relativeTo(workingDir).path.replace('\\', '/') }
val srcDir = File(workingDir, "src").apply { mkdirs() } val srcDir = File(workingDir, "src").apply { mkdirs() }
val cacheDir = File(workingDir, "incremental-data").apply { mkdirs() } val cacheDir = File(workingDir, "incremental-data").apply { mkdirs() }
@@ -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(
moduleNames = null, testDir,
allowNoFilesWithSuffixInTestData = false, moduleNames = null,
touchPolicy = TouchPolicy.CHECKSUM) allowNoFilesWithSuffixInTestData = false,
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))
@@ -35,9 +35,9 @@ abstract class AbstractIncrementalJsCompilerRunnerTest : AbstractIncrementalComp
get() = super.buildLogFinder.copy(isJsEnabled = true) get() = super.buildLogFinder.copy(isJsEnabled = true)
override fun createCompilerArguments(destinationDir: File, testDir: File): K2JSCompilerArguments = override fun createCompilerArguments(destinationDir: File, testDir: File): K2JSCompilerArguments =
K2JSCompilerArguments().apply { K2JSCompilerArguments().apply {
outputFile = File(destinationDir, "${testDir.name}.js").path outputFile = File(destinationDir, "${testDir.name}.js").path
sourceMap = true sourceMap = true
metaInfo = true metaInfo = true
} }
} }
@@ -21,7 +21,7 @@ import java.io.File
abstract class AbstractIncrementalJsCompilerRunnerWithFriendModulesDisabledTest : AbstractIncrementalJsCompilerRunnerTest() { abstract class AbstractIncrementalJsCompilerRunnerWithFriendModulesDisabledTest : AbstractIncrementalJsCompilerRunnerTest() {
override fun createCompilerArguments(destinationDir: File, testDir: File): K2JSCompilerArguments = override fun createCompilerArguments(destinationDir: File, testDir: File): K2JSCompilerArguments =
super.createCompilerArguments(destinationDir, testDir).apply { super.createCompilerArguments(destinationDir, testDir).apply {
friendModulesDisabled = true friendModulesDisabled = true
} }
} }
@@ -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()
@@ -69,15 +70,15 @@ abstract class AbstractIncrementalJvmCompilerRunnerTest : AbstractIncrementalCom
} }
override fun createCompilerArguments(destinationDir: File, testDir: File): K2JVMCompilerArguments = override fun createCompilerArguments(destinationDir: File, testDir: File): K2JVMCompilerArguments =
K2JVMCompilerArguments().apply { K2JVMCompilerArguments().apply {
moduleName = testDir.name moduleName = testDir.name
destination = destinationDir.path destination = destinationDir.path
classpath = compileClasspath classpath = compileClasspath
} }
private val compileClasspath = private val compileClasspath =
listOf( listOf(
kotlinStdlibJvm, kotlinStdlibJvm,
KotlinTestUtils.getAnnotationsJar() KotlinTestUtils.getAnnotationsJar()
).joinToString(File.pathSeparator) { it.canonicalPath } ).joinToString(File.pathSeparator) { it.canonicalPath }
} }
@@ -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.toSortedPaths(), "diff1.removed",
emptyArray<String>()) diff1.removed.toSortedPaths(),
assertArrayEquals("diff1.newOrModified", emptyArray<String>()
diff1.modified.toSortedPaths(), )
listOf(removedTxt, unchangedTxt, changedTxt).toSortedPaths()) assertArrayEquals(
"diff1.newOrModified",
diff1.modified.toSortedPaths(),
listOf(removedTxt, unchangedTxt, changedTxt).toSortedPaths()
)
removedTxt.delete() removedTxt.delete()
unchangedTxt.writeText("unchanged") unchangedTxt.writeText("unchanged")
@@ -50,17 +54,21 @@ 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.toSortedPaths(), "diff2.removed",
listOf(removedTxt).toSortedPaths()) diff2.removed.toSortedPaths(),
assertArrayEquals("diff2.newOrModified", listOf(removedTxt).toSortedPaths()
diff2.modified.toSortedPaths(), )
listOf(newTxt, changedTxt).toSortedPaths()) assertArrayEquals(
"diff2.newOrModified",
diff2.modified.toSortedPaths(),
listOf(newTxt, changedTxt).toSortedPaths()
)
} }
private fun Iterable<File>.toSortedPaths(): Array<String> = private fun Iterable<File>.toSortedPaths(): Array<String> =
map { it.canonicalPath }.sorted().toTypedArray() map { it.canonicalPath }.sorted().toTypedArray()
private fun File.filesWithExt(ext: String): Iterable<File> = private fun File.filesWithExt(ext: String): Iterable<File> =
walk().filter { it.isFile && it.extension.equals(ext, ignoreCase = true) }.toList() walk().filter { it.isFile && it.extension.equals(ext, ignoreCase = true) }.toList()
} }
@@ -1,13 +1,13 @@
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.*
class FileSnapshotTest : TestWithWorkingDir() { class FileSnapshotTest : TestWithWorkingDir() {
private val fileSnapshotProvider: FileSnapshotProvider private val fileSnapshotProvider: FileSnapshotProvider
get() = SimpleFileSnapshotProviderImpl() get() = SimpleFileSnapshotProviderImpl()
@Test @Test
fun testExternalizer() { fun testExternalizer() {
@@ -24,9 +24,9 @@ private const val END_COMPILED_FILES = "End of files"
private const val BEGIN_ERRORS = "COMPILATION FAILED" private const val BEGIN_ERRORS = "COMPILATION FAILED"
class BuildStep( class BuildStep(
val compiledKotlinFiles: MutableSet<String> = hashSetOf(), val compiledKotlinFiles: MutableSet<String> = hashSetOf(),
val compiledJavaFiles: MutableSet<String> = hashSetOf(), val compiledJavaFiles: MutableSet<String> = hashSetOf(),
val compileErrors: MutableList<String> = arrayListOf() val compileErrors: MutableList<String> = arrayListOf()
) { ) {
val compileSucceeded: Boolean val compileSucceeded: Boolean
get() = compileErrors.isEmpty() get() = compileErrors.isEmpty()
@@ -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) }
@@ -20,12 +20,12 @@ import org.jetbrains.kotlin.cli.common.ExitCode
import java.io.File import java.io.File
data class TestCompilationResult( data class TestCompilationResult(
val exitCode: ExitCode, val exitCode: ExitCode,
val compiledSources: Iterable<File>, val compiledSources: Iterable<File>,
val compileErrors: Collection<String> val compileErrors: Collection<String>
) { ) {
constructor( constructor(
icReporter: TestICReporter, icReporter: TestICReporter,
messageCollector: TestMessageCollector messageCollector: TestMessageCollector
) : this(icReporter.exitCode, icReporter.compiledSources, messageCollector.errors) ) : this(icReporter.exitCode, icReporter.compiledSources, messageCollector.errors)
} }
@@ -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>()
@@ -35,5 +35,5 @@ class TestMessageCollector : MessageCollector {
} }
override fun hasErrors(): Boolean = override fun hasErrors(): Boolean =
errors.isNotEmpty() errors.isNotEmpty()
} }