Skip to content

Commit

Permalink
Add test for second pass command line passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-l-teichmann committed Sep 25, 2023
1 parent 6229021 commit abce4e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/options/data/empty.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty but valid config file
21 changes: 20 additions & 1 deletion internal/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}

0 comments on commit abce4e7

Please sign in to comment.