Skip to content

Commit d586aae

Browse files
committed
test: errorcheck auto-generated functions
Add an "errorcheckwithauto" action which performs error check including lines with auto-generated functions (excluded by default). Comment "// ERRORAUTO" matches these lines. Add testcase for CL 29570 (as an example). Updates #16016, #17186. Change-Id: Iaba3727336cd602f3dda6b9e5f97dafe0848e632 Reviewed-on: https://go-review.googlesource.com/29652 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 3dfb92f commit d586aae

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

test/live.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// errorcheck -0 -l -live -wb=0
1+
// errorcheckwithauto -0 -l -live -wb=0
22
// +build !ppc64,!ppc64le
33
// ppc64 needs a better tighten pass to make f18 pass
44

@@ -658,3 +658,10 @@ func ddd1(x, y *int) { // ERROR "live at entry to ddd1: x y$"
658658
func ddd2(a ...*int) { // ERROR "live at entry to ddd2: a$"
659659
sink = a[0]
660660
}
661+
662+
// issue 16016: autogenerated wrapper should have arguments live
663+
type T struct{}
664+
665+
func (*T) Foo(ptr *int) {}
666+
667+
type R struct{ *T } // ERRORAUTO "live at entry to \(\*R\)\.Foo: \.this ptr" "live at entry to R\.Foo: \.this ptr"

test/run.go

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ type test struct {
242242
donec chan bool // closed when done
243243
dt time.Duration
244244

245-
src string
246-
action string // "compile", "build", etc.
245+
src string
247246

248247
tempDir string
249248
err error
@@ -457,15 +456,15 @@ func (t *test) run() {
457456
pkgPos = pos // some files are intentionally malformed
458457
}
459458
if ok, why := shouldTest(t.src[:pkgPos], goos, goarch); !ok {
460-
t.action = "skip"
461459
if *showSkips {
462-
fmt.Printf("%-20s %-20s: %s\n", t.action, t.goFileName(), why)
460+
fmt.Printf("%-20s %-20s: %s\n", "skip", t.goFileName(), why)
463461
}
464462
return
465463
}
466464

467465
var args, flags []string
468466
wantError := false
467+
wantAuto := false
469468
singlefilepkgs := false
470469
f := strings.Fields(action)
471470
if len(f) > 0 {
@@ -477,27 +476,25 @@ func (t *test) run() {
477476
switch action {
478477
case "rundircmpout":
479478
action = "rundir"
480-
t.action = "rundir"
481479
case "cmpout":
482480
action = "run" // the run case already looks for <dir>/<test>.out files
483-
fallthrough
484481
case "compile", "compiledir", "build", "run", "runoutput", "rundir":
485-
t.action = action
482+
// nothing to do
486483
case "errorcheckandrundir":
487484
wantError = false // should be no error if also will run
488-
fallthrough
485+
case "errorcheckwithauto":
486+
action = "errorcheck"
487+
wantAuto = true
488+
wantError = true
489489
case "errorcheck", "errorcheckdir", "errorcheckoutput":
490-
t.action = action
491490
wantError = true
492491
case "skip":
493492
if *runSkips {
494493
break
495494
}
496-
t.action = "skip"
497495
return
498496
default:
499497
t.err = skipError("skipped; unknown pattern: " + action)
500-
t.action = "??"
501498
return
502499
}
503500

@@ -574,7 +571,7 @@ func (t *test) run() {
574571
if *updateErrors {
575572
t.updateErrors(string(out), long)
576573
}
577-
t.err = t.errorCheck(string(out), long, t.gofile)
574+
t.err = t.errorCheck(string(out), wantAuto, long, t.gofile)
578575
return
579576

580577
case "compile":
@@ -622,7 +619,7 @@ func (t *test) run() {
622619
for _, name := range gofiles {
623620
fullshort = append(fullshort, filepath.Join(longdir, name), name)
624621
}
625-
t.err = t.errorCheck(string(out), fullshort...)
622+
t.err = t.errorCheck(string(out), wantAuto, fullshort...)
626623
if t.err != nil {
627624
break
628625
}
@@ -758,7 +755,7 @@ func (t *test) run() {
758755
return
759756
}
760757
}
761-
t.err = t.errorCheck(string(out), tfile, "tmp__.go")
758+
t.err = t.errorCheck(string(out), false, tfile, "tmp__.go")
762759
return
763760
}
764761
}
@@ -801,7 +798,7 @@ func (t *test) expectedOutput() string {
801798
return string(b)
802799
}
803800

804-
func splitOutput(out string) []string {
801+
func splitOutput(out string, wantAuto bool) []string {
805802
// gc error messages continue onto additional lines with leading tabs.
806803
// Split the output at the beginning of each line that doesn't begin with a tab.
807804
// <autogenerated> lines are impossible to match so those are filtered out.
@@ -812,7 +809,7 @@ func splitOutput(out string) []string {
812809
}
813810
if strings.HasPrefix(line, "\t") {
814811
res[len(res)-1] += "\n" + line
815-
} else if strings.HasPrefix(line, "go tool") || strings.HasPrefix(line, "<autogenerated>") || strings.HasPrefix(line, "#") {
812+
} else if strings.HasPrefix(line, "go tool") || strings.HasPrefix(line, "#") || !wantAuto && strings.HasPrefix(line, "<autogenerated>") {
816813
continue
817814
} else if strings.TrimSpace(line) != "" {
818815
res = append(res, line)
@@ -821,14 +818,14 @@ func splitOutput(out string) []string {
821818
return res
822819
}
823820

824-
func (t *test) errorCheck(outStr string, fullshort ...string) (err error) {
821+
func (t *test) errorCheck(outStr string, wantAuto bool, fullshort ...string) (err error) {
825822
defer func() {
826823
if *verbose && err != nil {
827824
log.Printf("%s gc output:\n%s", t, outStr)
828825
}
829826
}()
830827
var errs []error
831-
out := splitOutput(outStr)
828+
out := splitOutput(outStr, wantAuto)
832829

833830
// Cut directory name.
834831
for i := range out {
@@ -846,7 +843,11 @@ func (t *test) errorCheck(outStr string, fullshort ...string) (err error) {
846843

847844
for _, we := range want {
848845
var errmsgs []string
849-
errmsgs, out = partitionStrings(we.prefix, out)
846+
if we.auto {
847+
errmsgs, out = partitionStrings("<autogenerated>", out)
848+
} else {
849+
errmsgs, out = partitionStrings(we.prefix, out)
850+
}
850851
if len(errmsgs) == 0 {
851852
errs = append(errs, fmt.Errorf("%s:%d: missing error %q", we.file, we.lineNum, we.reStr))
852853
continue
@@ -906,7 +907,7 @@ func (t *test) updateErrors(out, file string) {
906907
// Parse new errors.
907908
errors := make(map[int]map[string]bool)
908909
tmpRe := regexp.MustCompile(`autotmp_[0-9]+`)
909-
for _, errStr := range splitOutput(out) {
910+
for _, errStr := range splitOutput(out, false) {
910911
colon1 := strings.Index(errStr, ":")
911912
if colon1 < 0 || errStr[:colon1] != file {
912913
continue
@@ -991,12 +992,14 @@ type wantedError struct {
991992
reStr string
992993
re *regexp.Regexp
993994
lineNum int
995+
auto bool // match <autogenerated> line
994996
file string
995997
prefix string
996998
}
997999

9981000
var (
9991001
errRx = regexp.MustCompile(`// (?:GC_)?ERROR (.*)`)
1002+
errAutoRx = regexp.MustCompile(`// (?:GC_)?ERRORAUTO (.*)`)
10001003
errQuotesRx = regexp.MustCompile(`"([^"]*)"`)
10011004
lineRx = regexp.MustCompile(`LINE(([+-])([0-9]+))?`)
10021005
)
@@ -1011,7 +1014,13 @@ func (t *test) wantedErrors(file, short string) (errs []wantedError) {
10111014
// double comment disables ERROR
10121015
continue
10131016
}
1014-
m := errRx.FindStringSubmatch(line)
1017+
var auto bool
1018+
m := errAutoRx.FindStringSubmatch(line)
1019+
if m != nil {
1020+
auto = true
1021+
} else {
1022+
m = errRx.FindStringSubmatch(line)
1023+
}
10151024
if m == nil {
10161025
continue
10171026
}
@@ -1046,6 +1055,7 @@ func (t *test) wantedErrors(file, short string) (errs []wantedError) {
10461055
reStr: rx,
10471056
re: re,
10481057
prefix: prefix,
1058+
auto: auto,
10491059
lineNum: lineNum,
10501060
file: short,
10511061
})

0 commit comments

Comments
 (0)