Skip to content

Commit d896521

Browse files
authored
Merge pull request #138 from commander-cli/add-filter-flag
Add --filter flag
2 parents bde1096 + cb91de1 commit d896521

File tree

16 files changed

+159
-59
lines changed

16 files changed

+159
-59
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020

2121
before_install:
2222
- go get -u golang.org/x/lint/golint
23-
- curl -L https://github.com/commander-cli/commander/releases/download/v1.2.1/commander-linux-amd64 -o ~/bin/commander
23+
- curl -L https://github.com/commander-cli/commander/releases/download/v2.1.0/commander-linux-amd64 -o ~/bin/commander
2424
- chmod +x ~/bin/commander
2525

2626
jobs:
@@ -37,7 +37,7 @@ jobs:
3737
- name: macOS integration
3838
os: osx
3939
script:
40-
- curl -L https://github.com/commander-cli/commander/releases/download/v0.3.0/commander-darwin-amd64 -o ~/bin/commander
40+
- curl -L https://github.com/commander-cli/commander/releases/download/v2.1.0/commander-darwin-amd64 -o ~/bin/commander
4141
- chmod +x ~/bin/commander
4242
- make integration-unix
4343

@@ -53,7 +53,7 @@ jobs:
5353
before_install:
5454
- choco install make
5555
- choco install curl
56-
- curl -L https://github.com/commander-cli/commander/releases/download/v1.2.1/commander-windows-amd64 -o C:\Windows\system32\commander.exe
56+
- curl -L https://github.com/commander-cli/commander/releases/download/v2.1.0/commander-windows-amd64 -o C:\Windows\system32\commander.exe
5757
script:
5858
- make integration-windows
5959

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# v2.2.0
22

33
- Move from `github.com/SimonBaeumer` to `github.com/commander-cli`
4+
- Remove `filter` as an argument, instead use `--filter` with regex support
45

56
# v2.1.0
67

