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 + "\"");