This tests that one can reset the flags. This still works but not well, and is superseded by FlagSet.
(t *testing.T)
| 984 | // This tests that one can reset the flags. This still works but not well, and is |
| 985 | // superseded by FlagSet. |
| 986 | func 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. |
| 1007 | func TestHelp(t *testing.T) { |
nothing calls this directly
no test coverage detected