From 3e8aa5dd495d30ff29cd4fb78aabe8fc0ebb1eda Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Mon, 13 Dec 2021 12:03:13 -0500 Subject: [PATCH] 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 --- src/cmd/compile/internal/amd64/versions_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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) } } -- 2.50.0