diff options
author | Robert Griesemer <gri@golang.org> | 2021-04-30 10:20:38 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-04-30 17:48:17 +0000 |
commit | 95c5f4da80960d0e3511d39c9a9db7280099a37e (patch) | |
tree | c90a2190c539c40532c23bec83efd91edefc5bcb /src/cmd/compile/internal/types2/check_test.go | |
parent | c55d5c887e8644df1e024573dbcf4e6e819371c2 (diff) | |
download | go-95c5f4da80960d0e3511d39c9a9db7280099a37e.tar.gz go-95c5f4da80960d0e3511d39c9a9db7280099a37e.zip |
cmd/compile/internal/types2: list errors by default in TestManual
TestManual is used for debugging; in this case we usually want to
see error messages reported rather than checked against ERROR comments
in the provided files. Make this the default. Use the new -verify
flag to verify reported errors against ERROR comments.
With this change we cannot get an error list for the non-manual
tests, but that is usually not useful anyway because there are
usually many errors in those test files. Run those tests manually
instead.
Also, corrected -lang flag synopsys: it applies to all tests, not
just TestManual.
Change-Id: I56e0ea0583840fc3ea150d9ccfc330370b66191c
Reviewed-on: https://go-review.googlesource.com/c/go/+/315729
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/check_test.go')
-rw-r--r-- | src/cmd/compile/internal/types2/check_test.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/types2/check_test.go b/src/cmd/compile/internal/types2/check_test.go index 0ee579062a..a3a0eea0cc 100644 --- a/src/cmd/compile/internal/types2/check_test.go +++ b/src/cmd/compile/internal/types2/check_test.go @@ -40,9 +40,9 @@ import ( ) var ( - haltOnError = flag.Bool("halt", false, "halt on error") - listErrors = flag.Bool("errlist", false, "list errors") - goVersion = flag.String("lang", "", "Go language version (e.g. \"go1.12\") for TestManual") + haltOnError = flag.Bool("halt", false, "halt on error") + verifyErrors = flag.Bool("verify", false, "verify errors (rather than list them) in TestManual") + goVersion = flag.String("lang", "", "Go language version (e.g. \"go1.12\")") ) func parseFiles(t *testing.T, filenames []string, mode syntax.Mode) ([]*syntax.File, []error) { @@ -96,7 +96,7 @@ func asGoVersion(s string) string { return "" } -func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uint, trace bool) { +func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uint, manual bool) { if len(filenames) == 0 { t.Fatal("no source files") } @@ -118,7 +118,8 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin goVersion = asGoVersion(pkgName) } - if *listErrors && len(errlist) > 0 { + listErrors := manual && !*verifyErrors + if listErrors && len(errlist) > 0 { t.Errorf("--- %s:", pkgName) for _, err := range errlist { t.Error(err) @@ -132,13 +133,13 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin if len(filenames) == 1 && strings.HasSuffix(filenames[0], "importC.src") { conf.FakeImportC = true } - conf.Trace = trace + conf.Trace = manual && testing.Verbose() conf.Importer = defaultImporter() conf.Error = func(err error) { if *haltOnError { defer panic(err) } - if *listErrors { + if listErrors { t.Error(err) return } @@ -146,7 +147,7 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin } conf.Check(pkgName, files, nil) - if *listErrors { + if listErrors { return } @@ -244,8 +245,8 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin // // go test -run Manual -- foo.go bar.go // -// To get an error list rather than having the test check against -// ERROR comments in the input files, provide the -errlist flag. +// Provide the -verify flag to verify errors against ERROR comments in +// the input files rather than having a list of errors reported. // The accepted Go language version can be controlled with the -lang flag. func TestManual(t *testing.T) { filenames := flag.Args() @@ -254,7 +255,7 @@ func TestManual(t *testing.T) { } testenv.MustHaveGoBuild(t) DefPredeclaredTestFuncs() - checkFiles(t, filenames, *goVersion, 0, testing.Verbose()) + checkFiles(t, filenames, *goVersion, 0, true) } // TODO(gri) go/types has extra TestLongConstants and TestIndexRepresentability tests |