1
0
mirror of https://github.com/golang/go synced 2024-10-01 20:38:32 -06:00

cmd/compile/internal/amd64: fix for coverage testing

Fix up a unit test to make it more friendly for coverage runs.
Currently on tip if you do

   cd ${GOROOT}/src ; go test -cover cmd/compile/...

it will cause a failure in the TestGoAMD64v1 testpoint of
cmd/compile/internal/amd64, the reason being that this testpoint
copies and reruns the test executable, expecting the rerun to produce
only the output "PASS", whereas if "-cover" is used, the output will
include percentage of statements covered as well. To fix, rework the
test to tolerate additional output if coverage is enabled.

Change-Id: I2512e06ca06e5f38108f2891ff84276d148c4f9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/371234
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2021-12-13 12:03:13 -05:00
parent f909f813a0
commit 3e8aa5dd49

View File

@ -74,8 +74,18 @@ func TestGoAMD64v1(t *testing.T) {
if err != nil {
t.Fatalf("couldn't execute test: %s", err)
}
if string(out) != "PASS\n" {
t.Fatalf("test reported error: %s", string(out))
// Expect to see output of the form "PASS\n", unless the test binary
// was compiled for coverage (in which case there will be an extra line).
success := false
lines := strings.Split(string(out), "\n")
if len(lines) == 2 {
success = lines[0] == "PASS" && lines[1] == ""
} else if len(lines) == 3 {
success = lines[0] == "PASS" &&
strings.HasPrefix(lines[1], "coverage") && lines[2] == ""
}
if !success {
t.Fatalf("test reported error: %s lines=%+v", string(out), lines)
}
}