]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/amd64: fix for coverage testing
authorThan McIntosh <thanm@google.com>
Mon, 13 Dec 2021 17:03:13 +0000 (12:03 -0500)
committerThan McIntosh <thanm@google.com>
Mon, 13 Dec 2021 19:08:31 +0000 (19:08 +0000)
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>
src/cmd/compile/internal/amd64/versions_test.go

index ee1a8ca3aa0ec73cd21abf9c38a09a6d99741429..7aa697b811442b3367f83998f1bdfb7b056701b8 100644 (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)
        }
 }