MCPcopy
hub / github.com/spf13/pflag / TestBoolFuncP

Function TestBoolFuncP

bool_func_test.go:28–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestBoolFuncP(t *testing.T) {
29 var count int
30 fn := func(_ string) error {
31 count++
32 return nil
33 }
34
35 fset := NewFlagSet("test", ContinueOnError)
36 fset.BoolFuncP("bfunc", "b", "Callback function", fn)
37
38 err := fset.Parse([]string{"--bfunc", "--bfunc=0", "--bfunc=false", "-b", "-b=0"})
39 if err != nil {
40 t.Fatal("expected no error; got", err)
41 }
42
43 if count != 5 {
44 t.Fatalf("expected 5 calls to the callback, got %d calls", count)
45 }
46}
47
48func TestBoolFuncUsage(t *testing.T) {
49 t.Run("regular func flag", func(t *testing.T) {

Callers

nothing calls this directly

Calls 3

BoolFuncPMethod · 0.95
ParseMethod · 0.95
NewFlagSetFunction · 0.85

Tested by

no test coverage detected