aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/codegangsta/cli/command_test.go
blob: c0f556ad242b6bdf83ea7e0067aa783abf32d210 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cli_test

import (
    "flag"
    "testing"

    "github.com/codegangsta/cli"
)

func TestCommandDoNotIgnoreFlags(t *testing.T) {
    app := cli.NewApp()
    set := flag.NewFlagSet("test", 0)
    test := []string{"blah", "blah", "-break"}
    set.Parse(test)

    c := cli.NewContext(app, set, set)

    command := cli.Command{
        Name:        "test-cmd",
        ShortName:   "tc",
        Usage:       "this is for testing",
        Description: "testing",
        Action:      func(_ *cli.Context) {},
    }
    err := command.Run(c)

    expect(t, err.Error(), "flag provided but not defined: -break")
}

func TestCommandIgnoreFlags(t *testing.T) {
    app := cli.NewApp()
    set := flag.NewFlagSet("test", 0)
    test := []string{"blah", "blah"}
    set.Parse(test)

    c := cli.NewContext(app, set, set)

    command := cli.Command{
        Name:            "test-cmd",
        ShortName:       "tc",
        Usage:           "this is for testing",
        Description:     "testing",
        Action:          func(_ *cli.Context) {},
        SkipFlagParsing: true,
    }
    err := command.Run(c)

    expect(t, err, nil)
}