1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00
revive/test/golint_test.go
Tamir Duberstein 1b2ffe282e Improve tests (#18)
* Use subtests

* Make unexported-return type check
2018-06-11 11:22:06 -07:00

69 lines
1.5 KiB
Go

package test
import (
"flag"
"io/ioutil"
"path"
"regexp"
"testing"
"github.com/mgechev/revive/lint"
"github.com/mgechev/revive/rule"
)
var lintMatch = flag.String("lint.match", "", "restrict fixtures matches to this pattern")
var rules = []lint.Rule{
&rule.VarDeclarationsRule{},
&rule.PackageCommentsRule{},
&rule.DotImportsRule{},
&rule.BlankImportsRule{},
&rule.ExportedRule{},
&rule.VarNamingRule{},
&rule.IndentErrorFlowRule{},
&rule.IfReturnRule{},
&rule.RangeRule{},
&rule.ErrorfRule{},
&rule.ErrorNamingRule{},
&rule.ErrorStringsRule{},
&rule.ReceiverNamingRule{},
&rule.IncrementDecrementRule{},
&rule.ErrorReturnRule{},
&rule.UnexportedReturnRule{},
&rule.TimeNamingRule{},
&rule.ContextKeysType{},
&rule.ContextAsArgumentRule{},
}
func TestAll(t *testing.T) {
baseDir := "../fixtures/golint/"
rx, err := regexp.Compile(*lintMatch)
if err != nil {
t.Fatalf("Bad -lint.match value %q: %v", *lintMatch, err)
}
fis, err := ioutil.ReadDir(baseDir)
if err != nil {
t.Fatalf("ioutil.ReadDir: %v", err)
}
if len(fis) == 0 {
t.Fatalf("no files in %v", baseDir)
}
for _, fi := range fis {
if !rx.MatchString(fi.Name()) {
continue
}
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)
}
if err := assertFailures(t, baseDir, fi, src, rules, map[string]lint.RuleConfig{}); err != nil {
t.Errorf("Linting %s: %v", fi.Name(), err)
}
})
}
}