Skip to content

Commit

Permalink
Improve continuous test/dev mode output
Browse files Browse the repository at this point in the history
- Fix output if no tests run
- Display time test were run
- Remove compiling log message, replace with message for test/dev mode
  restart with changed classes.
- Don't count skipped tests towards the number run
  • Loading branch information
stuartwdouglas committed Jun 9, 2021
1 parent 0e7f21d commit 00aaed5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,17 @@ public boolean doScan(boolean userInitiated, boolean force) throws IOException {
boolean configFileRestartNeeded = filesChanged.stream().map(main.watchedFilePaths::get)
.anyMatch(Boolean.TRUE::equals);
boolean instrumentationChange = false;

List<Path> changedFilesForRestart = new ArrayList<>();
if (configFileRestartNeeded) {
changedFilesForRestart
.addAll(filesChanged.stream().filter(fn -> Boolean.TRUE.equals(main.watchedFilePaths.get(fn)))
.map(Paths::get).collect(Collectors.toList()));
}
changedFilesForRestart.addAll(changedClassResults.getChangedClasses());
changedFilesForRestart.addAll(changedClassResults.getAddedClasses());
changedFilesForRestart.addAll(changedClassResults.getDeletedClasses());

if (ClassChangeAgent.getInstrumentation() != null && lastStartIndex != null && !configFileRestartNeeded
&& devModeType != DevModeType.REMOTE_LOCAL_SIDE) {
//attempt to do an instrumentation based reload
Expand Down Expand Up @@ -428,6 +439,9 @@ public boolean doScan(boolean userInitiated, boolean force) throws IOException {
boolean restartNeeded = !instrumentationChange && (changedClassResults.isChanged()
|| (IsolatedDevModeMain.deploymentProblem != null && userInitiated) || configFileRestartNeeded);
if (restartNeeded) {
String changeString = changedFilesForRestart.stream().map(Path::getFileName).map(Object::toString)
.collect(Collectors.joining(", ")) + ".";
log.infof("Restarting quarkus due to changes in " + changeString);
restartCallback.accept(filesChanged, changedClassResults);
long timeNanoSeconds = System.nanoTime() - startNanoseconds;
log.infof("Live reload total time: %ss ", Timing.convertToBigDecimalSeconds(timeNanoSeconds));
Expand Down Expand Up @@ -574,8 +588,6 @@ && sourceFileWasRecentModified(p, ignoreFirstScanChanges))
}
if (!changedSourceFiles.isEmpty()) {
classScanResult.compilationHappened = true;
log.info("Changed source files detected, recompiling "
+ changedSourceFiles.stream().map(File::getName).collect(Collectors.joining(", ")));
//so this is pretty yuck, but on a lot of systems a write is actually a truncate + write
//its possible we see the truncated file timestamp, then the write updates the timestamp
//which will then re-trigger continuous testing/live reload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import static io.quarkus.deployment.dev.testing.TestConsoleHandler.MessageFormat.helpOption;
import static io.quarkus.deployment.dev.testing.TestConsoleHandler.MessageFormat.statusFooter;
import static io.quarkus.deployment.dev.testing.TestConsoleHandler.MessageFormat.statusHeader;
import static io.quarkus.deployment.dev.testing.TestConsoleHandler.MessageFormat.toggleStatus;

import java.io.IOException;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;

Expand All @@ -19,6 +23,7 @@
import org.junit.platform.launcher.TestIdentifier;

import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.dev.ClassScanResult;
import io.quarkus.deployment.dev.RuntimeUpdatesProcessor;
import io.quarkus.dev.console.InputHandler;
import io.quarkus.dev.console.QuarkusConsole;
Expand Down Expand Up @@ -165,16 +170,37 @@ public void testComplete(TestResult result) {
@Override
public void runComplete(TestRunResults results) {
firstRun = false;
if (results.getCurrentTotalCount() == 0) {
SimpleDateFormat df = new SimpleDateFormat("kk:mm:ss");

String end = " Tests completed at " + df.format(new Date());
if (results.getTrigger() != null) {
ClassScanResult trigger = results.getTrigger();
Set<Path> paths = new LinkedHashSet<>();
paths.addAll(trigger.getChangedClasses());
paths.addAll(trigger.getAddedClasses());
paths.addAll(trigger.getDeletedClasses());
if (paths.size() == 1) {
end = end + " due to changes to " + paths.iterator().next().getFileName() + ".";
} else if (paths.size() > 1) {
end = end + " due to changes to " + paths.iterator().next().getFileName() + " and " + (paths.size() - 1)
+ " other files.";
} else {
//should never happen
end = end + ".";
}
} else {
end = end + ".";
}
if (results.getTotalCount() == 0) {
lastStatus = YELLOW + "No tests found" + RESET;
} else if (results.getFailedCount() == 0 && results.getPassedCount() == 0) {
lastStatus = String.format(YELLOW + "All %d tests were skipped" + RESET, results.getSkippedCount());
} else if (results.getCurrentFailing().isEmpty()) {
lastStatus = String.format(
GREEN + "All %d tests are passing (%d skipped), %d tests were run in %dms." + RESET,
GREEN + "All %d tests are passing (%d skipped), %d tests were run in %dms." + end + RESET,
results.getPassedCount(),
results.getSkippedCount(),
results.getCurrentTotalCount(), results.getTotalTime());
results.getCurrentTotalCount() - results.getSkippedCount(), results.getTotalTime());
} else {
//TODO: this should not use the logger, it should print a nicer status
log.error(statusHeader("TEST REPORT #" + results.getId()));
Expand All @@ -189,7 +215,7 @@ public void runComplete(TestRunResults results) {
statusFooter(RED + results.getCurrentFailedCount() + " TESTS FAILED"));
lastStatus = String.format(
RED + "%d tests failed" + RESET + " (" + GREEN + "%d passing" + RESET + ", " + YELLOW + "%d skipped"
+ RESET + "), %d tests were run in %dms." + RESET,
+ RESET + "), %d tests were run in %dms." + end + RESET,
results.getCurrentFailedCount(), results.getPassedCount(), results.getSkippedCount(),
results.getCurrentTotalCount(), results.getTotalTime());
}
Expand All @@ -200,10 +226,7 @@ public void runComplete(TestRunResults results) {

@Override
public void noTests(TestRunResults results) {
firstRun = false;
lastStatus = "No tests to run";
promptHandler.setStatus(lastStatus);
promptHandler.setPrompt(RUNNING_PROMPT);
runComplete(results);
}

@Override
Expand Down

0 comments on commit 00aaed5

Please sign in to comment.