From 7e1713af4420d0f13cad2cc447787b80645f0537 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Wed, 6 Jun 2018 18:59:23 +0300 Subject: [PATCH] Tests: keep "// !" directives first when auto-muting box tests --- .../kotlin/test/KotlinTestUtils.java | 21 +++++++++++++++++-- .../kotlin/test/KotlinTestUtils.java.173 | 21 +++++++++++++++++-- .../kotlin/test/KotlinTestUtils.java.as31 | 21 +++++++++++++++++-- .../kotlin/test/KotlinTestUtils.java.as32 | 21 +++++++++++++++++-- 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index d4a1fad3f5f..8fd7df18622 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -1060,8 +1060,25 @@ public class KotlinTestUtils { if (!isIgnored && AUTOMATICALLY_MUTE_FAILED_TESTS) { String text = doLoadFile(testDataFile); - String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name(); - String newText = directive + "\n" + text; + String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name() + "\n"; + + String newText; + if (text.startsWith("// !")) { + StringBuilder prefixBuilder = new StringBuilder(); + int l = 0; + while (text.startsWith("// !", l)) { + int r = text.indexOf("\n", l) + 1; + if (r <= 0) r = text.length(); + prefixBuilder.append(text.substring(l, r)); + l = r; + } + prefixBuilder.append(directive); + prefixBuilder.append(text.substring(l)); + + newText = prefixBuilder.toString(); + } else { + newText = directive + text; + } if (!newText.equals(text)) { System.err.println("\"" + directive + "\" was added to \"" + testDataFile + "\""); diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 index 235ab97f3ce..f07a34719b7 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.173 @@ -1060,8 +1060,25 @@ public class KotlinTestUtils { if (!isIgnored && AUTOMATICALLY_MUTE_FAILED_TESTS) { String text = doLoadFile(testDataFile); - String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name(); - String newText = directive + "\n" + text; + String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name() + "\n"; + + String newText; + if (text.startsWith("// !")) { + StringBuilder prefixBuilder = new StringBuilder(); + int l = 0; + while (text.startsWith("// !", l)) { + int r = text.indexOf("\n", l) + 1; + if (r <= 0) r = text.length(); + prefixBuilder.append(text.substring(l, r)); + l = r; + } + prefixBuilder.append(directive); + prefixBuilder.append(text.substring(l)); + + newText = prefixBuilder.toString(); + } else { + newText = directive + text; + } if (!newText.equals(text)) { System.err.println("\"" + directive + "\" was added to \"" + testDataFile + "\""); diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 index c0ed2433d4a..b57a877c3fe 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as31 @@ -1060,8 +1060,25 @@ public class KotlinTestUtils { if (!isIgnored && AUTOMATICALLY_MUTE_FAILED_TESTS) { String text = doLoadFile(testDataFile); - String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name(); - String newText = directive + "\n" + text; + String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name() + "\n"; + + String newText; + if (text.startsWith("// !")) { + StringBuilder prefixBuilder = new StringBuilder(); + int l = 0; + while (text.startsWith("// !", l)) { + int r = text.indexOf("\n", l) + 1; + if (r <= 0) r = text.length(); + prefixBuilder.append(text.substring(l, r)); + l = r; + } + prefixBuilder.append(directive); + prefixBuilder.append(text.substring(l)); + + newText = prefixBuilder.toString(); + } else { + newText = directive + text; + } if (!newText.equals(text)) { System.err.println("\"" + directive + "\" was added to \"" + testDataFile + "\""); diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 index 2cab28f4256..3fc0ff51cbb 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java.as32 @@ -1060,8 +1060,25 @@ public class KotlinTestUtils { if (!isIgnored && AUTOMATICALLY_MUTE_FAILED_TESTS) { String text = doLoadFile(testDataFile); - String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name(); - String newText = directive + "\n" + text; + String directive = InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX + targetBackend.name() + "\n"; + + String newText; + if (text.startsWith("// !")) { + StringBuilder prefixBuilder = new StringBuilder(); + int l = 0; + while (text.startsWith("// !", l)) { + int r = text.indexOf("\n", l) + 1; + if (r <= 0) r = text.length(); + prefixBuilder.append(text.substring(l, r)); + l = r; + } + prefixBuilder.append(directive); + prefixBuilder.append(text.substring(l)); + + newText = prefixBuilder.toString(); + } else { + newText = directive + text; + } if (!newText.equals(text)) { System.err.println("\"" + directive + "\" was added to \"" + testDataFile + "\"");