aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMidnightRocket <[email protected]>2025-03-21 18:02:55 +0100
committerMidnightRocket <[email protected]>2025-04-01 21:23:37 +0200
commitedb16648484c5752d70fd84f08b3aecc46e61339 (patch)
treed014832f50bf84cf17f3c2c268c2772593187718
parent9edfc8d416bea8aecfbdf0790a838f95ae133078 (diff)
Add better test for defaultIsZeroValue for generic Value type
-rw-r--r--flag_test.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/flag_test.go b/flag_test.go
index 643f099..344eb07 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,6 +1235,14 @@ 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 {