summaryrefslogtreecommitdiff
path: root/parse_test.go
diff options
context:
space:
mode:
authorHugo Hromic <[email protected]>2024-06-27 00:02:41 +0100
committerHugo Hromic <[email protected]>2024-06-27 00:33:09 +0100
commitaa844c7de9f0314b1fe66b9bdcc12090c7d0905e (patch)
treed0157b78d82c7667de1973da81e8d108b1ed509a /parse_test.go
parentdfca71d1594a749ef5e2203e84cfb5a1b8e9387b (diff)
Fix crash on errors in package-level `MustParse`
Diffstat (limited to 'parse_test.go')
-rw-r--r--parse_test.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/parse_test.go b/parse_test.go
index fe055fe..07af7ed 100644
--- a/parse_test.go
+++ b/parse_test.go
@@ -692,6 +692,21 @@ func TestMustParse(t *testing.T) {
assert.NotNil(t, parser)
}
+func TestMustParseError(t *testing.T) {
+ var args struct {
+ Foo []string `default:""`
+ }
+ var exitCode int
+ var stdout bytes.Buffer
+ mustParseExit = func(code int) { exitCode = code }
+ mustParseOut = &stdout
+ os.Args = []string{"example"}
+ parser := MustParse(&args)
+ assert.Nil(t, parser)
+ assert.Equal(t, -1, exitCode)
+ assert.Contains(t, stdout.String(), "default values are not supported for slice or map fields")
+}
+
func TestEnvironmentVariable(t *testing.T) {
var args struct {
Foo string `arg:"env"`