Skip to content

Commit

Permalink
Improve mvn quarkus:test output
Browse files Browse the repository at this point in the history
- Display test output by default
- Display banner if configured
  • Loading branch information
stuartwdouglas committed Jun 10, 2021
1 parent 4ecac27 commit 14ca92c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.quarkus.bootstrap.app.AugmentAction;
import io.quarkus.bootstrap.app.CuratedApplication;
import io.quarkus.bootstrap.runner.Timing;
import io.quarkus.deployment.builditem.ConsoleFormatterBannerBuildItem;
import io.quarkus.deployment.dev.testing.TestHandler;
import io.quarkus.deployment.dev.testing.TestSetupBuildItem;
import io.quarkus.deployment.dev.testing.TestSupport;
Expand All @@ -25,7 +26,6 @@
import io.quarkus.dev.spi.DevModeType;
import io.quarkus.dev.spi.HotReplacementSetup;
import io.quarkus.runner.bootstrap.AugmentActionImpl;
import io.quarkus.runtime.logging.LoggingSetupRecorder;

/**
* The main entry point of quarkus:test
Expand All @@ -41,6 +41,7 @@ public class IsolatedTestModeMain extends IsolatedDevModeMain {

private RuntimeUpdatesProcessor setupRuntimeCompilation(DevModeContext context, Path applicationRoot)
throws Exception {
System.setProperty("quarkus.test.display-test-output", "true");
if (!context.getAllModules().isEmpty()) {
ServiceLoader<CompilationProvider> serviceLoader = ServiceLoader.load(CompilationProvider.class);
List<CompilationProvider> compilationProviders = new ArrayList<>();
Expand Down Expand Up @@ -125,16 +126,13 @@ public void accept(CuratedApplication o, Map<String, Object> params) {
}
try {
augmentAction.performCustomBuild(TestHandler.class.getName(), null, TestSetupBuildItem.class.getName(),
LoggingSetupBuildItem.class.getName());
LoggingSetupBuildItem.class.getName(), ConsoleFormatterBannerBuildItem.class.getName());
} catch (Throwable t) {
//logging may not have been started, this is more reliable
System.err.println("Failed to start quarkus test mode");
t.printStackTrace();
System.exit(1);
}
//we don't actually start the app
//so logging would not be enabled
LoggingSetupRecorder.handleFailedStart();

Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,32 @@

import java.util.function.BiConsumer;

import org.jboss.logging.Logger;

import io.quarkus.banner.BannerConfig;
import io.quarkus.builder.BuildResult;
import io.quarkus.deployment.steps.BannerProcessor;
import io.quarkus.dev.console.QuarkusConsole;
import io.quarkus.runtime.BannerRecorder;
import io.quarkus.runtime.BannerRuntimeConfig;
import io.quarkus.runtime.configuration.ConfigInstantiator;
import io.quarkus.runtime.logging.LoggingSetupRecorder;

public class TestHandler implements BiConsumer<Object, BuildResult> {
@Override
public void accept(Object o, BuildResult buildResult) {
QuarkusConsole.start();
TestSupport.instance().get().start();

//we don't actually start the app
//so logging would not be enabled
BannerConfig bannerConfig = new BannerConfig();
BannerRuntimeConfig bannerRuntimeConfig = new BannerRuntimeConfig();
ConfigInstantiator.handleObject(bannerConfig);
ConfigInstantiator.handleObject(bannerRuntimeConfig);
LoggingSetupRecorder.handleFailedStart(new BannerProcessor()
.recordBanner(new BannerRecorder(), bannerConfig, bannerRuntimeConfig).getBannerSupplier());
Logger.getLogger("io.quarkus.test").info("Quarkus continuous testing mode started");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ public LoggingSetupRecorder() {

@SuppressWarnings("unused") //called via reflection, as it is in an isolated CL
public static void handleFailedStart() {
handleFailedStart(new RuntimeValue<>(Optional.empty()));
}

public static void handleFailedStart(RuntimeValue<Optional<Supplier<String>>> banner) {
LogConfig config = new LogConfig();
ConfigInstantiator.handleObject(config);
LogBuildTimeConfig buildConfig = new LogBuildTimeConfig();
ConfigInstantiator.handleObject(buildConfig);
new LoggingSetupRecorder().initializeLogging(config, buildConfig, Collections.emptyList(), Collections.emptyList(),
Collections.emptyList(), null);
Collections.emptyList(), banner);
}

public void initializeLogging(LogConfig config, LogBuildTimeConfig buildConfig,
Expand Down

0 comments on commit 14ca92c

Please sign in to comment.