1
0
mirror of https://github.com/golang/go synced 2024-11-23 03:40:02 -07:00

go/types: list errors by default in TestManual

This is a port of CL 315729 to go/types, adjusted for the slightly
different test set-up in go/types.

Added a TODO to reconcile these differences.

Change-Id: I71cae712d8fc23b7311ce35e09168b258e07fa35
Reviewed-on: https://go-review.googlesource.com/c/go/+/315850
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Rob Findley 2021-04-30 15:38:11 -04:00 committed by Robert Findley
parent a9db5a7386
commit 879db69ce2

View File

@ -46,7 +46,7 @@ import (
var ( var (
haltOnError = flag.Bool("halt", false, "halt on error") haltOnError = flag.Bool("halt", false, "halt on error")
listErrors = flag.Bool("errlist", false, "list errors") verifyErrors = flag.Bool("verify", false, "verify errors (rather than list them) in TestManual")
goVersion = flag.String("lang", "", "Go language version (e.g. \"go1.12\") for TestManual") goVersion = flag.String("lang", "", "Go language version (e.g. \"go1.12\") for TestManual")
) )
@ -202,7 +202,7 @@ func asGoVersion(s string) string {
return "" return ""
} }
func checkFiles(t *testing.T, sizes Sizes, goVersion string, filenames []string, srcs [][]byte) { func checkFiles(t *testing.T, sizes Sizes, goVersion string, filenames []string, srcs [][]byte, manual bool) {
if len(filenames) == 0 { if len(filenames) == 0 {
t.Fatal("no source files") t.Fatal("no source files")
} }
@ -229,7 +229,8 @@ func checkFiles(t *testing.T, sizes Sizes, goVersion string, filenames []string,
goVersion = asGoVersion(pkgName) goVersion = asGoVersion(pkgName)
} }
if *listErrors && len(errlist) > 0 { listErrors := manual && !*verifyErrors
if listErrors && len(errlist) > 0 {
t.Errorf("--- %s:", pkgName) t.Errorf("--- %s:", pkgName)
for _, err := range errlist { for _, err := range errlist {
t.Error(err) t.Error(err)
@ -253,7 +254,7 @@ func checkFiles(t *testing.T, sizes Sizes, goVersion string, filenames []string,
if *haltOnError { if *haltOnError {
defer panic(err) defer panic(err)
} }
if *listErrors { if listErrors {
t.Error(err) t.Error(err)
return return
} }
@ -265,7 +266,7 @@ func checkFiles(t *testing.T, sizes Sizes, goVersion string, filenames []string,
} }
conf.Check(pkgName, fset, files, nil) conf.Check(pkgName, fset, files, nil)
if *listErrors { if listErrors {
return return
} }
@ -302,8 +303,8 @@ func checkFiles(t *testing.T, sizes Sizes, goVersion string, filenames []string,
// //
// go test -run Manual -- foo.go bar.go // go test -run Manual -- foo.go bar.go
// //
// To get an error list rather than having the test check against // Provide the -verify flag to verify errors against ERROR comments in
// ERROR comments in the input files, provide the -errlist flag. // the input files rather than having a list of errors reported.
// The accepted Go language version can be controlled with the -lang flag. // The accepted Go language version can be controlled with the -lang flag.
func TestManual(t *testing.T) { func TestManual(t *testing.T) {
filenames := flag.Args() filenames := flag.Args()
@ -312,13 +313,13 @@ func TestManual(t *testing.T) {
} }
testenv.MustHaveGoBuild(t) testenv.MustHaveGoBuild(t)
DefPredeclaredTestFuncs() DefPredeclaredTestFuncs()
testPkg(t, filenames, *goVersion) testPkg(t, filenames, *goVersion, true)
} }
func TestLongConstants(t *testing.T) { func TestLongConstants(t *testing.T) {
format := "package longconst\n\nconst _ = %s\nconst _ = %s // ERROR excessively long constant" format := "package longconst\n\nconst _ = %s\nconst _ = %s // ERROR excessively long constant"
src := fmt.Sprintf(format, strings.Repeat("1", 9999), strings.Repeat("1", 10001)) src := fmt.Sprintf(format, strings.Repeat("1", 9999), strings.Repeat("1", 10001))
checkFiles(t, nil, "", []string{"longconst.go"}, [][]byte{[]byte(src)}) checkFiles(t, nil, "", []string{"longconst.go"}, [][]byte{[]byte(src)}, false)
} }
// TestIndexRepresentability tests that constant index operands must // TestIndexRepresentability tests that constant index operands must
@ -326,7 +327,7 @@ func TestLongConstants(t *testing.T) {
// represent larger values. // represent larger values.
func TestIndexRepresentability(t *testing.T) { func TestIndexRepresentability(t *testing.T) {
const src = "package index\n\nvar s []byte\nvar _ = s[int64 /* ERROR \"int64\\(1\\) << 40 \\(.*\\) overflows int\" */ (1) << 40]" const src = "package index\n\nvar s []byte\nvar _ = s[int64 /* ERROR \"int64\\(1\\) << 40 \\(.*\\) overflows int\" */ (1) << 40]"
checkFiles(t, &StdSizes{4, 4}, "", []string{"index.go"}, [][]byte{[]byte(src)}) checkFiles(t, &StdSizes{4, 4}, "", []string{"index.go"}, [][]byte{[]byte(src)}, false)
} }
func TestCheck(t *testing.T) { DefPredeclaredTestFuncs(); testDir(t, "check") } func TestCheck(t *testing.T) { DefPredeclaredTestFuncs(); testDir(t, "check") }
@ -361,12 +362,13 @@ func testDir(t *testing.T, dir string) {
filenames = []string{path} filenames = []string{path}
} }
t.Run(filepath.Base(path), func(t *testing.T) { t.Run(filepath.Base(path), func(t *testing.T) {
testPkg(t, filenames, "") testPkg(t, filenames, "", false)
}) })
} }
} }
func testPkg(t *testing.T, filenames []string, goVersion string) { // TODO(rFindley) reconcile the different test setup in go/types with types2.
func testPkg(t *testing.T, filenames []string, goVersion string, manual bool) {
srcs := make([][]byte, len(filenames)) srcs := make([][]byte, len(filenames))
for i, filename := range filenames { for i, filename := range filenames {
src, err := os.ReadFile(filename) src, err := os.ReadFile(filename)
@ -375,5 +377,5 @@ func testPkg(t *testing.T, filenames []string, goVersion string) {
} }
srcs[i] = src srcs[i] = src
} }
checkFiles(t, nil, goVersion, filenames, srcs) checkFiles(t, nil, goVersion, filenames, srcs, manual)
} }