From: Than McIntosh Date: Mon, 13 Dec 2021 17:03:13 +0000 (-0500) Subject: cmd/compile/internal/amd64: fix for coverage testing X-Git-Tag: go1.18beta1~9 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3e8aa5dd495d30ff29cd4fb78aabe8fc0ebb1eda;p=gostls13.git 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 Run-TryBot: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- diff --git a/src/cmd/compile/internal/amd64/versions_test.go b/src/cmd/compile/internal/amd64/versions_test.go index ee1a8ca3aa..7aa697b811 100644 --- a/src/cmd/compile/internal/amd64/versions_test.go +++ b/src/cmd/compile/internal/amd64/versions_test.go @@ -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) } }