go.tools/go/types: enable more std lib tests
R=adonovan CC=golang-dev https://golang.org/cl/13798043
This commit is contained in:
parent
c2d7895b1e
commit
26a4f47422
|
@ -16,6 +16,7 @@ import (
|
||||||
"go/scanner"
|
"go/scanner"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -37,6 +38,35 @@ func TestStdlib(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// firstComment returns the contents of the first comment in
|
||||||
|
// the given file, assuming there's one within the first KB.
|
||||||
|
func firstComment(filename string) string {
|
||||||
|
f, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var src [1 << 10]byte // read at most 1KB
|
||||||
|
n, _ := f.Read(src[:])
|
||||||
|
|
||||||
|
var s scanner.Scanner
|
||||||
|
s.Init(fset.AddFile("", fset.Base(), n), src[:n], nil, scanner.ScanComments)
|
||||||
|
for {
|
||||||
|
_, tok, lit := s.Scan()
|
||||||
|
switch tok {
|
||||||
|
case token.COMMENT:
|
||||||
|
// remove trailing */ of multi-line comment
|
||||||
|
if lit[1] == '*' {
|
||||||
|
lit = lit[:len(lit)-2]
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(lit[2:])
|
||||||
|
case token.EOF:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testTestDir(t *testing.T, path string, ignore ...string) {
|
func testTestDir(t *testing.T, path string, ignore ...string) {
|
||||||
files, err := ioutil.ReadDir(path)
|
files, err := ioutil.ReadDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,29 +85,20 @@ func testTestDir(t *testing.T, path string, ignore ...string) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse file
|
// get per-file instructions
|
||||||
filename := filepath.Join(path, f.Name())
|
|
||||||
// TODO(gri) The parser loses comments when bailing out early,
|
|
||||||
// and then we don't see the errorcheck command for
|
|
||||||
// some files. Use parser.AllErrors for now. Fix this.
|
|
||||||
file, err := parser.ParseFile(fset, filename, nil, parser.ParseComments|parser.AllErrors)
|
|
||||||
|
|
||||||
// check per-file instructions
|
|
||||||
// For now we only check some cases.
|
|
||||||
expectErrors := false
|
expectErrors := false
|
||||||
if len(file.Comments) > 0 {
|
filename := filepath.Join(path, f.Name())
|
||||||
if group := file.Comments[0]; len(group.List) > 0 {
|
if cmd := firstComment(filename); cmd != "" {
|
||||||
cmd := strings.TrimSpace(group.List[0].Text[2:]) // 2: ignore // or /* of comment
|
switch cmd {
|
||||||
switch cmd {
|
case "skip", "compiledir":
|
||||||
case "skip", "compiledir":
|
continue // ignore this file
|
||||||
continue
|
case "errorcheck":
|
||||||
case "errorcheck":
|
expectErrors = true
|
||||||
expectErrors = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// type-check file if it parsed cleanly
|
// parse and type-check file
|
||||||
|
file, err := parser.ParseFile(fset, filename, nil, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_, err = Check(filename, fset, []*ast.File{file})
|
_, err = Check(filename, fset, []*ast.File{file})
|
||||||
}
|
}
|
||||||
|
@ -106,9 +127,6 @@ func TestStdtest(t *testing.T) {
|
||||||
|
|
||||||
func TestStdfixed(t *testing.T) {
|
func TestStdfixed(t *testing.T) {
|
||||||
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
|
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
|
||||||
"bug050.go", "bug088.go", "bug106.go", // TODO(gri) parser loses comments when bailing out early
|
|
||||||
"bug222.go", "bug282.go", "bug306.go", // TODO(gri) parser loses comments when bailing out early
|
|
||||||
"issue4776.go", // TODO(gri) parser loses comments when bailing out early
|
|
||||||
"bug136.go", "bug179.go", "bug344.go", // TODO(gri) implement missing label checks
|
"bug136.go", "bug179.go", "bug344.go", // TODO(gri) implement missing label checks
|
||||||
"bug251.go", // TODO(gri) incorrect cycle checks for interface types
|
"bug251.go", // TODO(gri) incorrect cycle checks for interface types
|
||||||
"bug165.go", // TODO(gri) isComparable not working for incomplete struct type
|
"bug165.go", // TODO(gri) isComparable not working for incomplete struct type
|
||||||
|
|
Loading…
Reference in New Issue