Skip to content

Commit fe546a3

Browse files
committed
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 <[email protected]>
1 parent 680b4cd commit fe546a3

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed

Diff for: go/types/check_test.go

+52-45
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
// _ = x /* ERROR "not declared" */ + 1
2121
// }
2222

23-
// TODO(gri) Also collect strict mode errors of the form /* STRICT ... */
24-
// and test against strict mode.
25-
2623
package types_test
2724

2825
import (
@@ -33,6 +30,7 @@ import (
3330
"go/token"
3431
"io/ioutil"
3532
"regexp"
33+
"runtime"
3634
"strings"
3735
"testing"
3836

@@ -50,40 +48,47 @@ var (
5048
// positions relative to surrounding tokens.
5149

5250
// Each tests entry is list of files belonging to the same package.
53-
var tests = [][]string{
54-
{"testdata/errors.src"},
55-
{"testdata/importdecl0a.src", "testdata/importdecl0b.src"},
56-
{"testdata/importdecl1a.src", "testdata/importdecl1b.src"},
57-
{"testdata/cycles.src"},
58-
{"testdata/cycles1.src"},
59-
{"testdata/cycles2.src"},
60-
{"testdata/cycles3.src"},
61-
{"testdata/cycles4.src"},
62-
{"testdata/init0.src"},
63-
{"testdata/init1.src"},
64-
{"testdata/init2.src"},
65-
{"testdata/decls0.src"},
66-
{"testdata/decls1.src"},
67-
{"testdata/decls2a.src", "testdata/decls2b.src"},
68-
{"testdata/decls3.src"},
69-
{"testdata/const0.src"},
70-
{"testdata/const1.src"},
71-
{"testdata/constdecl.src"},
72-
{"testdata/vardecl.src"},
73-
{"testdata/expr0.src"},
74-
{"testdata/expr1.src"},
75-
{"testdata/expr2.src"},
76-
{"testdata/expr3.src"},
77-
{"testdata/methodsets.src"},
78-
{"testdata/shifts.src"},
79-
{"testdata/builtins.src"},
80-
{"testdata/conversions.src"},
81-
{"testdata/stmt0.src"},
82-
{"testdata/stmt1.src"},
83-
{"testdata/gotos.src"},
84-
{"testdata/labels.src"},
85-
{"testdata/issues.src"},
86-
{"testdata/blank.src"},
51+
var tests = []struct {
52+
files string // blank-separated list of file names
53+
cond func() bool // condition under which the test should be run; nil means always
54+
}{
55+
{"testdata/errors.src", nil},
56+
{"testdata/importdecl0a.src testdata/importdecl0b.src", nil},
57+
{"testdata/importdecl1a.src testdata/importdecl1b.src", nil},
58+
{"testdata/cycles.src", nil},
59+
{"testdata/cycles1.src", nil},
60+
{"testdata/cycles2.src", nil},
61+
{"testdata/cycles3.src", nil},
62+
{"testdata/cycles4.src", nil},
63+
{"testdata/init0.src", nil},
64+
{"testdata/init1.src", nil},
65+
{"testdata/init2.src", nil},
66+
{"testdata/decls0.src", nil},
67+
{"testdata/decls1.src", nil},
68+
{"testdata/decls2a.src testdata/decls2b.src", nil},
69+
{"testdata/decls3.src", nil},
70+
{"testdata/const0.src", nil},
71+
{"testdata/const1.src", nil},
72+
{"testdata/constdecl.src", notGo1_4}, // Go 1.4 parser doesn't report certain errors
73+
{"testdata/vardecl.src", notGo1_4}, // Go 1.4 parser doesn't report certain errors
74+
{"testdata/expr0.src", nil},
75+
{"testdata/expr1.src", nil},
76+
{"testdata/expr2.src", nil},
77+
{"testdata/expr3.src", notGo1_4}, // Go 1.4 parser doesn't permit omitting key type in map literals
78+
{"testdata/methodsets.src", nil},
79+
{"testdata/shifts.src", nil},
80+
{"testdata/builtins.src", nil},
81+
{"testdata/conversions.src", nil},
82+
{"testdata/stmt0.src", nil},
83+
{"testdata/stmt1.src", nil},
84+
{"testdata/gotos.src", nil},
85+
{"testdata/labels.src", nil},
86+
{"testdata/issues.src", nil},
87+
{"testdata/blank.src", nil},
88+
}
89+
90+
func notGo1_4() bool {
91+
return !strings.HasPrefix(runtime.Version(), "go1.4")
8792
}
8893

8994
var fset = token.NewFileSet()
@@ -104,10 +109,10 @@ func splitError(err error) (pos, msg string) {
104109
return
105110
}
106111

107-
func parseFiles(t *testing.T, filenames []string) ([]*ast.File, []error) {
112+
func parseFiles(t *testing.T, filenames string) ([]*ast.File, []error) {
108113
var files []*ast.File
109114
var errlist []error
110-
for _, filename := range filenames {
115+
for _, filename := range strings.Split(filenames, " ") {
111116
file, err := parser.ParseFile(fset, filename, nil, parser.AllErrors)
112117
if file == nil {
113118
t.Fatalf("%s: %s", filename, err)
@@ -226,9 +231,9 @@ func eliminate(t *testing.T, errmap map[string][]string, errlist []error) {
226231
}
227232
}
228233

229-
func checkFiles(t *testing.T, testfiles []string) {
234+
func checkFiles(t *testing.T, filenames string) {
230235
// parse files and collect parser errors
231-
files, errlist := parseFiles(t, testfiles)
236+
files, errlist := parseFiles(t, filenames)
232237

233238
pkgName := "<no package>"
234239
if len(files) > 0 {
@@ -284,13 +289,15 @@ func TestCheck(t *testing.T) {
284289
DefPredeclaredTestFuncs()
285290

286291
// If explicit test files are specified, only check those.
287-
if files := *testFiles; files != "" {
288-
checkFiles(t, strings.Split(files, " "))
292+
if *testFiles != "" {
293+
checkFiles(t, *testFiles)
289294
return
290295
}
291296

292297
// Otherwise, run all the tests.
293-
for _, files := range tests {
294-
checkFiles(t, files)
298+
for _, test := range tests {
299+
if test.cond == nil || test.cond() {
300+
checkFiles(t, test.files)
301+
}
295302
}
296303
}

0 commit comments

Comments
 (0)