Test: change log dump format in gradle tests so it could be parsed again

This commit is contained in:
Alexey Tsvetkov
2016-03-25 06:54:48 +03:00
parent b050722249
commit 5d2d827772
5 changed files with 78 additions and 70 deletions
@@ -1,7 +1,7 @@
package org.jetbrains.kotlin.gradle package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.incremental.dumpBuildLog
import org.jetbrains.kotlin.gradle.incremental.parseTestBuildLog import org.jetbrains.kotlin.gradle.incremental.parseTestBuildLog
import org.jetbrains.kotlin.utils.Printer
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@@ -21,28 +21,7 @@ class BuildLogParserParametrizedIT : BaseGradleIT() {
val logFile = File(testDir, LOG_FILE_NAME) val logFile = File(testDir, LOG_FILE_NAME)
assert(logFile.isFile) { "Log file: $logFile does not exist" } assert(logFile.isFile) { "Log file: $logFile does not exist" }
val parsedStages = parseTestBuildLog(logFile) val actualNormalized = dumpBuildLog(parseTestBuildLog(logFile)).trim()
val sb = StringBuilder()
val p = Printer(sb)
for ((i, stage) in parsedStages.withIndex()) {
if (i > 0) {
p.println()
}
p.println("Step #${i + 1}")
p.println("Compiled java files:")
p.printlnSorted(stage.compiledJavaFiles)
p.println("Compiled kotlin files:")
p.printlnSorted(stage.compiledKotlinFiles)
p.println("Compile errors:")
p.printlnSorted(stage.compileErrors)
}
val actualNormalized = sb.toString().normalizeLineEnds()
val expectedFile = File(testDir, EXPECTED_PARSED_LOG_FILE_NAME) val expectedFile = File(testDir, EXPECTED_PARSED_LOG_FILE_NAME)
if (!expectedFile.isFile) { if (!expectedFile.isFile) {
@@ -52,8 +31,12 @@ class BuildLogParserParametrizedIT : BaseGradleIT() {
throw AssertionError("Expected file log did not exist, created: $expectedFile") throw AssertionError("Expected file log did not exist, created: $expectedFile")
} }
val expectedNormalized = expectedFile.readText().normalizeLineEnds() val expectedNormalized = expectedFile.readText().trim()
Assert.assertEquals("Parsed content was unexpected: ", expectedNormalized, actualNormalized) Assert.assertEquals("Parsed content was unexpected: ", expectedNormalized, actualNormalized)
// parse expected, dump again and compare (to check that dumped log can be parsed again)
val reparsedActualNormalized = dumpBuildLog(parseTestBuildLog(expectedFile)).trim()
Assert.assertEquals("Reparsed content was unexpected: ", expectedNormalized, reparsedActualNormalized)
} }
companion object { companion object {
@@ -69,13 +52,4 @@ class BuildLogParserParametrizedIT : BaseGradleIT() {
return directories.map { arrayOf(it.name) }.toList() return directories.map { arrayOf(it.name) }.toList()
} }
} }
} }
private fun <T : Comparable<T>> Printer.printlnSorted(elements: Iterable<T>) {
pushIndent()
elements.sorted().forEach { this.println(it) }
popIndent()
}
private fun String.normalizeLineEnds(): String =
lines().map { it.trimEnd() }.joinToString(separator="\n")
@@ -3,6 +3,10 @@ package org.jetbrains.kotlin.gradle.incremental
import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtil
import java.io.File import java.io.File
private const val BEGIN_COMPILED_FILES = "Compiling files:"
private const val END_COMPILED_FILES = "End of files"
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(),
@@ -34,12 +38,12 @@ fun parseTestBuildLog(file: File): List<BuildStep> {
var readFiles = false var readFiles = false
for (line in stepLines) { for (line in stepLines) {
if (line.startsWith("Compiling files:")) { if (line.startsWith(BEGIN_COMPILED_FILES)) {
readFiles = true readFiles = true
continue continue
} }
if (readFiles && line.startsWith("End of files")) { if (readFiles && line.startsWith(END_COMPILED_FILES)) {
readFiles = false readFiles = false
continue continue
} }
@@ -61,7 +65,7 @@ fun parseTestBuildLog(file: File): List<BuildStep> {
} }
fun BuildStep.parseErrors(stepLines: List<String>) { fun BuildStep.parseErrors(stepLines: List<String>) {
val startIndex = stepLines.indexOfLast { it.startsWith("COMPILATION FAILED") } val startIndex = stepLines.indexOfLast { it.startsWith(BEGIN_ERRORS) }
if (startIndex > 0) { if (startIndex > 0) {
compileErrors.addAll(stepLines.subList(startIndex + 1, stepLines.size)) compileErrors.addAll(stepLines.subList(startIndex + 1, stepLines.size))
@@ -78,3 +82,28 @@ fun parseTestBuildLog(file: File): List<BuildStep> {
buildStep buildStep
} }
} }
fun dumpBuildLog(buildSteps: Iterable<BuildStep>): String {
val sb = StringBuilder()
for ((i, step) in buildSteps.withIndex()) {
if (i > 0) {
sb.appendln()
}
sb.appendln("================ Step #${i+1} =================")
sb.appendln()
sb.appendln(BEGIN_COMPILED_FILES)
step.compiledKotlinFiles.sorted().forEach { sb.appendln(it) }
step.compiledJavaFiles.sorted().forEach { sb.appendln(it) }
sb.appendln(END_COMPILED_FILES)
sb.appendln("------------------------------------------")
if (!step.compileSucceeded) {
sb.appendln(BEGIN_ERRORS)
step.compileErrors.forEach { sb.appendln(it) }
}
}
return sb.toString()
}
@@ -1,14 +1,16 @@
Step #1 ================ Step #1 =================
Compiled java files:
Compiled kotlin files:
src/UsageVal.kt
src/UsageVar.kt
src/inlineGet.kt
Compile errors:
Step #2 Compiling files:
Compiled java files: src/UsageVal.kt
Compiled kotlin files: src/UsageVar.kt
src/UsageVar.kt src/inlineGet.kt
src/inlineSet.kt End of files
Compile errors: ------------------------------------------
================ Step #2 =================
Compiling files:
src/UsageVar.kt
src/inlineSet.kt
End of files
------------------------------------------
@@ -1,14 +1,16 @@
Step #1 ================ Step #1 =================
Compiled java files:
Compiled kotlin files: Compiling files:
module1/src/module1_a.kt module1/src/module1_a.kt
module2/src/module2_b.kt module2/src/module2_b.kt
Compile errors: End of files
Cannot access 'A': it is 'internal' in 'a' ------------------------------------------
Cannot access 'A': it is 'internal' in 'a' COMPILATION FAILED
Cannot access 'ClassAnnotation': it is 'internal' in 'a' Cannot access 'FileAnnotation': it is 'internal' in 'a'
Cannot access 'ClassAnnotation': it is 'internal' in 'a' Cannot access 'A': it is 'internal' in 'a'
Cannot access 'FileAnnotation': it is 'internal' in 'a' Cannot access 'FileAnnotation': it is 'internal' in 'a'
Cannot access 'FileAnnotation': it is 'internal' in 'a' Cannot access 'ClassAnnotation': it is 'internal' in 'a'
Cannot access 'a': it is 'internal' in 'a' Cannot access 'ClassAnnotation': it is 'internal' in 'a'
Function effective visibility 'public' should be the same or less permissive than its parameter type effective visibility 'internal' Function effective visibility 'public' should be the same or less permissive than its parameter type effective visibility 'internal'
Cannot access 'A': it is 'internal' in 'a'
Cannot access 'a': it is 'internal' in 'a'
@@ -1,6 +1,7 @@
Step #1 ================ Step #1 =================
Compiled java files:
src/JavaClass.java Compiling files:
Compiled kotlin files: src/usage.kt
src/usage.kt src/JavaClass.java
Compile errors: End of files
------------------------------------------