cmd/commander/commander.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func createTestCommand() cli.Command {
4747
return cli.Command{
4848
Name: "test",
4949
Usage: "Execute the test suite, by default it will use the commander.yaml from your current directory",
50-
ArgsUsage: "[file] [title]",
50+
ArgsUsage: "[file] [--filter]",
5151
Flags: []cli.Flag{
5252
cli.BoolFlag{
5353
Name: "no-color",
@@ -63,9 +63,20 @@ func createTestCommand() cli.Command {
6363
Name: "dir",
6464
Usage: "Execute all test files in a directory sorted by file name, this is not recursive - e.g. /path/to/test_files/",
6565
},
66+
cli.StringSliceFlag{
67+
Name: "filter",
68+
Usage: `Filter tests by a given regex pattern. Tests are filtered by its title.
69+
70+
Example:
71+
test commander.yaml --filter="my test"
72+
73+
Apply multiple filters:
74+
test commander.yaml --filter=filter1 --filter=filter2
75+
`,
76+
},
6677
},
6778
Action: func(c *cli.Context) error {
68-
return app.TestCommand(c.Args().First(), c.Args().Get(1), app.NewAddContextFromCli(c))
79+
return app.TestCommand(c.Args().First(), app.NewTestContextFromCli(c))
6980
},
7081
}
7182
}

commander_unix.yaml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,36 @@ tests:
7878
stdout:
7979
contains:
8080
- 'integration/unix/directory_test/: is a directory'
81-
exit-code: 1
81+
exit-code: 1
82+
83+
test filter flag works:
84+
command: ./commander test integration/unix/filter_test.yaml --filter=executed
85+
stdout:
86+
contains:
87+
- ✓ [local] should be executed
88+
- ✓ [local] should also be executed
89+
not-contains:
90+
- should be filtered
91+
exit-code: 0
92+
93+
test filter flag with regex:
94+
command: ./commander test integration/unix/filter_test.yaml --filter="executed$"
95+
stdout:
96+
contains:
97+
- ✓ [local] should be executed
98+
- ✓ [local] should also be executed
99+
not-contains:
100+
- should be ignored
101+
- executed at the beginning is ignored
102+
exit-code: 0
103+
104+
test mulitple filters:
105+
command: ./commander test integration/unix/filter_test.yaml --filter="executed$" --filter="should be ignored"
106+
stdout:
107+
contains:
108+
- ✓ [local] should be executed
109+
- ✓ [local] should also be executed
110+
- ✓ [local] should be ignored
111+
not-contains:
112+
- executed at the beginning is ignored
113+
exit-code: 0

examples/minimal_test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
tests:
22
echo hello:
33
exit-code: 0
4+
echo hello123:
5+
exit-code: 0

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module github.com/commander-cli/commander
22

33
require (
44
github.com/Microsoft/go-winio v0.4.14 // indirect
5-
github.com/SimonBaeumer/commander v1.3.0 // indirect
65
github.com/antchfx/xmlquery v1.1.0
76
github.com/antchfx/xpath v1.1.0 // indirect
87
github.com/commander-cli/cmd v1.3.0

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
22
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
3-
github.com/SimonBaeumer/cmd v1.1.0 h1:tr5dUMlly/8bLiC5B0J1AcE4ISru8POEfzAirWnUJnY=
4-
github.com/SimonBaeumer/cmd v1.1.0/go.mod h1:4mc/LDXDWNbkeooqHP83yx3JXtInPHjJkF8zhzqqmZE=
5-
github.com/SimonBaeumer/commander v1.3.0 h1:QwZ7sTYFrmkOAccZwu8LZltDC08kIEcFjBBOkpjdZIg=
6-
github.com/SimonBaeumer/commander v1.3.0/go.mod h1:sNvvvwudBa2kQcSO7G1PttZHcBUnS5LmtJAjDS1Yh+U=
73
github.com/antchfx/xmlquery v1.1.0 h1:vj0kZ1y3Q6my4AV+a9xbWrMYzubw+84zuiKgvfV8vb8=
84
github.com/antchfx/xmlquery v1.1.0/go.mod h1:/+CnyD/DzHRnv2eRxrVbieRU/FIF6N0C+7oTtyUtCKk=
95
github.com/antchfx/xpath v1.1.0 h1:mJTvYpiHvxNQRD4Lbfin/FodHVCHh2a5KrOFr4ZxMOI=
@@ -40,9 +36,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
4036
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
4137
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4238
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
43-
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
4439
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
45-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
4640
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
4741
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
4842
github.com/tidwall/gjson v1.3.2 h1:+7p3qQFaH3fOMXAJSrdZwGKcOO/lYdGS0HqGhPqDdTI=

integration/unix/filter_test.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests:
2+
should be executed:
3+
command: echo executed
4+
exit-code: 0
5+
6+
should also be executed:
7+
command: echo executed
8+
exit-code: 0
9+
10+
executed at the beginning is ignored:
11+
command: echo ignored
12+
exit-code: 0
13+
14+
should be ignored:
15+
command: echo filtered
16+
exit-code: 0

pkg/app/app.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package app
22

3-
import "github.com/urfave/cli"
3+
import (
4+
"github.com/urfave/cli"
5+
)
46

57
const (
68
//AppName defines the app name
@@ -9,20 +11,22 @@ const (
911
CommanderFile = "commander.yaml"
1012
)
1113

12-
//AddCommandContext holds all flags for the add command
13-
type AddCommandContext struct {
14+
//TestCommandContext holds all flags for the add command
15+
type TestCommandContext struct {
1416
Verbose bool
1517
NoColor bool
1618
Dir bool
1719
Concurrent int
20+
Filters []string
1821
}
1922

20-
//NewAddContextFromCli is a constructor which creates the context
21-
func NewAddContextFromCli(c *cli.Context) AddCommandContext {
22-
return AddCommandContext{
23+
//NewTestContextFromCli is a constructor which creates the context
24+
func NewTestContextFromCli(c *cli.Context) TestCommandContext {
25+
return TestCommandContext{
2326
Verbose: c.Bool("verbose"),
2427
NoColor: c.Bool("no-color"),
2528
Dir: c.Bool("dir"),
2629
Concurrent: c.Int("concurrent"),
30+
Filters: c.StringSlice("filter"),
2731
}
2832
}

pkg/app/app_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88
)
99

10-
func TestNewAddCommandContextFromCli(t *testing.T) {
10+
func TestNewTestCommandContextFromCli(t *testing.T) {
1111
set := flag.NewFlagSet("verbose", 0)
1212
set.Bool("verbose", true, "")
1313
set.Bool("no-color", true, "")
@@ -16,7 +16,7 @@ func TestNewAddCommandContextFromCli(t *testing.T) {
1616
context := &cli.Context{}
1717
ctx := cli.NewContext(nil, set, context)
1818

19-
r := NewAddContextFromCli(ctx)
19+
r := NewTestContextFromCli(ctx)
2020

2121
assert.True(t, r.Verbose)
2222
assert.True(t, r.NoColor)

0 commit comments

Comments
 (0)