]> Cypherpunks repositories - gostls13.git/commit
cmd/cgo/internal: skip in tests, not in TestMain
authorAustin Clements <austin@google.com>
Mon, 22 May 2023 19:19:49 +0000 (15:19 -0400)
committerAustin Clements <austin@google.com>
Mon, 22 May 2023 20:56:11 +0000 (20:56 +0000)
commit5abfdc8c75b13edbe3ccc918df47dd2da85454d8
tree58da26821f29fd48ef28ce9b77c843ebca13e896
parenta1f3dc33dced2d337261b693b1ef1bf6a5bbce8d
cmd/cgo/internal: skip in tests, not in TestMain

Many cgo integration tests do a lot of common setup in TestMain, and
that means they require a lot from the test environment to even get
off the ground. If something is missing, right now they print a "SKIP"
message to stderr and exit without running any tests.

Make these behave more like normal tests by instead setting a global
skip function if some precondition isn't satisfied, and having every
test call that. This way we run the tests and see them skip.

I would prefer something much more structured. For example, if we
replaced the global state set up by TestMain in these tests by instead
calling a function that returned that state (after setting it up on
the first call), that function could do the appropriate skips and
there would be no way to accidentally access this state without
checking the preconditions. But that's substantially more work and may
be much easier after we do further cleanup of these tests.

Change-Id: I92de569fd27596798c5e478402449cd735ec53a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/497096
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/cgo/internal/testcarchive/carchive_test.go
src/cmd/cgo/internal/testcshared/cshared_test.go
src/cmd/cgo/internal/testplugin/plugin_test.go
src/cmd/cgo/internal/testshared/shared_test.go