DoTest (DoTest test, TargetBackend targetBackend, String ignoreDirective, TestCase testCase) { return filePath -> { File testDataFile = new File(filePath); boolean isIgnored = isIgnoredTarget(targetBackend, testDataFile, ignoreDirective); if (DONT_IGNORE_TESTS_WORKING_ON_COMPATIBLE_BACKEND) { // Only ignore if it is ignored for both backends // Motivation: this backend works => all good, even if compatible backend fails // This backend fails, compatible works => need to know isIgnored &= isIgnoredTarget(targetBackend.getCompatibleWith(), testDataFile); } try { test.invoke(filePath); } catch (Throwable e) { if (!isIgnored && AUTOMATICALLY_MUTE_FAILED_TESTS) { String text = doLoadFile(testDataFile); String directive = ignoreDirective + 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, 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 + "\""); FileUtil.writeToFile(testDataFile, newText); } } if (RUN_IGNORED_TESTS_AS_REGULAR || !isIgnored) { throw e; } if (PRINT_STACKTRACE_FOR_IGNORED_TESTS) { e.printStackTrace(); } else { System.err.println("MUTED TEST with `" + ignoreDirective + "`"); } return; } if (isIgnored) { if (testCase instanceof IgnorableTestCase ignorableTestCase) { ignorableTestCase.setIgnoreIsPassedCallback(() -> { processIgnoreIsPassed(targetBackend, ignoreDirective, testDataFile); return null; }); return; } processIgnoreIsPassed(targetBackend, ignoreDirective, testDataFile); } }; }