Test: change log dump format in gradle tests so it could be parsed again
This commit is contained in:
+8
-34
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.incremental.dumpBuildLog
|
||||
import org.jetbrains.kotlin.gradle.incremental.parseTestBuildLog
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
@@ -21,28 +21,7 @@ class BuildLogParserParametrizedIT : BaseGradleIT() {
|
||||
val logFile = File(testDir, LOG_FILE_NAME)
|
||||
assert(logFile.isFile) { "Log file: $logFile does not exist" }
|
||||
|
||||
val parsedStages = parseTestBuildLog(logFile)
|
||||
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 actualNormalized = dumpBuildLog(parseTestBuildLog(logFile)).trim()
|
||||
val expectedFile = File(testDir, EXPECTED_PARSED_LOG_FILE_NAME)
|
||||
|
||||
if (!expectedFile.isFile) {
|
||||
@@ -52,8 +31,12 @@ class BuildLogParserParametrizedIT : BaseGradleIT() {
|
||||
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)
|
||||
|
||||
// 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 {
|
||||
@@ -69,13 +52,4 @@ class BuildLogParserParametrizedIT : BaseGradleIT() {
|
||||
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")
|
||||
}
|
||||
+32
-3
@@ -3,6 +3,10 @@ package org.jetbrains.kotlin.gradle.incremental
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
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(
|
||||
val compiledKotlinFiles: MutableSet<String> = hashSetOf(),
|
||||
val compiledJavaFiles: MutableSet<String> = hashSetOf(),
|
||||
@@ -34,12 +38,12 @@ fun parseTestBuildLog(file: File): List<BuildStep> {
|
||||
var readFiles = false
|
||||
|
||||
for (line in stepLines) {
|
||||
if (line.startsWith("Compiling files:")) {
|
||||
if (line.startsWith(BEGIN_COMPILED_FILES)) {
|
||||
readFiles = true
|
||||
continue
|
||||
}
|
||||
|
||||
if (readFiles && line.startsWith("End of files")) {
|
||||
if (readFiles && line.startsWith(END_COMPILED_FILES)) {
|
||||
readFiles = false
|
||||
continue
|
||||
}
|
||||
@@ -61,7 +65,7 @@ fun parseTestBuildLog(file: File): List<BuildStep> {
|
||||
}
|
||||
|
||||
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) {
|
||||
compileErrors.addAll(stepLines.subList(startIndex + 1, stepLines.size))
|
||||
@@ -78,3 +82,28 @@ fun parseTestBuildLog(file: File): List<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()
|
||||
}
|
||||
+15
-13
@@ -1,14 +1,16 @@
|
||||
Step #1
|
||||
Compiled java files:
|
||||
Compiled kotlin files:
|
||||
src/UsageVal.kt
|
||||
src/UsageVar.kt
|
||||
src/inlineGet.kt
|
||||
Compile errors:
|
||||
================ Step #1 =================
|
||||
|
||||
Step #2
|
||||
Compiled java files:
|
||||
Compiled kotlin files:
|
||||
src/UsageVar.kt
|
||||
src/inlineSet.kt
|
||||
Compile errors:
|
||||
Compiling files:
|
||||
src/UsageVal.kt
|
||||
src/UsageVar.kt
|
||||
src/inlineGet.kt
|
||||
End of files
|
||||
------------------------------------------
|
||||
|
||||
================ Step #2 =================
|
||||
|
||||
Compiling files:
|
||||
src/UsageVar.kt
|
||||
src/inlineSet.kt
|
||||
End of files
|
||||
------------------------------------------
|
||||
|
||||
+16
-14
@@ -1,14 +1,16 @@
|
||||
Step #1
|
||||
Compiled java files:
|
||||
Compiled kotlin files:
|
||||
module1/src/module1_a.kt
|
||||
module2/src/module2_b.kt
|
||||
Compile errors:
|
||||
Cannot access 'A': it is 'internal' in 'a'
|
||||
Cannot access 'A': it is 'internal' in 'a'
|
||||
Cannot access 'ClassAnnotation': it is 'internal' in 'a'
|
||||
Cannot access 'ClassAnnotation': it is 'internal' in 'a'
|
||||
Cannot access 'FileAnnotation': it is 'internal' in 'a'
|
||||
Cannot access 'FileAnnotation': it is 'internal' in 'a'
|
||||
Cannot access 'a': it is 'internal' in 'a'
|
||||
Function effective visibility 'public' should be the same or less permissive than its parameter type effective visibility 'internal'
|
||||
================ Step #1 =================
|
||||
|
||||
Compiling files:
|
||||
module1/src/module1_a.kt
|
||||
module2/src/module2_b.kt
|
||||
End of files
|
||||
------------------------------------------
|
||||
COMPILATION FAILED
|
||||
Cannot access 'FileAnnotation': it is 'internal' in 'a'
|
||||
Cannot access 'A': it is 'internal' in 'a'
|
||||
Cannot access 'FileAnnotation': it is 'internal' in 'a'
|
||||
Cannot access 'ClassAnnotation': 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'
|
||||
Cannot access 'A': it is 'internal' in 'a'
|
||||
Cannot access 'a': it is 'internal' in 'a'
|
||||
|
||||
+7
-6
@@ -1,6 +1,7 @@
|
||||
Step #1
|
||||
Compiled java files:
|
||||
src/JavaClass.java
|
||||
Compiled kotlin files:
|
||||
src/usage.kt
|
||||
Compile errors:
|
||||
================ Step #1 =================
|
||||
|
||||
Compiling files:
|
||||
src/usage.kt
|
||||
src/JavaClass.java
|
||||
End of files
|
||||
------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user