Skip to content

Commit 56806ee

Browse files
committed
main.go: Non-zero -list exit (fix oz#70)
1 parent 75be867 commit 56806ee

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

main.go

+5
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ func parseMainArgs() *model {
236236
q = arg
237237
}
238238
results := SearchZones(strings.ToLower(q))
239+
if len(results) < 1 {
240+
fmt.Fprintf(os.Stderr(), "Unknown time zone %s\n", q)
241+
os.Exit(3)
242+
return nil
243+
}
239244
results.Print(os.Stdout())
240245
os.Exit(0)
241246
return nil

main_test.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,21 @@ func TestMainArgList(t *testing.T) {
258258
}
259259

260260
osWrapper.Setargs([]string{"-list", "!"})
261-
expectedOutput := "Unknown time zone !"
261+
expectedErrOutput := "Unknown time zone !"
262262
parseMainArgsWithPanicRecovery(&err)
263263
if err != nil {
264-
t.Errorf("Unexpected failure for -list flag: %v", err)
264+
t.Errorf("Unexpected failure for `-list !` flag: %v", err)
265265
}
266266
if osWrapper.ExitCode == nil {
267-
t.Error("Main -list should exit, but did not")
267+
t.Error("Main `-list !` should exit, but did not")
268268
} else if *osWrapper.ExitCode != 3 {
269-
t.Errorf("Main -list should exit with code 3, but got %v", *osWrapper.ExitCode)
269+
t.Errorf("Main `-list !` should exit with code 3, but got %v", *osWrapper.ExitCode)
270270
}
271-
if output := strings.TrimSpace(osWrapper.ConsumeStderr()); output != expectedOutput {
272-
t.Errorf("Main -list should have printed '%v', but got '%v'", expectedOutput, output)
271+
if errOutput := strings.TrimSpace(osWrapper.ConsumeStderr()); errOutput != expectedErrOutput {
272+
t.Errorf("Main `-list !` should have stderr '%v', but got '%v'", expectedErrOutput, errOutput)
273+
}
274+
if stdOutput := osWrapper.ConsumeStdout(); len(stdOutput) > 0 {
275+
t.Errorf("Main `-list !` should have empty stdout, but got '%v'", stdOutput)
273276
}
274277
}
275278

0 commit comments

Comments
 (0)