Skip to content

Commit

Permalink
Merge pull request #18625 from ebullient/cli-no-tests
Browse files Browse the repository at this point in the history
CLI: correct behavior of --tests and --no-tests
  • Loading branch information
ebullient authored Jul 12, 2021
2 parents 67aa114 + fef11c4 commit 498c3e1
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 11 deletions.
5 changes: 1 addition & 4 deletions devtools/cli/src/main/java/io/quarkus/cli/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ void dryRunBuild(CommandLine.Help help, BuildTool buildTool, BuildSystemRunner.B

@Override
public String toString() {
return "Build [clean=" + buildOptions.clean
+ ", buildNative=" + buildOptions.buildNative
+ ", offline=" + buildOptions.offline
+ ", runTests=" + buildOptions.runTests
return "Build [buildOptions=" + buildOptions
+ ", properties=" + propertiesOptions.properties
+ ", output=" + output
+ ", params=" + params + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ public BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption ru
if (buildOptions.buildNative) {
args.add("--native");
}
if (buildOptions.clean) {
args.add("--fresh");
}

args.add("build");
args.addAll(flattenMappedProperties(propertiesOptions.properties));
args.addAll(params);
args.add(getMainPath());
return prependExecutable(args);
Expand Down
13 changes: 10 additions & 3 deletions devtools/cli/src/main/java/io/quarkus/cli/common/BuildOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ public class BuildOptions {
@CommandLine.Option(order = 5, names = { "--offline" }, description = "Work offline.", defaultValue = "false")
public boolean offline = false;

@CommandLine.Option(order = 6, names = { "--tests" }, description = "Run tests.", negatable = true)
public boolean runTests = true;
@CommandLine.Option(order = 6, names = {
"--no-tests" }, description = "Run tests.", negatable = true, defaultValue = "false")
public boolean skipTests = false;

public boolean skipTests() {
return !runTests;
return skipTests;
}

@Override
public String toString() {
return "BuildOptions [buildNative=" + buildNative + ", clean=" + clean + ", offline=" + offline + ", skipTests="
+ skipTests + "]";
}
}
5 changes: 3 additions & 2 deletions devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,12 @@ public static Result invokeExtensionRemoveNonexistent(Path projectRoot) throws E
}

public static Result invokeValidateDryRunBuild(Path projectRoot) throws Exception {
Result result = execute(projectRoot, "build", "-e", "-B", "--clean", "--dryrun",
Result result = execute(projectRoot, "build", "-e", "-B", "--dryrun",
"-Dproperty=value1", "-Dproperty2=value2");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);
System.out.println(result.stdout);
Assertions.assertTrue(result.stdout.contains("Command line"),
"--dry-run should echo command line");
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@ public void testBuildOutsideOfProject() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "build", "-e");
Assertions.assertEquals(CommandLine.ExitCode.USAGE, result.exitCode,
"'quarkus build' should fail outside of a quarkus project directory:\n" + result);
System.out.println(result);
}

@Test
public void testDevOutsideOfProject() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "dev", "-e");
Assertions.assertEquals(CommandLine.ExitCode.USAGE, result.exitCode,
"'quarkus dev' should fail outside of a quarkus project directory:\n" + result);
System.out.println(result);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,47 @@ public void testExtensionList() throws Exception {
"Expected OK return code. Result:\n" + result);
}

@Test
public void testBuildOptions() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "--gradle", "-e", "-B", "--verbose");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);

// 1 --clean --tests --native --offline
result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
"--clean", "--tests", "--native", "--offline");

Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);

Assertions.assertTrue(result.stdout.contains(" clean"),
"gradle command should specify 'clean'\n" + result);

Assertions.assertFalse(result.stdout.contains("-x test"),
"gradle command should not specify '-x test'\n" + result);

Assertions.assertTrue(result.stdout.contains("-Dquarkus.package.type=native"),
"gradle command should specify -Dquarkus.package.type=native\n" + result);

Assertions.assertTrue(result.stdout.contains("--offline"),
"gradle command should specify --offline\n" + result);

// 2 --no-clean --no-tests
result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
"--no-clean", "--no-tests");

Assertions.assertFalse(result.stdout.contains(" clean"),
"gradle command should not specify 'clean'\n" + result);

Assertions.assertTrue(result.stdout.contains("-x test"),
"gradle command should specify '-x test'\n" + result);

