Skip to content

Commit

Permalink
Update gunit tags to use NamesPathsWithExcludeCfg (#95)
Browse files Browse the repository at this point in the history
Allows tags to exclude specific files or paths from matching.
  • Loading branch information
nmiyake authored Apr 6, 2017
1 parent 39bf657 commit 347fee8
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 17 deletions.
8 changes: 4 additions & 4 deletions apps/gunit/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
)

type GUnit struct {
// Tags group tests into different sets. The key is the name of the tag and the value is a matcher.NamesPathsCfg
// that specifies the rules for matching the tests that are part of the tag. Any test that matches the provided
// matcher is considered part of the tag.
Tags map[string]matcher.NamesPathsCfg `yaml:"tags" json:"tags"`
// Tags group tests into different sets. The key is the name of the tag and the value is a
// matcher.NamesPathsWithExcludeCfg that specifies the rules for matching the tests that are part of the tag.
// Any test that matches the provided matcher is considered part of the tag.
Tags map[string]matcher.NamesPathsWithExcludeCfg `yaml:"tags" json:"tags"`

// Exclude specifies the files that should be excluded from tests.
Exclude matcher.NamesPathsCfg `yaml:"exclude" json:"exclude"`
Expand Down
27 changes: 21 additions & 6 deletions apps/gunit/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func TestLoadConfig(t *testing.T) {
- "integration_tests"
paths:
- "test"
exclude:
names:
- "ignore"
paths:
- "test/foo"
exclude:
names:
- ".*test"
Expand All @@ -50,10 +55,16 @@ func TestLoadConfig(t *testing.T) {
`,
json: `{"exclude":{"names":["gunit"],"paths":["generated_src"]}}`,
want: config.GUnit{
Tags: map[string]matcher.NamesPathsCfg{
Tags: map[string]matcher.NamesPathsWithExcludeCfg{
"integration": {
Names: []string{`integration_tests`},
Paths: []string{`test`},
NamesPathsCfg: matcher.NamesPathsCfg{
Names: []string{`integration_tests`},
Paths: []string{`test`},
},
Exclude: matcher.NamesPathsCfg{
Names: []string{`ignore`},
Paths: []string{`test/foo`},
},
},
},
Exclude: matcher.NamesPathsCfg{
Expand All @@ -76,12 +87,16 @@ func TestLoadConfig(t *testing.T) {
- "test"
`,
want: config.GUnit{
Tags: map[string]matcher.NamesPathsCfg{
Tags: map[string]matcher.NamesPathsWithExcludeCfg{
"integration": {
Names: []string{`integration_tests`},
NamesPathsCfg: matcher.NamesPathsCfg{
Names: []string{`integration_tests`},
},
},
"mixedCasing": {
Paths: []string{`test`},
NamesPathsCfg: matcher.NamesPathsCfg{
Paths: []string{`test`},
},
},
},
},
Expand Down
7 changes: 6 additions & 1 deletion apps/gunit/config/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ tags:
- "integration_tests"
paths:
- "test"
exclude:
names:
- "ignore"
paths:
- "test/exclude"
`
cfg, err := config.LoadRawConfig(yml, "")
if err != nil {
panic(err)
}
fmt.Printf("%q", fmt.Sprintf("%+v", cfg))
// Output: "{Tags:map[integration:{Names:[integration_tests] Paths:[test]}] Exclude:{Names:[] Paths:[]}}"
// Output: "{Tags:map[integration:{NamesPathsCfg:{Names:[integration_tests] Paths:[test]} Exclude:{Names:[ignore] Paths:[test/exclude]}}] Exclude:{Names:[] Paths:[]}}"
}
57 changes: 57 additions & 0 deletions apps/gunit/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,63 @@ func TestRun(t *testing.T) {
},
wantError: "(?s).+1 package had failing tests:.+",
},
{
name: "tag will skip excluded tests",
filesToCreate: []gofiles.GoFileSpec{
{
RelPath: "foo_test.go",
Src: `package foo
import "testing"
func TestFoo(t *testing.T) {
t.Errorf("fooFail")
}`,
},
{
RelPath: "integration/bar_test.go",
Src: `package bar
import "testing"
func TestBar(t *testing.T) {
t.Errorf("barFail")
}`,
},
{
RelPath: "integration/baz/baz_test.go",
Src: `package baz
import "testing"
func TestBaz(t *testing.T) {
t.Errorf("bazFail")
}`,
},
{
RelPath: "integration/exclude/exclude_test.go",
Src: `package exclude
import "testing"
func TestExclude(t *testing.T) {
t.Errorf("exclude")
}`,
},
},
config: unindent(`tags:
integration:
names:
- "integration"
exclude:
paths:
- "integration/exclude"
exclude:
paths:
- "vendor"
`),
args: []string{
"--tags", "integration",
},
wantMatch: func(currCaseTmpDir string) string {
return `(?s)` +
`--- FAIL: TestBar (.+)\n.+bar_test.go:[0-9]+: barFail.+FAIL\t` + pkgName(t, currCaseTmpDir) + `/integration\s+[0-9.]+s.+` +
`--- FAIL: TestBaz (.+)\n.+baz_test.go:[0-9]+: bazFail.+FAIL\t` + pkgName(t, currCaseTmpDir) + `/integration/baz\s+[0-9.]+s.+`
},
wantError: "(?s).+2 packages had failing tests:.+",
},
{
name: "tags are case-insensitive",
filesToCreate: []gofiles.GoFileSpec{
Expand Down
16 changes: 15 additions & 1 deletion vendor/github.com/palantir/pkg/matcher/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/palantir/pkg/matcher/files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/palantir/pkg/matcher/matchers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@
"revisionTime": "2016-12-02T17:17:08Z"
},
{
"checksumSHA1": "MhrjempJy/hQiqcj1axZp/oox9Q=",
"checksumSHA1": "rBe6S08Qg9PJd56jlY5knLgUQLk=",
"path": "github.com/palantir/pkg/matcher",
"revision": "c60ea2d471b77fae0cd4219bd329bd7e0e01d5b8",
"revisionTime": "2016-12-02T17:17:08Z"
"revision": "5d8e3ae75f4c1da9363692b04fcb4334bf09b82a",
"revisionTime": "2017-04-06T01:49:46Z"
},
{
"checksumSHA1": "wFdDjAqsTus/qC39RSSB7liU124=",
Expand Down

0 comments on commit 347fee8

Please sign in to comment.