go/types: exclude some tests when running against Go 1.4

For golang/go#11811.

Change-Id: I130f9608840177cfb7fb9fae30765fcb5aa77411
Reviewed-on: https://go-review.googlesource.com/13008
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Robert Griesemer 2015-07-31 12:41:33 -07:00
parent 680b4cd5a8
commit fe546a3233
1 changed files with 52 additions and 45 deletions

View File

@ -20,9 +20,6 @@
// _ = x /* ERROR "not declared" */ + 1 // _ = x /* ERROR "not declared" */ + 1
// } // }
// TODO(gri) Also collect strict mode errors of the form /* STRICT ... */
// and test against strict mode.
package types_test package types_test
import ( import (
@ -33,6 +30,7 @@ import (
"go/token" "go/token"
"io/ioutil" "io/ioutil"
"regexp" "regexp"
"runtime"
"strings" "strings"
"testing" "testing"
@ -50,40 +48,47 @@ var (
// positions relative to surrounding tokens. // positions relative to surrounding tokens.
// Each tests entry is list of files belonging to the same package. // Each tests entry is list of files belonging to the same package.
var tests = [][]string{ var tests = []struct {
{"testdata/errors.src"}, files string // blank-separated list of file names
{"testdata/importdecl0a.src", "testdata/importdecl0b.src"}, cond func() bool // condition under which the test should be run; nil means always
{"testdata/importdecl1a.src", "testdata/importdecl1b.src"}, }{
{"testdata/cycles.src"}, {"testdata/errors.src", nil},
{"testdata/cycles1.src"}, {"testdata/importdecl0a.src testdata/importdecl0b.src", nil},
{"testdata/cycles2.src"}, {"testdata/importdecl1a.src testdata/importdecl1b.src", nil},
{"testdata/cycles3.src"}, {"testdata/cycles.src", nil},
{"testdata/cycles4.src"}, {"testdata/cycles1.src", nil},
{"testdata/init0.src"}, {"testdata/cycles2.src", nil},
{"testdata/init1.src"}, {"testdata/cycles3.src", nil},
{"testdata/init2.src"}, {"testdata/cycles4.src", nil},
{"testdata/decls0.src"}, {"testdata/init0.src", nil},
{"testdata/decls1.src"}, {"testdata/init1.src", nil},
{"testdata/decls2a.src", "testdata/decls2b.src"}, {"testdata/init2.src", nil},
{"testdata/decls3.src"}, {"testdata/decls0.src", nil},
{"testdata/const0.src"}, {"testdata/decls1.src", nil},
{"testdata/const1.src"}, {"testdata/decls2a.src testdata/decls2b.src", nil},
{"testdata/constdecl.src"}, {"testdata/decls3.src", nil},
{"testdata/vardecl.src"}, {"testdata/const0.src", nil},
{"testdata/expr0.src"}, {"testdata/const1.src", nil},
{"testdata/expr1.src"}, {"testdata/constdecl.src", notGo1_4}, // Go 1.4 parser doesn't report certain errors
{"testdata/expr2.src"}, {"testdata/vardecl.src", notGo1_4}, // Go 1.4 parser doesn't report certain errors
{"testdata/expr3.src"}, {"testdata/expr0.src", nil},
{"testdata/methodsets.src"}, {"testdata/expr1.src", nil},
{"testdata/shifts.src"}, {"testdata/expr2.src", nil},
{"testdata/builtins.src"}, {"testdata/expr3.src", notGo1_4}, // Go 1.4 parser doesn't permit omitting key type in map literals
{"testdata/conversions.src"}, {"testdata/methodsets.src", nil},
{"testdata/stmt0.src"}, {"testdata/shifts.src", nil},
{"testdata/stmt1.src"}, {"testdata/builtins.src", nil},
{"testdata/gotos.src"}, {"testdata/conversions.src", nil},
{"testdata/labels.src"}, {"testdata/stmt0.src", nil},
{"testdata/issues.src"}, {"testdata/stmt1.src", nil},
{"testdata/blank.src"}, {"testdata/gotos.src", nil},
{"testdata/labels.src", nil},
{"testdata/issues.src", nil},
{"testdata/blank.src", nil},
}
func notGo1_4() bool {
return !strings.HasPrefix(runtime.Version(), "go1.4")
} }
var fset = token.NewFileSet() var fset = token.NewFileSet()
@ -104,10 +109,10 @@ func splitError(err error) (pos, msg string) {
return return
} }
func parseFiles(t *testing.T, filenames []string) ([]*ast.File, []error) { func parseFiles(t *testing.T, filenames string) ([]*ast.File, []error) {
var files []*ast.File var files []*ast.File
var errlist []error var errlist []error
for _, filename := range filenames { for _, filename := range strings.Split(filenames, " ") {
file, err := parser.ParseFile(fset, filename, nil, parser.AllErrors) file, err := parser.ParseFile(fset, filename, nil, parser.AllErrors)
if file == nil { if file == nil {
t.Fatalf("%s: %s", filename, err) t.Fatalf("%s: %s", filename, err)
@ -226,9 +231,9 @@ func eliminate(t *testing.T, errmap map[string][]string, errlist []error) {
} }
} }
func checkFiles(t *testing.T, testfiles []string) { func checkFiles(t *testing.T, filenames string) {
// parse files and collect parser errors // parse files and collect parser errors
files, errlist := parseFiles(t, testfiles) files, errlist := parseFiles(t, filenames)
pkgName := "<no package>" pkgName := "<no package>"
if len(files) > 0 { if len(files) > 0 {
@ -284,13 +289,15 @@ func TestCheck(t *testing.T) {
DefPredeclaredTestFuncs() DefPredeclaredTestFuncs()
// If explicit test files are specified, only check those. // If explicit test files are specified, only check those.
if files := *testFiles; files != "" { if *testFiles != "" {
checkFiles(t, strings.Split(files, " ")) checkFiles(t, *testFiles)
return return
} }
// Otherwise, run all the tests. // Otherwise, run all the tests.
for _, files := range tests { for _, test := range tests {
checkFiles(t, files) if test.cond == nil || test.cond() {
checkFiles(t, test.files)
}
} }
} }