aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/check_test.go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2021-01-12 09:20:22 -0500
committerRobert Findley <rfindley@google.com>2021-01-20 15:51:34 +0000
commitfa01ade41e1632dbb8e1b06ff1e6565e8900fb38 (patch)
tree12828dcaa39e1c580a472446d39838411c35dd68 /src/go/types/check_test.go
parent734cb8be0a05f6dba241a14f94a1d238a41d4ded (diff)
downloadgo-fa01ade41e1632dbb8e1b06ff1e6565e8900fb38.tar.gz
go-fa01ade41e1632dbb8e1b06ff1e6565e8900fb38.zip
[dev.typeparams] go/types: add tests from dev.go2go
Add tests from the dev.go2go branch, modified to eliminate support for parenthesized type embedding and method type parameters. For the most part these tests were made to pass via the fixes from preceding CLs in this stack. While integrating support for type parameters with the changes to go/types in master, a decision was made to temporarily use an error code of 0 for new error messages. Now that these messages are actually emitted during checking of test packages, it is a test failure for them to have an error code of 0. To satisfy the test, create a new temporary error code '_Todo', which represents an error code that has not yet been assigned. _Todo is added only where it was necessary to make tests pass: many error codes were left as 0, meaning we don't have any tests that produce them. This marker may help us produce more comprehensive tests in the future. Finally, each package checked by testDir was made into a subtest, for the ease of running individual packages while debugging test failures. This seemed worth keeping. Change-Id: Iba421b797e9fb11af664a73902f67d6c4f30ecad Reviewed-on: https://go-review.googlesource.com/c/go/+/283854 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/go/types/check_test.go')
-rw-r--r--src/go/types/check_test.go44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go
index 66943d676c..51eae052f3 100644
--- a/src/go/types/check_test.go
+++ b/src/go/types/check_test.go
@@ -68,11 +68,11 @@ func splitError(err error) (pos, msg string) {
return
}
-func parseFiles(t *testing.T, filenames []string) ([]*ast.File, []error) {
+func parseFiles(t *testing.T, filenames []string, mode parser.Mode) ([]*ast.File, []error) {
var files []*ast.File
var errlist []error
for _, filename := range filenames {
- file, err := parser.ParseFile(fset, filename, nil, parser.AllErrors)
+ file, err := parser.ParseFile(fset, filename, nil, mode)
if file == nil {
t.Fatalf("%s: %s", filename, err)
}
@@ -191,8 +191,17 @@ func eliminate(t *testing.T, errmap map[string][]string, errlist []error) {
}
func checkFiles(t *testing.T, sources []string) {
+ if len(sources) == 0 {
+ t.Fatal("no source files")
+ }
+
+ mode := parser.AllErrors
+ if strings.HasSuffix(sources[0], ".go2") {
+ mode |= parser.ParseTypeParams
+ }
+
// parse files and collect parser errors
- files, errlist := parseFiles(t, sources)
+ files, errlist := parseFiles(t, sources, mode)
pkgName := "<no package>"
if len(files) > 0 {
@@ -208,7 +217,6 @@ func checkFiles(t *testing.T, sources []string) {
// typecheck and collect typechecker errors
var conf Config
- // TODO(rFindley) parse generics when given a .go2 suffix.
// special case for importC.src
if len(sources) == 1 && strings.HasSuffix(sources[0], "importC.src") {
@@ -274,11 +282,8 @@ func TestCheck(t *testing.T) {
checkFiles(t, strings.Split(*testFiles, " "))
}
-func TestTestdata(t *testing.T) { DefPredeclaredTestFuncs(); testDir(t, "testdata") }
-
-// TODO(rFindley) add go2 examples.
-// func TestExamples(t *testing.T) { testDir(t, "examples") }
-
+func TestTestdata(t *testing.T) { DefPredeclaredTestFuncs(); testDir(t, "testdata") }
+func TestExamples(t *testing.T) { testDir(t, "examples") }
func TestFixedbugs(t *testing.T) { testDir(t, "fixedbugs") }
func testDir(t *testing.T, dir string) {
@@ -290,20 +295,18 @@ func testDir(t *testing.T, dir string) {
return
}
- for count, fi := range fis {
+ for _, fi := range fis {
path := filepath.Join(dir, fi.Name())
// if fi is a directory, its files make up a single package
+ var files []string
if fi.IsDir() {
- if testing.Verbose() {
- fmt.Printf("%3d %s\n", count, path)
- }
fis, err := ioutil.ReadDir(path)
if err != nil {
t.Error(err)
continue
}
- files := make([]string, len(fis))
+ files = make([]string, len(fis))
for i, fi := range fis {
// if fi is a directory, checkFiles below will complain
files[i] = filepath.Join(path, fi.Name())
@@ -311,14 +314,11 @@ func testDir(t *testing.T, dir string) {
fmt.Printf("\t%s\n", files[i])
}
}
- checkFiles(t, files)
- continue
- }
-
- // otherwise, fi is a stand-alone file
- if testing.Verbose() {
- fmt.Printf("%3d %s\n", count, path)
+ } else {
+ files = []string{path}
}
- checkFiles(t, []string{path})
+ t.Run(filepath.Base(path), func(t *testing.T) {
+ checkFiles(t, files)
+ })
}
}