Skip to content

Commit

Permalink
Merge pull request #35311 from mkouba/issue-35290
Browse files Browse the repository at this point in the history
CLI: test command updates
  • Loading branch information
ebullient authored Aug 10, 2023
2 parents 9c73946 + 43abc6c commit c43f0bd
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 4 deletions.
34 changes: 31 additions & 3 deletions devtools/cli/src/main/java/io/quarkus/cli/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

import io.quarkus.cli.build.BaseBuildCommand;
import io.quarkus.cli.build.BuildSystemRunner;
import io.quarkus.cli.build.BuildSystemRunner.BuildCommandArgs;
import io.quarkus.cli.common.BuildOptions;
import io.quarkus.cli.common.DebugOptions;
import io.quarkus.cli.common.DevOptions;
import io.quarkus.cli.common.RunModeOption;
import io.quarkus.devtools.project.BuildTool;
import picocli.CommandLine;
import picocli.CommandLine.Parameters;
Expand All @@ -24,6 +27,14 @@ public class Test extends BaseBuildCommand implements Callable<Integer> {
@CommandLine.ArgGroup(order = 3, exclusive = false, validate = true, heading = "%nDebug options:%n")
DebugOptions debugOptions = new DebugOptions();

@CommandLine.Option(names = "--once", description = "Run the test suite with continuous mode disabled.")
boolean runOnce = false;

@CommandLine.Option(names = "--filter", description = { "Run a subset of the test suite that matches the given filter.",
"If continuous testing is enabled then the value is a regular expression that is matched against the test class name.",
"If continuous testing is disabled then the value is passed as-is to the underlying build tool." })
String filter;

@Parameters(description = "Parameters passed to the application.")
List<String> params = new ArrayList<>();

Expand All @@ -34,11 +45,28 @@ public Integer call() {
output.throwIfUnmatchedArguments(spec.commandLine());

BuildSystemRunner runner = getRunner();

if (runOnce) {
BuildOptions buildOptions = new BuildOptions();
buildOptions.clean = testOptions.clean;
buildOptions.offline = testOptions.offline;
buildOptions.skipTests = !testOptions.runTests;
BuildCommandArgs commandArgs = runner.prepareTest(buildOptions, new RunModeOption(), params, filter);
if (testOptions.isDryRun()) {
dryRunTest(spec.commandLine().getHelp(), runner.getBuildTool(), commandArgs, false);
return CommandLine.ExitCode.OK;
}
return runner.run(commandArgs);
}

if (filter != null) {
params.add("-Dquarkus.test.include-pattern=" + filter);
}
List<Supplier<BuildSystemRunner.BuildCommandArgs>> commandArgs = runner.prepareDevTestMode(
false, testOptions, debugOptions, params);

if (testOptions.isDryRun()) {
dryRunTest(spec.commandLine().getHelp(), runner.getBuildTool(), commandArgs.iterator().next().get());
dryRunTest(spec.commandLine().getHelp(), runner.getBuildTool(), commandArgs.iterator().next().get(), true);
return CommandLine.ExitCode.OK;
}
int ret = 1;
Expand All @@ -55,8 +83,8 @@ public Integer call() {
}
}

void dryRunTest(CommandLine.Help help, BuildTool buildTool, BuildSystemRunner.BuildCommandArgs args) {
output.printText("\nRun current project in test mode\n",
void dryRunTest(CommandLine.Help help, BuildTool buildTool, BuildSystemRunner.BuildCommandArgs args, boolean isContinuous) {
output.printText("\nRun current project in" + (isContinuous ? " continuous" : "") + " test mode\n",
"\t" + projectRoot().toString());
Map<String, String> dryRunOutput = new TreeMap<>();
dryRunOutput.put("Build tool", buildTool.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Integer updateProject(TargetQuarkusVersionGroup targetQuarkusVersion, RewriteGro

BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption runMode, List<String> params);

BuildCommandArgs prepareTest(BuildOptions buildOptions, RunModeOption runMode, List<String> params, String filter);

List<Supplier<BuildCommandArgs>> prepareDevTestMode(boolean devMode, DevOptions commonOptions,
DebugOptions debugOptions, List<String> params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ public BuildCommandArgs prepareAction(String action, BuildOptions buildOptions,
return prependExecutable(args);
}

@Override
public BuildCommandArgs prepareTest(BuildOptions buildOptions, RunModeOption runMode, List<String> params, String filter) {
if (filter != null) {
params.add("--tests " + filter);
}
return prepareAction("test", buildOptions, runMode, params);
}

@Override
public List<Supplier<BuildCommandArgs>> prepareDevTestMode(boolean devMode, DevOptions commonOptions,
DebugOptions debugOptions, List<String> params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption ru
return prepareAction("build", buildOptions, runMode, params);
}

@Override
public BuildCommandArgs prepareTest(BuildOptions buildOptions, RunModeOption runMode, List<String> params, String filter) {
throw new UnsupportedOperationException("Not there yet. ;)");
}

@Override
public List<Supplier<BuildCommandArgs>> prepareDevTestMode(boolean devMode, DevOptions commonOptions,
DebugOptions debugOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ public BuildCommandArgs prepareAction(String action, BuildOptions buildOptions,
return prependExecutable(args);
}

@Override
public BuildCommandArgs prepareTest(BuildOptions buildOptions, RunModeOption runMode, List<String> params, String filter) {
if (filter != null) {
params.add("-Dtest=" + filter);
}
return prepareAction("test", buildOptions, runMode, params);
}

@Override
public List<Supplier<BuildCommandArgs>> prepareDevTestMode(boolean devMode, DevOptions commonOptions,
DebugOptions debugOptions, List<String> params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,22 @@ public void testDevOptions() throws Exception {

Assertions.assertTrue(result.stdout.contains("-Dquarkus.args='arg1 arg2'"),
"gradle command should not specify -Dquarkus.args='arg1 arg2'\n" + result);

// 4 TEST MODE: test --clean --debug --suspend --offline
result = CliDriver.execute(project, "test", "-e", "--dry-run",
"--clean", "--debug", "--suspend", "--debug-mode=listen", "--offline", "--filter=FooTest");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
Assertions.assertTrue(result.stdout.contains("Run current project in continuous test mode"), result.toString());
Assertions.assertTrue(result.stdout.contains("-Dquarkus.test.include-pattern=FooTest"), result.toString());

// 5 TEST MODE - run once: test --once --offline
result = CliDriver.execute(project, "test", "-e", "--dry-run",
"--once", "--offline", "--filter=FooTest");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
Assertions.assertTrue(result.stdout.contains("Run current project in test mode"), result.toString());
Assertions.assertTrue(result.stdout.contains("--tests FooTest"), result.toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,19 @@ public void testDevTestOptions() throws Exception {

// 4 TEST MODE: test --clean --debug --suspend --offline
result = CliDriver.execute(project, "test", "-e", "--dry-run",
"--clean", "--debug", "--suspend", "--debug-mode=listen", "--offline");
"--clean", "--debug", "--suspend", "--debug-mode=listen", "--offline", "--filter=FooTest");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
Assertions.assertTrue(result.stdout.contains("Run current project in continuous test mode"), result.toString());
Assertions.assertTrue(result.stdout.contains("-Dquarkus.test.include-pattern=FooTest"), result.toString());

// 5 TEST MODE - run once: test --once --offline
result = CliDriver.execute(project, "test", "-e", "--dry-run",
"--once", "--offline", "--filter=FooTest");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
Assertions.assertTrue(result.stdout.contains("Run current project in test mode"), result.toString());
Assertions.assertTrue(result.stdout.contains("-Dtest=FooTest"), result.toString());
}

@Test
Expand Down

0 comments on commit c43f0bd

Please sign in to comment.