}
-func testDir(t *testing.T, dir, pkg string) {
+func runTest(t *testing.T, path, pkg string) {
exitCode = 0
*pkgName = pkg
*recursive = false
importer = testImporter
- processDirectory(dir)
+
+ if pkg == "" {
+ processFiles([]string{path}, true)
+ } else {
+ processDirectory(path)
+ }
+
if exitCode != 0 {
- t.Errorf("processing %s failed: exitCode = %d", dir, exitCode)
+ t.Errorf("processing %s failed: exitCode = %d", path, exitCode)
}
}
+var tests = []struct {
+ path string
+ pkg string
+}{
+ // individual files
+ {"testdata/test1.go", ""},
+
+ // directories
+ {filepath.Join(runtime.GOROOT(), "src/pkg/go/ast"), "ast"},
+ {filepath.Join(runtime.GOROOT(), "src/pkg/go/token"), "scanner"},
+ {filepath.Join(runtime.GOROOT(), "src/pkg/go/scanner"), "scanner"},
+ {filepath.Join(runtime.GOROOT(), "src/pkg/go/parser"), "parser"},
+}
+
+
func Test(t *testing.T) {
- testDir(t, filepath.Join(runtime.GOROOT(), "src/pkg/go/ast"), "ast")
- testDir(t, filepath.Join(runtime.GOROOT(), "src/pkg/go/token"), "scanner")
- testDir(t, filepath.Join(runtime.GOROOT(), "src/pkg/go/scanner"), "scanner")
- testDir(t, filepath.Join(runtime.GOROOT(), "src/pkg/go/parser"), "parser")
+ for _, test := range tests {
+ runTest(t, test.path, test.pkg)
+ }
}
var endline int
if p.file.Line(p.pos) == line {
- // The comment is on same line as previous token; it
+ // The comment is on same line as the previous token; it
// cannot be a lead comment but may be a line comment.
comment, endline = p.consumeCommentGroup()
if p.file.Line(p.pos) != endline {
// at the identifier in the TypeSpec and ends at the end of the innermost
// containing block.
// (Global identifiers are resolved in a separate phase after parsing.)
- spec := &ast.TypeSpec{doc, ident, nil, p.lineComment}
+ spec := &ast.TypeSpec{doc, ident, nil, nil}
p.declare(spec, p.topScope, ast.Typ, ident)
spec.Type = p.parseType()
p.expectSemi() // call before accessing p.linecomment
+ spec.Comment = p.lineComment
return spec
}