aboutsummaryrefslogtreecommitdiff
path: root/flag_test.go
diff options
context:
space:
mode:
authorEric Paris <[email protected]>2015-08-07 18:19:17 -0400
committerEric Paris <[email protected]>2015-08-07 18:26:20 -0400
commit72d256dc0568ff0c62c58ad4e32b6b5fc0d533d8 (patch)
tree2ff044d4ef04218719a62138c5778226cbd45228 /flag_test.go
parent534019bcaea096fc0f0641afa2aed1e80cbb0ccc (diff)
New helper to easily see if a flag has been set
A lot easier than having to do it in the user over and over and over.
Diffstat (limited to 'flag_test.go')
-rw-r--r--flag_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/flag_test.go b/flag_test.go
index a5928e5..0f1d751 100644
--- a/flag_test.go
+++ b/flag_test.go
@@ -381,6 +381,26 @@ func TestFlagSetParse(t *testing.T) {
testParse(NewFlagSet("test", ContinueOnError), t)
}
+func TestChangedHelper(t *testing.T) {
+ f := NewFlagSet("changedtest", ContinueOnError)
+ _ = f.Bool("changed", false, "changed bool")
+ _ = f.Bool("unchanged", false, "unchanged bool")
+
+ args := []string{"--changed"}
+ if err := f.Parse(args); err != nil {
+ t.Error("f.Parse() = false after Parse")
+ }
+ if !f.Changed("changed") {
+ t.Errorf("--changed wasn't changed!")
+ }
+ if f.Changed("unchanged") {
+ t.Errorf("--unchanged was changed!")
+ }
+ if f.Changed("invalid") {
+ t.Errorf("--invalid was changed!")
+ }
+}
+
func replaceSeparators(name string, from []string, to string) string {
result := name
for _, sep := range from {