Skip to content

Commit 2337c3f

Browse files
tsiq-karoldMykolaGolubyev
authored andcommitted
correct exit criteria from cli
1 parent e51756c commit 2337c3f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

webtau-groovy/src/main/groovy/com/twosigma/webtau/cli/WebTauTestCliConfig.groovy

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ class WebTauTestCliConfig {
3131

3232
private WebTauConfig cfg = WebTauConfig.INSTANCE
3333

34+
private final ExitHandler exitHandler
35+
3436
private List<String> testFiles
3537
private String env
3638
private Path configPath
3739
private CommandLine commandLine
3840
private ConfigObject configObject
3941

4042
WebTauTestCliConfig(String... args) {
43+
this({ System.exit(it) }, args)
44+
}
45+
46+
WebTauTestCliConfig(ExitHandler exitHandler, String... args) {
47+
this.exitHandler = exitHandler
4148
parseArgs(args)
4249
}
4350

@@ -75,10 +82,11 @@ class WebTauTestCliConfig {
7582
Options options = createOptions()
7683
commandLine = createCommandLine(args, options)
7784

78-
if (commandLine.hasOption("help") || args.length < 1) {
85+
if (commandLine.hasOption("help") || commandLine.argList.isEmpty()) {
7986
HelpFormatter helpFormatter = new HelpFormatter()
8087
helpFormatter.printHelp("webtau [options] [testFile1] [testFile2]", options)
81-
System.exit(1)
88+
exitHandler.exit(1)
89+
return
8290
}
8391

8492
testFiles = new ArrayList<>(commandLine.argList)
@@ -115,4 +123,8 @@ class WebTauTestCliConfig {
115123
private Map commandLineArgsAsMap() {
116124
commandLine.options.collectEntries { [it.longOpt, it.value] }
117125
}
126+
127+
interface ExitHandler {
128+
void exit(int status)
129+
}
118130
}

webtau-groovy/src/test/groovy/com/twosigma/webtau/cli/WebTauTestCliConfigTest.groovy

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ class WebTauTestCliConfigTest {
2828

2929
@Test
3030
void "should use default environment values when evn is not specified"() {
31-
def cliConfig = new WebTauTestCliConfig("--config=src/test/resources/test.cfg")
31+
def cliConfig = new WebTauTestCliConfig("--config=src/test/resources/test.cfg", "testFile")
3232
cliConfig.parseConfig(groovy)
3333

3434
cfg.baseUrl.should == "http://localhost:8180"
3535
}
3636

3737
@Test
3838
void "should use environment specific values when evn is specified"() {
39-
def cliConfig = new WebTauTestCliConfig("--config=src/test/resources/test.cfg", "--env=dev")
39+
def cliConfig = new WebTauTestCliConfig("--config=src/test/resources/test.cfg", "--env=dev", "testFile")
4040
cliConfig.parseConfig(groovy)
4141

4242
cfg.baseUrl.should == "http://dev.host:8080"
4343
}
44+
45+
@Test
46+
void "should exit if only config file provided"() {
47+
Integer retCode
48+
new WebTauTestCliConfig({ retCode = it }, "--config=src/test/resources/test.cfg", "--env=dev")
49+
50+
retCode.should == 1
51+
}
4452
}

0 commit comments

Comments
 (0)