diff options
| author | Alex Flint <[email protected]> | 2019-10-19 23:23:32 -0700 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2019-10-19 23:23:32 -0700 |
| commit | cc768447a7257b5957349efe0f7ecbaaa95f34f8 (patch) | |
| tree | 519e05a2d45687990959b44f98e5c0fb1f6b9c9d /usage_test.go | |
| parent | 5d3ebcceeee6ce36f5f7244f7cd9600d9823748e (diff) | |
store default values during NewParser
Diffstat (limited to 'usage_test.go')
| -rw-r--r-- | usage_test.go | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/usage_test.go b/usage_test.go index fc0b8c5..d9d33f0 100644 --- a/usage_test.go +++ b/usage_test.go @@ -96,28 +96,39 @@ func (n *MyEnum) MarshalText() ([]byte, error) { return nil, errors.New("There was a problem") } -func TestUsageError(t *testing.T) { - expectedHelp := `Usage: example [--name NAME] +func TestUsageWithDefaults(t *testing.T) { + expectedHelp := `Usage: example [--label LABEL] [--content CONTENT] Options: - --name NAME [default: error: There was a problem] + --label LABEL [default: cat] + --content CONTENT [default: dog] --help, -h display this help and exit ` var args struct { - Name *MyEnum + Label string + Content string `default:"dog"` } - v := MyEnum(42) - args.Name = &v + args.Label = "cat" p, err := NewParser(Config{"example"}, &args) - - // NB: some might might expect there to be an error here require.NoError(t, err) + args.Label = "should_ignore_this" + var help bytes.Buffer p.WriteHelp(&help) assert.Equal(t, expectedHelp, help.String()) } +func TestUsageCannotMarshalToString(t *testing.T) { + var args struct { + Name *MyEnum + } + v := MyEnum(42) + args.Name = &v + _, err := NewParser(Config{"example"}, &args) + assert.EqualError(t, err, `args.Name: error marshaling default value to string: There was a problem`) +} + func TestUsageLongPositionalWithHelp_legacyForm(t *testing.T) { expectedHelp := `Usage: example VERYLONGPOSITIONALWITHHELP |
