From 1b2ffe282e90c75ce1e21ec24573d37a2d595ff0 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 11 Jun 2018 14:22:06 -0400 Subject: [PATCH] Improve tests (#18) * Use subtests * Make unexported-return type check --- fixtures/golint/unexported-return.go | 10 ++++++++-- test/golint_test.go | 22 ++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/fixtures/golint/unexported-return.go b/fixtures/golint/unexported-return.go index ef20638..8a711ac 100644 --- a/fixtures/golint/unexported-return.go +++ b/fixtures/golint/unexported-return.go @@ -12,14 +12,20 @@ func Exported() hidden { // MATCH /exported func Exported returns unexported typ // ExpErr returns a builtin type. func ExpErr() error { // ok + return nil } -func (hidden) ExpOnHidden() hidden { // ok +func (h hidden) ExpOnHidden() hidden { // ok + return h +} + +func (hidden) ForInterface() error { + return nil } // Interface is exported. type Interface interface { - ExpOnHidden() + ForInterface() error } // ExportedAsInterface returns a hidden type as an exported interface, which is fine. diff --git a/test/golint_test.go b/test/golint_test.go index f63d8e7..492d8f5 100644 --- a/test/golint_test.go +++ b/test/golint_test.go @@ -7,9 +7,8 @@ import ( "regexp" "testing" - "github.com/mgechev/revive/rule" - "github.com/mgechev/revive/lint" + "github.com/mgechev/revive/rule" ) var lintMatch = flag.String("lint.match", "", "restrict fixtures matches to this pattern") @@ -55,16 +54,15 @@ func TestAll(t *testing.T) { if !rx.MatchString(fi.Name()) { continue } - //t.Logf("Testing %s", fi.Name()) - src, err := ioutil.ReadFile(path.Join(baseDir, fi.Name())) - if err != nil { - t.Fatalf("Failed reading %s: %v", fi.Name(), err) - } + t.Run(fi.Name(), func(t *testing.T) { + src, err := ioutil.ReadFile(path.Join(baseDir, fi.Name())) + if err != nil { + t.Fatalf("Failed reading %s: %v", fi.Name(), err) + } - err = assertFailures(t, baseDir, fi, src, rules, map[string]lint.RuleConfig{}) - if err != nil { - t.Errorf("Linting %s: %v", fi.Name(), err) - continue - } + if err := assertFailures(t, baseDir, fi, src, rules, map[string]lint.RuleConfig{}); err != nil { + t.Errorf("Linting %s: %v", fi.Name(), err) + } + }) } }