aboutsummaryrefslogtreecommitdiff
path: root/flag_test.go
diff options
context:
space:
mode:
authorTomas Aschan <[email protected]>2025-04-01 22:50:37 +0200
committerGitHub <[email protected]>2025-04-01 22:50:37 +0200
commit19c9c4072e41218b18b93dbfc3798c18835d2fd5 (patch)
tree8b776ebe618ee95f5c1db63c1c4b71b3b35b0b60 /flag_test.go
parent5ca813443bd2a4d9f46a253ea0407d23b3790713 (diff)
parentc96309303407244840d6f2bc00ae32dc95390c25 (diff)
Merge pull request #422 from MidnightRocket/fix-default-is-zerovalue-for-generic-value-type
Fix defaultIsZeroValue check for generic Value types
Diffstat (limited to 'flag_test.go')
-rw-r--r--flag_test.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/flag_test.go b/flag_test.go
index 643f099..0dbe874 100644
--- a/flag_test.go
+++ b/flag_test.go
@@ -1183,6 +1183,7 @@ const defaultOutput = ` --A for bootstrapping, allo
--StringSlice strings string slice with zero default
--Z int an int that defaults to zero
--custom custom custom Value implementation
+ --custom-with-val custom custom value which has been set from command line while help is shown
--customP custom a VarP with default (default 10)
--maxT timeout set timeout for dial
-v, --verbose count verbosity
@@ -1234,12 +1235,18 @@ func TestPrintDefaults(t *testing.T) {
cv2 := customValue(10)
fs.VarP(&cv2, "customP", "", "a VarP with default")
+ // Simulate case where a value has been provided and the help screen is shown
+ var cv3 customValue
+ fs.Var(&cv3, "custom-with-val", "custom value which has been set from command line while help is shown")
+ err := fs.Parse([]string{"--custom-with-val", "3"})
+ if err != nil {
+ t.Error("Parsing flags failed:", err)
+ }
+
fs.PrintDefaults()
got := buf.String()
if got != defaultOutput {
- fmt.Println("\n" + got)
- fmt.Printf("\n" + defaultOutput)
- t.Errorf("got %q want %q\n", got, defaultOutput)
+ t.Errorf("\n--- Got:\n%s--- Wanted:\n%s\n", got, defaultOutput)
}
}