summaryrefslogtreecommitdiff
path: root/usage_test.go
diff options
context:
space:
mode:
authorWlazlo, Matt <[email protected]>2018-04-16 11:07:48 +1000
committerWlazlo, Matt <[email protected]>2018-04-16 11:07:48 +1000
commit51337ded775c91dc26574d7d2dc2e493cf416138 (patch)
treefbcf34b3dbf7c874ed261ed390c82c6fc933479f /usage_test.go
parentd4cc703210ff08d7bc4f73bfbec1e51eda29a5a4 (diff)
fixed example comment, test coverage issue
Diffstat (limited to 'usage_test.go')
-rw-r--r--usage_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/usage_test.go b/usage_test.go
index 4aa2f24..4f179f0 100644
--- a/usage_test.go
+++ b/usage_test.go
@@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
"strings"
"fmt"
+ "errors"
)
type NameDotName struct {
@@ -85,6 +86,42 @@ Options:
assert.Equal(t, expectedHelp, help.String())
}
+type MyEnum int
+
+func (n *MyEnum) UnmarshalText(b []byte) error {
+ b = []byte("Hello")
+ return nil
+}
+
+func (n *MyEnum) MarshalText() (text []byte, err error) {
+ s := "There was a problem"
+ text = []byte(s)
+ err = errors.New(s)
+ return
+}
+
+func TestUsageError(t *testing.T) {
+ expectedHelp := `Usage: example [--name NAME]
+
+Options:
+ --name NAME [default: error: There was a problem]
+ --help, -h display this help and exit
+`
+ var args struct {
+ Name *MyEnum
+ }
+ v := MyEnum(42)
+ args.Name = &v
+ p, err := NewParser(Config{"example"}, &args)
+
+ // NB: some might might expect there to be an error here
+ require.NoError(t, err)
+
+ var help bytes.Buffer
+ p.WriteHelp(&help)
+ assert.Equal(t, expectedHelp, help.String())
+}
+
func TestUsageLongPositionalWithHelp_legacyForm(t *testing.T) {
expectedHelp := `Usage: example VERYLONGPOSITIONALWITHHELP