@@ -1183,6 +1183,7 @@ const defaultOutput = ` --A for bootstrapping, allo
11831183 --StringSlice strings string slice with zero default
11841184 --Z int an int that defaults to zero
11851185 --custom custom custom Value implementation
1186+ --custom-with-val custom custom value which has been set from command line while help is shown
11861187 --customP custom a VarP with default (default 10)
11871188 --maxT timeout set timeout for dial
11881189 -v, --verbose count verbosity
@@ -1234,12 +1235,18 @@ func TestPrintDefaults(t *testing.T) {
12341235 cv2 := customValue (10 )
12351236 fs .VarP (& cv2 , "customP" , "" , "a VarP with default" )
12361237
1238+ // Simulate case where a value has been provided and the help screen is shown
1239+ var cv3 customValue
1240+ fs .Var (& cv3 , "custom-with-val" , "custom value which has been set from command line while help is shown" )
1241+ err := fs .Parse ([]string {"--custom-with-val" , "3" })
1242+ if err != nil {
1243+ t .Error ("Parsing flags failed:" , err )
1244+ }
1245+
12371246 fs .PrintDefaults ()
12381247 got := buf .String ()
12391248 if got != defaultOutput {
1240- fmt .Println ("\n " + got )
1241- fmt .Printf ("\n " + defaultOutput )
1242- t .Errorf ("got %q want %q\n " , got , defaultOutput )
1249+ t .Errorf ("\n --- Got:\n %s--- Wanted:\n %s\n " , got , defaultOutput )
12431250 }
12441251}
12451252
0 commit comments