From a1e2b672eacc00152b7047ea971474283b60bf1e Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Tue, 4 Oct 2022 11:06:19 -0700 Subject: [PATCH] add a test to check that default values can be ignored if needed --- v2/parse_test.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/v2/parse_test.go b/v2/parse_test.go index d323847..148bd09 100644 --- a/v2/parse_test.go +++ b/v2/parse_test.go @@ -805,18 +805,25 @@ func TestEnvironmentVariableIgnored(t *testing.T) { assert.Equal(t, "", args.Foo) } -// func TestDefaultValuesIgnored(t *testing.T) { -// var args struct { -// Foo string `default:"bad"` -// } +func TestDefaultValuesIgnored(t *testing.T) { + var args struct { + Foo string `default:"bad"` + } -// p, err := NewParser(Config{IgnoreDefault: true}, &args) -// require.NoError(t, err) + // just checking that default values are not automatically applied + // in ProcessCommandLine or ProcessEnvironment -// err = p.Parse(nil) -// assert.NoError(t, err) -// assert.Equal(t, "", args.Foo) -// } + p, err := NewParser(Config{}, &args) + require.NoError(t, err) + + err = p.ProcessCommandLine(nil) + assert.NoError(t, err) + + err = p.ProcessEnvironment(nil) + assert.NoError(t, err) + + assert.Equal(t, "", args.Foo) +} func TestEnvironmentVariableInSubcommand(t *testing.T) { var args struct {