]> Cypherpunks repositories - gostls13.git/commitdiff
gotype: support for more tests, added one new test
authorRobert Griesemer <gri@golang.org>
Wed, 30 Mar 2011 22:27:23 +0000 (15:27 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 30 Mar 2011 22:27:23 +0000 (15:27 -0700)
also: minor fix to parser

Note: gotest won't run the gotype test yet until
it permits TestXXX functions where XXX is empty.

R=r
CC=golang-dev
https://golang.org/cl/4300053

src/cmd/gotype/gotype_test.go
src/cmd/gotype/testdata/test1.go [new file with mode: 0644]
src/pkg/go/parser/parser.go

index 96f54ea419afd4f534fb69d289aa345f51d2147a..f5eccab765af434cd044294865f64e9c941f8905 100644 (file)
@@ -20,21 +20,41 @@ func testImporter(importPath string) (string, *ast.Scope, os.Error) {
 }
 
 
-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)
+       }
 }
diff --git a/src/cmd/gotype/testdata/test1.go b/src/cmd/gotype/testdata/test1.go
new file mode 100644 (file)
index 0000000..0bd4656
--- /dev/null
@@ -0,0 +1,6 @@
+package p
+
+func _() {
+       // the scope of a local type declaration starts immediately after the type name
+       type T struct{ _ *T }
+}
index 5b1edace1b6cfbcee28fca1f17146c49bff947ee..fd9ad0f1b529785cc0638ea7c9be33603d3e028c 100644 (file)
@@ -332,7 +332,7 @@ func (p *parser) next() {
                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 {
@@ -2021,11 +2021,12 @@ func parseTypeSpec(p *parser, doc *ast.CommentGroup, _ int) ast.Spec {
        // 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
 }