From edb16648484c5752d70fd84f08b3aecc46e61339 Mon Sep 17 00:00:00 2001 From: MidnightRocket Date: Fri, 21 Mar 2025 18:02:55 +0100 Subject: Add better test for defaultIsZeroValue for generic Value type --- flag_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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 { -- cgit v1.2.3