summaryrefslogtreecommitdiff
path: root/usage_test.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2016-09-08 21:18:19 -0700
committerAlex Flint <[email protected]>2016-09-08 21:18:19 -0700
commitc453aa1a28b0cc9baac51cf5cc04df2688d3cd25 (patch)
tree7503a5a4f6fad156748c240cb7bec498e8715204 /usage_test.go
parent34954f45cec4632059c6aa8ca6f769a748464cf7 (diff)
add support for version string
Diffstat (limited to 'usage_test.go')
-rw-r--r--usage_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/usage_test.go b/usage_test.go
index b63a7d0..e60efdb 100644
--- a/usage_test.go
+++ b/usage_test.go
@@ -100,3 +100,32 @@ options:
p.WriteHelp(&help)
assert.Equal(t, expectedHelp, help.String())
}
+
+type versioned struct{}
+
+// Version returns the version for this program
+func (versioned) Version() string {
+ return "example 3.2.1"
+}
+
+func TestUsageWithVersion(t *testing.T) {
+ expectedHelp := `example 3.2.1
+usage: example
+
+options:
+ --help, -h display this help and exit
+ --version display version and exit
+`
+ os.Args[0] = "example"
+ p, err := NewParser(Config{}, &versioned{})
+ require.NoError(t, err)
+
+ var help bytes.Buffer
+ p.WriteHelp(&help)
+ actual := help.String()
+ t.Logf("Expected:\n%s", expectedHelp)
+ t.Logf("Actual:\n%s", actual)
+ if expectedHelp != actual {
+ t.Fail()
+ }
+}