]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: list errors by default in TestManual
authorRobert Griesemer <gri@golang.org>
Fri, 30 Apr 2021 17:20:38 +0000 (10:20 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 30 Apr 2021 17:48:17 +0000 (17:48 +0000)
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>
src/cmd/compile/internal/types2/check_test.go

index 0ee579062af418d414dcb7a8a3ed4d90447ace53..a3a0eea0cc51e0d94192d9b4b52a6cbc1b37d0e8 100644 (file)
@@ -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