lint/testutil: typecheck code once for all Go versions
@@ -63,13 +63,10 @@ func TestAll(t *testing.T, c lint.Checker, dir string) {
files[v] = append(files[v], fi)
}
- for version, fis := range files {
- l := &lint.Linter{Checker: c, GoVersion: version}
-
conf := &loader.Config{
ParserMode: parser.ParseComments,
}
- files := map[string][]byte{}
+ sources := map[string][]byte{}
for _, fi := range fis {
filename := path.Join(baseDir, fi.Name())
src, err := ioutil.ReadFile(filename)
@@ -82,7 +79,7 @@ func TestAll(t *testing.T, c lint.Checker, dir string) {
t.Errorf("error parsing %s: %s", filename, err)
continue
}
- files[fi.Name()] = src
+ sources[fi.Name()] = src
conf.CreateFromFiles(fi.Name(), f)
}
@@ -90,8 +87,15 @@ func TestAll(t *testing.T, c lint.Checker, dir string) {
if err != nil {
t.Fatalf("error loading program: %s", err)
}
+
+ for version, fis := range files {
+ l := &lint.Linter{Checker: c, GoVersion: version}
+
res := l.Lint(lprog)
- for name, src := range files {
+ for _, fi := range fis {
+ name := fi.Name()
+ src := sources[name]
+
ins := parseInstructions(t, name, src)
for _, in := range ins {
@@ -118,7 +122,13 @@ func TestAll(t *testing.T, c lint.Checker, dir string) {
}
for _, p := range res {
pos := lprog.Fset.Position(p.Position)
+ name := filepath.Base(pos.Filename)
+ for _, fi := range fis {
+ if name == fi.Name() {
t.Errorf("Unexpected problem at %s: %v", pos, p.Text)
+ break
+ }
+ }
}
}
}
