all: fix non-gopls short tests on js/wasm and update for wasip1/wasm

testenv.HasExec should not assume that "js" and "ios" are the only
platforms that can't exec. Instead of hard-coding a list of GOOS,
hard-code only the ones known to work and probe the remainder by
trying to re-exec the test binary.

Similarly, in testenv_notunix, negate the list of unix platforms
instead of hard-coding the non-unix ones.

Add missing calls to testenv functions were needed.

For golang/go#58141.
Updates golang/go#59718.

Change-Id: I0114e0bfb6d091e84b325d7f9bb0896da22482be
Reviewed-on: https://go-review.googlesource.com/c/tools/+/486315
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Commit-Queue: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Bryan C. Mills 2023-04-19 11:29:10 -04:00 • committed by Gopher Robot
commit b452a8164e

View file

@ -14,9 +14,11 @@ import (
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
"golang.org/x/tools/internal/stack/stacktest"
"golang.org/x/tools/internal/testenv"
)
func TestIdleTimeout(t *testing.T) {
testenv.NeedsLocalhostNet(t)
stacktest.NoLeak(t)
// Use a panicking time.AfterFunc instead of context.WithTimeout so that we
@ -161,19 +163,20 @@ func TestServe(t *testing.T) {
tests := []struct {
name string
factory func(context.Context) (jsonrpc2.Listener, error)
factory func(context.Context, testing.TB) (jsonrpc2.Listener, error)
}{
{"tcp", func(ctx context.Context) (jsonrpc2.Listener, error) {
{"tcp", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {
testenv.NeedsLocalhostNet(t)
return jsonrpc2.NetListener(ctx, "tcp", "localhost:0", jsonrpc2.NetListenOptions{})
}},
{"pipe", func(ctx context.Context) (jsonrpc2.Listener, error) {
{"pipe", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {
return jsonrpc2.NetPipeListener(ctx)
}},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
fake, err := test.factory(ctx)
fake, err := test.factory(ctx, t)
if err != nil {
t.Fatal(err)
}