mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
c55d5c887e
commit
95c5f4da80
1 changed files with 12 additions and 11 deletions
|
|
@ -41,8 +41,8 @@ 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\")")
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseFiles(t *testing.T, filenames []string, mode syntax.Mode) ([]*syntax.File, []error) {
|
func parseFiles(t *testing.T, filenames []string, mode syntax.Mode) ([]*syntax.File, []error) {
|
||||||
|
|
@ -96,7 +96,7 @@ func asGoVersion(s string) string {
|
||||||
return ""
|
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 {
|
if len(filenames) == 0 {
|
||||||
t.Fatal("no source files")
|
t.Fatal("no source files")
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +118,8 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin
|
||||||
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)
|
||||||
|
|
@ -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") {
|
if len(filenames) == 1 && strings.HasSuffix(filenames[0], "importC.src") {
|
||||||
conf.FakeImportC = true
|
conf.FakeImportC = true
|
||||||
}
|
}
|
||||||
conf.Trace = trace
|
conf.Trace = manual && testing.Verbose()
|
||||||
conf.Importer = defaultImporter()
|
conf.Importer = defaultImporter()
|
||||||
conf.Error = func(err error) {
|
conf.Error = func(err error) {
|
||||||
if *haltOnError {
|
if *haltOnError {
|
||||||
defer panic(err)
|
defer panic(err)
|
||||||
}
|
}
|
||||||
if *listErrors {
|
if listErrors {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +147,7 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin
|
||||||
}
|
}
|
||||||
conf.Check(pkgName, files, nil)
|
conf.Check(pkgName, files, nil)
|
||||||
|
|
||||||
if *listErrors {
|
if listErrors {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -244,8 +245,8 @@ func checkFiles(t *testing.T, filenames []string, goVersion string, colDelta uin
|
||||||
//
|
//
|
||||||
// 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()
|
||||||
|
|
@ -254,7 +255,7 @@ func TestManual(t *testing.T) {
|
||||||
}
|
}
|
||||||
testenv.MustHaveGoBuild(t)
|
testenv.MustHaveGoBuild(t)
|
||||||
DefPredeclaredTestFuncs()
|
DefPredeclaredTestFuncs()
|
||||||
checkFiles(t, filenames, *goVersion, 0, testing.Verbose())
|
checkFiles(t, filenames, *goVersion, 0, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(gri) go/types has extra TestLongConstants and TestIndexRepresentability tests
|
// TODO(gri) go/types has extra TestLongConstants and TestIndexRepresentability tests
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue