diff --git a/internal/options/data/empty.toml b/internal/options/data/empty.toml new file mode 100644 index 0000000..b852bc0 --- /dev/null +++ b/internal/options/data/empty.toml @@ -0,0 +1 @@ +# Empty but valid config file diff --git a/internal/options/options_test.go b/internal/options/options_test.go index 200ffa6..93b7b3f 100644 --- a/internal/options/options_test.go +++ b/internal/options/options_test.go @@ -14,7 +14,7 @@ type config struct { ConfigLocation string `long:"configlocation" description:"test location"` } -// Parser helps parsing command line arguments and loading +// TestParse helps parsing command line arguments and loading // stored configurations from file. func TestParse(t *testing.T) { originalArgs := os.Args @@ -152,3 +152,22 @@ func TestErrorCheck(t *testing.T) { t.Fatalf("process ran with err %v, want exit status 1", err) } + +// TestSecondPassCommandlineParsing checks if the second pass +// of the command line passing is error checked. +func TestSecondPassCommandlineParsing(t *testing.T) { + orig := os.Args + defer func() { os.Args = orig }() + + os.Args = []string{"cmd"} + p := Parser[config]{ + ConfigLocation: func(cfg *config) string { + // This is a bit stupid. + os.Args = []string{"cmd", "--invalid"} + return "data/empty.toml" + }, + } + if _, _, err := p.Parse(); err == nil { + t.Fatalf("Second command line parsing pass did not fail.\n") + } +}