20
20
// _ = x /* ERROR "not declared" */ + 1
21
21
// }
22
22
23
- // TODO(gri) Also collect strict mode errors of the form /* STRICT ... */
24
- // and test against strict mode.
25
-
26
23
package types_test
27
24
28
25
import (
@@ -33,6 +30,7 @@ import (
33
30
"go/token"
34
31
"io/ioutil"
35
32
"regexp"
33
+ "runtime"
36
34
"strings"
37
35
"testing"
38
36
@@ -50,40 +48,47 @@ var (
50
48
// positions relative to surrounding tokens.
51
49
52
50
// 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" )
87
92
}
88
93
89
94
var fset = token .NewFileSet ()
@@ -104,10 +109,10 @@ func splitError(err error) (pos, msg string) {
104
109
return
105
110
}
106
111
107
- func parseFiles (t * testing.T , filenames [] string ) ([]* ast.File , []error ) {
112
+ func parseFiles (t * testing.T , filenames string ) ([]* ast.File , []error ) {
108
113
var files []* ast.File
109
114
var errlist []error
110
- for _ , filename := range filenames {
115
+ for _ , filename := range strings . Split ( filenames , " " ) {
111
116
file , err := parser .ParseFile (fset , filename , nil , parser .AllErrors )
112
117
if file == nil {
113
118
t .Fatalf ("%s: %s" , filename , err )
@@ -226,9 +231,9 @@ func eliminate(t *testing.T, errmap map[string][]string, errlist []error) {
226
231
}
227
232
}
228
233
229
- func checkFiles (t * testing.T , testfiles [] string ) {
234
+ func checkFiles (t * testing.T , filenames string ) {
230
235
// parse files and collect parser errors
231
- files , errlist := parseFiles (t , testfiles )
236
+ files , errlist := parseFiles (t , filenames )
232
237
233
238
pkgName := "<no package>"
234
239
if len (files ) > 0 {
@@ -284,13 +289,15 @@ func TestCheck(t *testing.T) {
284
289
DefPredeclaredTestFuncs ()
285
290
286
291
// 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 )
289
294
return
290
295
}
291
296
292
297
// 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
+ }
295
302
}
296
303
}
0 commit comments