Assertions.assertFalse(result.stdout.contains("native"),
"gradle command should not specify native\n" + result);

Assertions.assertFalse(result.stdout.contains("offline"),
"gradle command should not specify offline\n" + result);
}

@Test
public void testCreateArgPassthrough() throws Exception {
Path nested = workspaceRoot.resolve("cli-nested");
Expand Down
41 changes: 41 additions & 0 deletions devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public void testCreateAppDefaults() throws Exception {
"Generated source should reference resteasy. Found:\n" + source);

result = CliDriver.invokeValidateDryRunBuild(project);
Assertions.assertTrue(result.stdout.contains("-Dproperty=value1 -Dproperty2=value2"),
"result should contain '-Dproperty=value1 -Dproperty2=value2':\n" + result.stdout);

CliDriver.invokeValidateBuild(project);
}
Expand Down Expand Up @@ -113,6 +115,45 @@ public void testCreateCliDefaults() throws Exception {
"Expected OK return code. Result:\n" + result);
}

@Test
public void testBuildOptions() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "--jbang", "-e", "-B", "--verbose");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);

// 1 --clean --tests --native --offline
result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
"--clean", "--tests", "--native", "--offline");

Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);

Assertions.assertTrue(result.stdout.contains("--fresh"),
"jbang command should specify '--fresh'\n" + result);

// presently no support for --tests or --no-tests

Assertions.assertTrue(result.stdout.contains("--native"),
"jbang command should specify --native\n" + result);

Assertions.assertTrue(result.stdout.contains("--offline"),
"jbang command should specify --offline\n" + result);

// 2 --no-clean --no-tests
result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
"--no-clean", "--no-tests");

Assertions.assertFalse(result.stdout.contains("--fresh"),
"jbang command should not specify '--fresh'\n" + result);

// presently no support for --tests or --no-tests

Assertions.assertFalse(result.stdout.contains("native"),
"jbang command should not specify native\n" + result);

Assertions.assertFalse(result.stdout.contains("offline"),
"jbang command should not specify offline\n" + result);
}

void validateBasicIdentifiers(Path project, String group, String artifact, String version) throws Exception {
Assertions.assertTrue(project.resolve("README.md").toFile().exists(),
"README.md should exist: " + project.resolve("README.md").toAbsolutePath().toString());
Expand Down
44 changes: 44 additions & 0 deletions devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,50 @@ public void testExtensionList() throws Exception {
"Expected error return code. Result:\n" + result);
}

@Test
public void testBuildOptions() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "-e", "-B", "--verbose");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);

// 1 --clean --tests --native --offline
result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
"--clean", "--tests", "--native", "--offline");
Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
"Expected OK return code. Result:\n" + result);

Assertions.assertTrue(result.stdout.contains(" clean"),
"mvn command should specify 'clean'\n" + result);

Assertions.assertFalse(result.stdout.contains("-DskipTests"),
"mvn command should not specify -DskipTests\n" + result);
Assertions.assertFalse(result.stdout.contains("-Dmaven.test.skip=true"),
"mvn command should not specify -Dmaven.test.skip=true\n" + result);

Assertions.assertTrue(result.stdout.contains("-Dnative"),
"mvn command should specify -Dnative\n" + result);

Assertions.assertTrue(result.stdout.contains("--offline"),
"mvn command should specify --offline\n" + result);

// 2 --no-clean --no-tests
result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
"--no-clean", "--no-tests");

Assertions.assertFalse(result.stdout.contains(" clean"),
"mvn command should not specify 'clean'\n" + result);

Assertions.assertTrue(result.stdout.contains("-DskipTests"),
"mvn command should specify -DskipTests\n" + result);
Assertions.assertTrue(result.stdout.contains("-Dmaven.test.skip=true"),
"mvn command should specify -Dmaven.test.skip=true\n" + result);

Assertions.assertFalse(result.stdout.contains("-Dnative"),
"mvn command should not specify -Dnative\n" + result);

Assertions.assertFalse(result.stdout.contains("--offline"),
"mvn command should not specify --offline\n" + result);
}

@Test
public void testCreateCliDefaults() throws Exception {
CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "cli", "-e", "-B", "--verbose");
Expand Down

0 comments on commit 498c3e1

Please sign in to comment.