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

Function TestChangingArgs

flag_test.go:986–1004  ·  view source on GitHub ↗

This tests that one can reset the flags. This still works but not well, and is superseded by FlagSet.

(t *testing.T)

Source from the content-addressed store, hash-verified

984// This tests that one can reset the flags. This still works but not well, and is
985// superseded by FlagSet.
986func TestChangingArgs(t *testing.T) {
987 ResetForTesting(func() { t.Fatal("bad parse") })
988 oldArgs := os.Args
989 defer func() { os.Args = oldArgs }()
990 os.Args = []string{"cmd", "--before", "subcmd"}
991 before := Bool("before", false, "")
992 if err := GetCommandLine().Parse(os.Args[1:]); err != nil {
993 t.Fatal(err)
994 }
995 cmd := Arg(0)
996 os.Args = []string{"subcmd", "--after", "args"}
997 after := Bool("after", false, "")
998 Parse()
999 args := Args()
1000
1001 if !*before || cmd != "subcmd" || !*after || len(args) != 1 || args[0] != "args" {
1002 t.Fatalf("expected true subcmd true [args] got %v %v %v %v", *before, cmd, *after, args)
1003 }
1004}
1005
1006// Test that -help invokes the usage message and returns ErrHelp.
1007func TestHelp(t *testing.T) {

Callers

nothing calls this directly

Calls 7

ResetForTestingFunction · 0.85
BoolFunction · 0.85
GetCommandLineFunction · 0.85
ArgFunction · 0.85
ParseFunction · 0.85
ArgsFunction · 0.85
ParseMethod · 0.65

Tested by

no test coverage detected