From 65a6b08fd39046229777d56bd293433ee1c6a8cd Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Mon, 10 Jun 2019 13:29:01 +0300 Subject: [PATCH] Fix lines joining of TextDiagnostics on Windows The initial assumption were that inside compiler and test framework all line breaks are normalized, because we read text files only through IDEA utils (which do normalization). The mistake was that 'StringBuilder.appendln()' appends 'System.lineSeparator()' as well, so it's not enough to only check that we don't load files from disk without normalizing whitespaces. Note that using 'it.replace(System.lineSeparator(), ...)' would be incorrect too, because actually we have strings with two kinds of line breaks here (normalized and not normalized), so we're looking for both via simple regex. --- .../jetbrains/kotlin/checkers/diagnostics/TextDiagnostic.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/TextDiagnostic.kt b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/TextDiagnostic.kt index bc03781848c..3d357e7c040 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/TextDiagnostic.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/checkers/diagnostics/TextDiagnostic.kt @@ -81,7 +81,7 @@ class TextDiagnostic( if (renderParameters && parameters != null) { result.append("(") - result.append(StringUtil.join(parameters, { "\"${it.replace('\n', ' ')}\"" }, ", ")) + result.append(StringUtil.join(parameters, { "\"" + crossPlatformLineBreak.matcher(it).replaceAll(" ") + "\"" }, ", ")) result.append(")") } return result.toString() @@ -92,6 +92,8 @@ class TextDiagnostic( } companion object { + private val crossPlatformLineBreak = Pattern.compile("""\r?\n""") + fun parseDiagnostic(text: String): TextDiagnostic { val matcher = CheckerTestUtil.individualDiagnosticPattern.matcher(text) if (!matcher.find())