1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-28 08:49:11 +02:00
revive/test/golint_test.go

69 lines
1.5 KiB
Go
Raw Normal View History

2018-02-05 01:02:45 +02:00
package test
import (
"flag"
"io/ioutil"
"path"
"regexp"
"testing"
"github.com/mgechev/revive/lint"
"github.com/mgechev/revive/rule"
2018-02-05 01:02:45 +02:00
)
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{},
2018-05-27 06:28:31 +02:00
&rule.VarNamingRule{},
2018-05-27 01:14:36 +02:00
&rule.IndentErrorFlowRule{},
2018-02-05 01:02:45 +02:00
&rule.IfReturnRule{},
&rule.RangeRule{},
&rule.ErrorfRule{},
2018-05-27 06:28:31 +02:00
&rule.ErrorNamingRule{},
2018-02-05 01:02:45 +02:00
&rule.ErrorStringsRule{},
2018-05-27 06:28:31 +02:00
&rule.ReceiverNamingRule{},
2018-02-05 01:02:45 +02:00
&rule.IncrementDecrementRule{},
&rule.ErrorReturnRule{},
&rule.UnexportedReturnRule{},
2018-05-27 06:28:31 +02:00
&rule.TimeNamingRule{},
&rule.ContextKeysType{},
&rule.ContextAsArgumentRule{},
2018-02-05 01:02:45 +02:00
}
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)
}
2018-02-05 01:02:45 +02:00
if err := assertFailures(t, baseDir, fi, src, rules, map[string]lint.RuleConfig{}); err != nil {
t.Errorf("Linting %s: %v", fi.Name(), err)
}
})
2018-02-05 01:02:45 +02:00
}
}