Skip to content

Commit

Permalink
Maven test utils: Regexp accounts for terminal colours
Browse files Browse the repository at this point in the history
Fixes 31689
  • Loading branch information
Karm committed Mar 8, 2023
1 parent d213830 commit d60fc26
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ private QuarkusDevModeLauncher newLauncher() throws Exception {
.debugPort(System.getProperty("debugPort"))
.suspend(System.getProperty("suspend"));
if (System.getProperty(IO_QUARKUS_DEVMODE_ARGS) == null) {
builder.jvmArgs("-Dquarkus.test.basic-console=true")
builder.jvmArgs("-Dquarkus.console.basic=true")
.jvmArgs("-Dio.quarkus.force-color-support=true");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class IDELauncherImpl implements Closeable {

public static Closeable launch(Path classesDir, Map<String, Object> context) {
System.setProperty(FORCE_COLOR_SUPPORT, "true");
System.setProperty("quarkus.test.basic-console", "true"); //IDE's don't support raw mode
System.setProperty("quarkus.console.basic", "true"); //IDE's don't support raw mode
final Path projectDir = BuildToolHelper.getProjectDir(classesDir);
if (projectDir == null) {
throw new IllegalStateException("Failed to locate project dir for " + classesDir);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#quarkus.test.continuous-testing=enabled
#quarkus.test.basic-console=true
#quarkus.console.basic=true
quarkus.live-reload.instrumentation=false
greeting=hello
greeting=hello

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
greeting=bonjour
quarkus.test.continuous-testing=enabled
quarkus.test.basic-console=true
quarkus.console.basic=true

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Boolean call() throws Exception {
}

public static String appProperties(String... props) {
return "quarkus.test.continuous-testing=enabled\nquarkus.test.display-test-output=true\nquarkus.test.basic-console=true\nquarkus.test.disable-console-input=true\n"
return "quarkus.test.continuous-testing=enabled\nquarkus.test.display-test-output=true\nquarkus.console.basic=true\nquarkus.test.disable-console-input=true\n"
+ String.join("\n", Arrays.asList(props));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Boolean call() throws Exception {
}

public static String appProperties(String... props) {
return "quarkus.test.continuous-testing=enabled\nquarkus.test.display-test-output=true\nquarkus.test.basic-console=true\nquarkus.test.disable-console-input=true\n"
return "quarkus.test.continuous-testing=enabled\nquarkus.test.display-test-output=true\nquarkus.console.basic=true\nquarkus.test.disable-console-input=true\n"
+ String.join("\n", Arrays.asList(props));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -18,10 +22,16 @@ public class TestModeContinuousTestingMavenTestUtils extends ContinuousTestingMa
// Example output we look for
// 1 test failed (1 passing, 0 skipped), 1 test was run in 217ms. Tests completed at 21:22:34 due to changes to HelloResource$Blah.class and 1 other files.
// All 2 tests are passing (0 skipped), 2 tests were run in 1413ms. Tests completed at 21:22:33.
private static final Pattern ALL_PASSING = Pattern.compile("All (\\d\\d*) tests are passing \\((\\d\\d*) skipped\\)",
// Windows log, despite `quarkus.console.basic=true', might contain terminal control symbols, colour decorations.
// e.g. the matcher is then fighting: 1 test failed (1 passing, 0 skipped)
private static final Pattern ALL_PASSING = Pattern.compile(
"(?:\\e\\[[\\d;]+m)*All (\\d+) tests are passing \\((\\d+) skipped\\)",
Pattern.MULTILINE);
private static final Pattern SOME_PASSING = Pattern
.compile("(\\d\\d*) tests? failed \\((\\d\\d*) passing, (\\d\\d*) skipped\\)", Pattern.MULTILINE);
.compile(
"(?:\\e\\[[\\d;]+m)*(\\d+) tests? failed(?:\\e\\[[\\d;]+m)* \\((?:\\e\\[[\\d;]+m)*(\\d+) " +
"passing(?:\\e\\[[\\d;]+m)*, (?:\\e\\[[\\d;]+m)*(\\d+) skipped(?:\\e\\[[\\d;]+m)*\\)",
Pattern.MULTILINE);
private static final String TESTS_COMPLETED = "Tests completed at";
private final RunningInvoker running;
private int startPosition = 0;
Expand All @@ -39,7 +49,7 @@ public TestStatus waitForNextCompletion() {
.atMost(3, TimeUnit.MINUTES).until(() -> getLogSinceLastRun().contains(TESTS_COMPLETED));
TestStatus testStatus = new TestStatus();
try {
String log = getLogSinceLastRun();
final String log = getLogSinceLastRun();

Matcher matcher = ALL_PASSING.matcher(log);
int failCount;
Expand All @@ -52,7 +62,15 @@ public TestStatus waitForNextCompletion() {
} else {
matcher = SOME_PASSING.matcher(log);
if (!matcher.find()) {
fail("Tests were run, but the log is not parseable with the patterns we know. This is the log\n: " + log);
final Path f = File.createTempFile("quarkus-maven-test-debug-log", ".txt").toPath();
Files.writeString(f, log, StandardCharsets.UTF_8);
fail("Tests were run, but the log is not parseable with the patterns we know, " + System.lineSeparator()
+ "i.e. neither \"" + ALL_PASSING.pattern() + "\" nor \"" + SOME_PASSING.pattern() + "\"."
+ System.lineSeparator() +
" Note that possible terminal control characters might not be seen here. " + System.lineSeparator()
+
"Check the text file dump too: " + f.toAbsolutePath() + ". This is the log:"
+ System.lineSeparator() + log);
}
failCount = Integer.parseInt(matcher.group(1));
passCount = Integer.parseInt(matcher.group(2));
Expand Down

0 comments on commit d60fc26

Please sign in to comment.