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)
fun Iterable<File>.relativePaths() =
map { it.relativeTo(workingDir).path.replace('\\', '/') }
map { it.relativeTo(workingDir).path.replace('\\', '/') }
val srcDir = File(workingDir, "src").apply { mkdirs() }
val cacheDir = File(workingDir, "incremental-data").apply { mkdirs() }
@@ -50,10 +50,12 @@ abstract class AbstractIncrementalCompilerRunnerTestBase<Args : CommonCompilerAr
// modifications
val buildLogFile = buildLogFinder.findBuildLog(testDir) ?: throw IllegalStateException("build log file not found in $workingDir")
val buildLogSteps = parseTestBuildLog(buildLogFile)
val modifications = getModificationsToPerform(testDir,
moduleNames = null,
allowNoFilesWithSuffixInTestData = false,
touchPolicy = TouchPolicy.CHECKSUM)
val modifications = getModificationsToPerform(
testDir,
moduleNames = null,
allowNoFilesWithSuffixInTestData = false,
touchPolicy = TouchPolicy.CHECKSUM
)
assert(modifications.size == 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)
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))
actualSBWithoutErrors.appendLine(stepLogAsString(step, compiledSources.relativePaths(), compileErrors, includeErrors = false))
step++
@@ -83,14 +92,13 @@ abstract class AbstractIncrementalCompilerRunnerTestBase<Args : CommonCompilerAr
if (BuildLogFinder.isJpsLogFile(buildLogFile)) {
// JPS logs should be updated carefully, because standalone logs are a bit different (no removed classes, iterations, etc)
Assert.assertEquals(expectedSB.toString(), actualSB.toString())
}
else {
} else {
UsefulTestCase.assertSameLinesWithFile(buildLogFile.canonicalPath, actualSB.toString(), false)
}
}
// todo: also compare caches
run rebuildAndCompareOutput@ {
run rebuildAndCompareOutput@{
val rebuildOutDir = File(workingDir, "rebuild-out").apply { mkdirs() }
val rebuildCacheDir = File(workingDir, "rebuild-cache").apply { mkdirs() }
val rebuildResult = make(rebuildCacheDir, sourceRoots, createCompilerArguments(rebuildOutDir, testDir))
@@ -35,9 +35,9 @@ abstract class AbstractIncrementalJsCompilerRunnerTest : AbstractIncrementalComp
get() = super.buildLogFinder.copy(isJsEnabled = true)
override fun createCompilerArguments(destinationDir: File, testDir: File): K2JSCompilerArguments =
K2JSCompilerArguments().apply {
outputFile = File(destinationDir, "${testDir.name}.js").path
sourceMap = true
metaInfo = true
}
K2JSCompilerArguments().apply {
outputFile = File(destinationDir, "${testDir.name}.js").path
sourceMap = true
metaInfo = true
}
}
@@ -21,7 +21,7 @@ import java.io.File
abstract class AbstractIncrementalJsCompilerRunnerWithFriendModulesDisabledTest : AbstractIncrementalJsCompilerRunnerTest() {
override fun createCompilerArguments(destinationDir: File, testDir: File): K2JSCompilerArguments =
super.createCompilerArguments(destinationDir, testDir).apply {
friendModulesDisabled = true
}
super.createCompilerArguments(destinationDir, testDir).apply {
friendModulesDisabled = true
}
}
@@ -57,7 +57,8 @@ abstract class AbstractIncrementalJvmCompilerRunnerTest : AbstractIncrementalCom
}
val args = arrayOf("-cp", javaClasspath,
"-d", javaDestinationDir.canonicalPath,
*javaSources.map { it.canonicalPath }.toTypedArray())
*javaSources.map { it.canonicalPath }.toTypedArray()
)
val err = ByteArrayOutputStream()
val javac = ToolProvider.getSystemJavaCompiler()
@@ -69,15 +70,15 @@ abstract class AbstractIncrementalJvmCompilerRunnerTest : AbstractIncrementalCom
}
override fun createCompilerArguments(destinationDir: File, testDir: File): K2JVMCompilerArguments =
K2JVMCompilerArguments().apply {
moduleName = testDir.name
destination = destinationDir.path
classpath = compileClasspath
}
K2JVMCompilerArguments().apply {
moduleName = testDir.name
destination = destinationDir.path
classpath = compileClasspath
}
private val compileClasspath =
listOf(
kotlinStdlibJvm,
KotlinTestUtils.getAnnotationsJar()
).joinToString(File.pathSeparator) { it.canonicalPath }
listOf(
kotlinStdlibJvm,
KotlinTestUtils.getAnnotationsJar()
).joinToString(File.pathSeparator) { it.canonicalPath }
}
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import java.io.File
abstract class AbstractIncrementalMultiplatformJsCompilerRunnerTest : AbstractIncrementalJsCompilerRunnerTest() {
@@ -22,7 +22,6 @@ import org.junit.Assert
import org.junit.Before
import org.junit.Test
import java.io.File
import java.io.OutputStream
import java.util.*
class BuildDiffsStorageTest {
@@ -45,8 +44,10 @@ class BuildDiffsStorageTest {
val fqNames = listOf(FqName("fizz.Buzz"))
val diff = BuildDifference(100, true, DirtyData(lookupSymbols, fqNames))
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]))])",
diffs.toString())
Assert.assertEquals(
"BuildDiffsStorage(buildDiffs=[BuildDifference(ts=100, isIncremental=true, dirtyData=DirtyData(dirtyLookupSymbols=[LookupSymbol(name=foo, scope=bar)], dirtyClassesFqNames=[fizz.Buzz]))])",
diffs.toString()
)
}
@Test
@@ -87,8 +88,7 @@ class BuildDiffsStorageTest {
BuildDiffsStorage.CURRENT_VERSION++
val diffsDeserialized = BuildDiffsStorage.readFromFile(storageFile, reporter = null)
Assert.assertEquals(null, diffsDeserialized)
}
finally {
} finally {
BuildDiffsStorage.CURRENT_VERSION = versionBackup
}
}
@@ -2,7 +2,7 @@ package org.jetbrains.kotlin.incremental.snapshots
import org.jetbrains.kotlin.TestWithWorkingDir
import org.junit.After
import org.junit.Assert.*
import org.junit.Assert.assertArrayEquals
import org.junit.Before
import org.junit.Test
import java.io.File
@@ -37,12 +37,16 @@ class FileSnapshotMapTest : TestWithWorkingDir() {
val diff1 = snapshotMap.compareAndUpdate(src.filesWithExt("txt"))
assertArrayEquals("diff1.removed",
diff1.removed.toSortedPaths(),
emptyArray<String>())
assertArrayEquals("diff1.newOrModified",
diff1.modified.toSortedPaths(),
listOf(removedTxt, unchangedTxt, changedTxt).toSortedPaths())
assertArrayEquals(
"diff1.removed",
diff1.removed.toSortedPaths(),
emptyArray<String>()
)
assertArrayEquals(
"diff1.newOrModified",
diff1.modified.toSortedPaths(),
listOf(removedTxt, unchangedTxt, changedTxt).toSortedPaths()
)
removedTxt.delete()
unchangedTxt.writeText("unchanged")
@@ -50,17 +54,21 @@ class FileSnapshotMapTest : TestWithWorkingDir() {
val newTxt = File(foo, "new.txt").apply { writeText("new") }
val diff2 = snapshotMap.compareAndUpdate(src.filesWithExt("txt"))
assertArrayEquals("diff2.removed",
diff2.removed.toSortedPaths(),
listOf(removedTxt).toSortedPaths())
assertArrayEquals("diff2.newOrModified",
diff2.modified.toSortedPaths(),
listOf(newTxt, changedTxt).toSortedPaths())
assertArrayEquals(
"diff2.removed",
diff2.removed.toSortedPaths(),
listOf(removedTxt).toSortedPaths()
)
assertArrayEquals(
"diff2.newOrModified",
diff2.modified.toSortedPaths(),
listOf(newTxt, changedTxt).toSortedPaths()
)
}
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> =
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
import org.jetbrains.kotlin.TestWithWorkingDir
import org.junit.Assert.*
import org.junit.Assert.assertNotEquals
import org.junit.Test
import java.io.*
class FileSnapshotTest : TestWithWorkingDir() {
private val fileSnapshotProvider: FileSnapshotProvider
get() = SimpleFileSnapshotProviderImpl()
get() = SimpleFileSnapshotProviderImpl()
@Test
fun testExternalizer() {
@@ -24,9 +24,9 @@ private const val END_COMPILED_FILES = "End of files"
private const val BEGIN_ERRORS = "COMPILATION FAILED"
class BuildStep(
val compiledKotlinFiles: MutableSet<String> = hashSetOf(),
val compiledJavaFiles: MutableSet<String> = hashSetOf(),
val compileErrors: MutableList<String> = arrayListOf()
val compiledKotlinFiles: MutableSet<String> = hashSetOf(),
val compiledJavaFiles: MutableSet<String> = hashSetOf(),
val compileErrors: MutableList<String> = arrayListOf()
) {
val compileSucceeded: Boolean
get() = compileErrors.isEmpty()
@@ -69,11 +69,9 @@ fun parseTestBuildLog(file: File): List<BuildStep> {
if (path.endsWith(".kt")) {
compiledKotlinFiles.add(path)
}
else if (path.endsWith(".java")) {
} else if (path.endsWith(".java")) {
compiledJavaFiles.add(path)
}
else {
} else {
throw IllegalStateException("Expected .kt or .java file, got: $path")
}
}
@@ -109,7 +107,7 @@ fun dumpBuildLog(buildSteps: Iterable<BuildStep>): String {
sb.appendln()
}
sb.appendln("================ Step #${i+1} =================")
sb.appendln("================ Step #${i + 1} =================")
sb.appendln()
sb.appendln(BEGIN_COMPILED_FILES)
step.compiledKotlinFiles.sorted().forEach { sb.appendln(it) }
@@ -20,12 +20,12 @@ import org.jetbrains.kotlin.cli.common.ExitCode
import java.io.File
data class TestCompilationResult(
val exitCode: ExitCode,
val compiledSources: Iterable<File>,
val compileErrors: Collection<String>
val exitCode: ExitCode,
val compiledSources: Iterable<File>,
val compileErrors: Collection<String>
) {
constructor(
icReporter: TestICReporter,
messageCollector: TestMessageCollector
icReporter: TestICReporter,
messageCollector: TestMessageCollector
) : 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.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import java.util.ArrayList
import java.util.*
class TestMessageCollector : MessageCollector {
val errors = ArrayList<String>()
@@ -35,5 +35,5 @@ class TestMessageCollector : MessageCollector {
}
override fun hasErrors(): Boolean =
errors.isNotEmpty()
errors.isNotEmpty()
}