add a test to check that default values can be ignored if needed

This commit is contained in:
Alex Flint 2022-10-04 11:06:19 -07:00
parent 22f214d7ed
commit a1e2b672ea
1 changed files with 17 additions and 10 deletions

View File

@ -805,18 +805,25 @@ func TestEnvironmentVariableIgnored(t *testing.T) {
assert.Equal(t, "", args.Foo) assert.Equal(t, "", args.Foo)
} }
// func TestDefaultValuesIgnored(t *testing.T) { func TestDefaultValuesIgnored(t *testing.T) {
// var args struct { var args struct {
// Foo string `default:"bad"` Foo string `default:"bad"`
// } }
// p, err := NewParser(Config{IgnoreDefault: true}, &args) // just checking that default values are not automatically applied
// require.NoError(t, err) // in ProcessCommandLine or ProcessEnvironment
// err = p.Parse(nil) p, err := NewParser(Config{}, &args)
// assert.NoError(t, err) require.NoError(t, err)
// assert.Equal(t, "", args.Foo)
// } 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) { func TestEnvironmentVariableInSubcommand(t *testing.T) {
var args struct { var args struct {