From: Austin Clements Date: Mon, 24 Apr 2023 18:26:39 +0000 (-0400) Subject: cmd/dist: actually only compile tests with -compile-only X-Git-Tag: go1.21rc1~778 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ce0b9143123abe8005a059c92dbd763f7ab46214;p=gostls13.git cmd/dist: actually only compile tests with -compile-only Currently, "dist test -compile-only" still runs the test binaries, just with -run=^$ so no tests are run. It does this because, until recently, "go test -c" would fail if passed multiple test packages. But this has some unexpected consequences: init code still runs, TestMain still runs, and we generally can't test cross-compiling of tests. Now that #15513 is fixed, we can pass multiple packages to "go test -c". Hence, this CL make dist just use "go test -c" as one would expect. Found in the course of working on #37486, though it doesn't really affect that. Change-Id: If7d3c72c9e0f74d4ea0dd422411e5ee93b314be4 Reviewed-on: https://go-review.googlesource.com/c/go/+/488275 TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Reviewed-by: Bryan Mills Run-TryBot: Austin Clements --- diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index f58b49e028..cc96223aa6 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -317,9 +317,7 @@ func (opts *goTest) bgCommand(t *tester) *exec.Cmd { // Combine the flags. args := append([]string{"test"}, build...) if t.compileOnly { - // We can't pass -c with multiple packages, so run the tests but - // tell them not to do anything. - args = append(args, "-run=^$") + args = append(args, "-c", "-o", os.DevNull) } else { args = append(args, run...) } diff --git a/src/testing/testing.go b/src/testing/testing.go index c970d05256..fcf7048f23 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -1934,7 +1934,6 @@ func (m *M) Run() (code int) { // in which case every test will run nothing and succeed, // with no obvious way to detect this problem (since no tests are running). // So make 'no tests to run' a hard failure when testing package testing itself. - // The compile-only builders use -run=^$ to run no tests, so allow that. fmt.Print(chatty.prefix(), "FAIL: package testing must run tests\n") testOk = false }