Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#37: Encapsulate command line options parser
- Loading branch information
1 parent
79c6f9f
commit 6c9d0a5
Showing
5 changed files
with
213 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
junit-console/src/main/java/org/junit/gen5/console/options/AirlineCommandLineOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,93 @@ | |||
/* | |||
* Copyright 2015 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|||
package org.junit.gen5.console.options; | |||
|
|||
import java.util.List; | |||
|
|||
import io.airlift.airline.Arguments; | |||
import io.airlift.airline.Command; | |||
import io.airlift.airline.Option; | |||
|
|||
@Command(name = "ConsoleRunner", description = "console test runner") | |||
public class AirlineCommandLineOptions implements CommandLineOptions { | |||
|
|||
// @formatter:off | |||
@Option(name = {"-h", "--help"}, description = "Display help information") | |||
private boolean displayHelp; | |||
|
|||
@Option(name = { "-x", "--enable-exit-code" }, | |||
description = "Exit process with number of failing tests as exit code") | |||
private boolean exitCodeEnabled; | |||
|
|||
@Option(name = { "-C", "--disable-ansi-colors" }, | |||
description = "Disable colored output (not supported by all terminals)") | |||
private boolean ansiColorOutputDisabled; | |||
|
|||
@Option(name = {"-a", "--all"}, description = "Run all tests") | |||
private boolean runAllTests; | |||
|
|||
@Option(name = {"-D", "--hide-details"}, description = "Hide details while tests are being executed. " | |||
+ "Only show the summary and test failures.") | |||
private boolean hideDetails; | |||
|
|||
@Option(name = {"-n", "--filter-classname"}, description = "Give a regular expression to include only classes whose fully qualified names match.") | |||
private String classnameFilter; | |||
|
|||
@Option(name = {"-t", "--filter-tags"}, description = "Give a tag to include in the test run. This option can be repeated.") | |||
private List<String> tagsFilter; | |||
|
|||
@Arguments(description = "Test classes, methods or packages to execute." | |||
+ " If --all|-a has been chosen, arguments can list all classpath roots that should be considered for test scanning," | |||
+ " or none if the full classpath shall be scanned.") | |||
private List<String> arguments; | |||
// @formatter:on | |||
|
|||
@Override | |||
public boolean isDisplayHelp() { | |||
return displayHelp; | |||
} | |||
|
|||
@Override | |||
public boolean isExitCodeEnabled() { | |||
return exitCodeEnabled; | |||
} | |||
|
|||
@Override | |||
public boolean isAnsiColorOutputDisabled() { | |||
return ansiColorOutputDisabled; | |||
} | |||
|
|||
@Override | |||
public boolean isRunAllTests() { | |||
return runAllTests; | |||
} | |||
|
|||
@Override | |||
public boolean isHideDetails() { | |||
return hideDetails; | |||
} | |||
|
|||
@Override | |||
public String getClassnameFilter() { | |||
return classnameFilter; | |||
} | |||
|
|||
@Override | |||
public List<String> getTagsFilter() { | |||
return tagsFilter; | |||
} | |||
|
|||
@Override | |||
public List<String> getArguments() { | |||
return arguments; | |||
} | |||
|
|||
} |
29 changes: 29 additions & 0 deletions
29
...console/src/main/java/org/junit/gen5/console/options/AirlineCommandLineOptionsParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
/* | |||
* Copyright 2015 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|||
package org.junit.gen5.console.options; | |||
|
|||
import static io.airlift.airline.Help.help; | |||
import static io.airlift.airline.SingleCommand.singleCommand; | |||
import static io.airlift.airline.model.MetadataLoader.loadCommand; | |||
|
|||
public class AirlineCommandLineOptionsParser implements CommandLineOptionsParser { | |||
|
|||
@Override | |||
public CommandLineOptions parse(String... arguments) { | |||
return singleCommand(AirlineCommandLineOptions.class).parse(arguments); | |||
} | |||
|
|||
@Override | |||
public void printHelp() { | |||
help(loadCommand(AirlineCommandLineOptions.class)); | |||
} | |||
|
|||
} |
33 changes: 33 additions & 0 deletions
33
junit-console/src/main/java/org/junit/gen5/console/options/CommandLineOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,33 @@ | |||
/* | |||
* Copyright 2015 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|||
package org.junit.gen5.console.options; | |||
|
|||
import java.util.List; | |||
|
|||
public interface CommandLineOptions { | |||
|
|||
boolean isDisplayHelp(); | |||
|
|||
boolean isExitCodeEnabled(); | |||
|
|||
boolean isAnsiColorOutputDisabled(); | |||
|
|||
boolean isRunAllTests(); | |||
|
|||
boolean isHideDetails(); | |||
|
|||
String getClassnameFilter(); | |||
|
|||
List<String> getTagsFilter(); | |||
|
|||
List<String> getArguments(); | |||
|
|||
} |
19 changes: 19 additions & 0 deletions
19
junit-console/src/main/java/org/junit/gen5/console/options/CommandLineOptionsParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
/* | |||
* Copyright 2015 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|||
package org.junit.gen5.console.options; | |||
|
|||
public interface CommandLineOptionsParser { | |||
|
|||
CommandLineOptions parse(String... arguments); | |||
|
|||
void printHelp(); | |||
|
|||
} |