Skip to content

Commit 7db3d3f

Browse files
findleyrgopherbot
authored andcommitted
internal/jsonrpc2_v2,mcp: remove unneeded dependencies
Remove dependencies on the eventtest and testenv packages from jsonrpc2_v2 and mcp packages, in preparation for forking. Change-Id: Id0efb0c3187629f6fb1822cc853ec52acea41b0d Reviewed-on: https://go-review.googlesource.com/c/tools/+/682696 Reviewed-by: Jonathan Amsterdam <[email protected]> Auto-Submit: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 3590a17 commit 7db3d3f

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

internal/jsonrpc2_v2/jsonrpc2_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import (
1212
"reflect"
1313
"testing"
1414

15-
"golang.org/x/tools/internal/event/export/eventtest"
1615
jsonrpc2 "golang.org/x/tools/internal/jsonrpc2_v2"
17-
"golang.org/x/tools/internal/stack/stacktest"
1816
)
1917

2018
var callTests = []invoker{
@@ -130,8 +128,7 @@ func TestConnectionHeader(t *testing.T) {
130128
}
131129

132130
func testConnection(t *testing.T, framer jsonrpc2.Framer) {
133-
stacktest.NoLeak(t)
134-
ctx := eventtest.NewContext(context.Background(), t)
131+
ctx := context.Background()
135132
listener, err := jsonrpc2.NetPipeListener(ctx)
136133
if err != nil {
137134
t.Fatal(err)
@@ -147,7 +144,6 @@ func testConnection(t *testing.T, framer jsonrpc2.Framer) {
147144
client, err := jsonrpc2.Dial(ctx,
148145
listener.Dialer(), binder{framer, func(h *handler) {
149146
defer h.conn.Close()
150-
ctx := eventtest.NewContext(ctx, t)
151147
test.Invoke(t, ctx, h)
152148
if call, ok := test.(*call); ok {
153149
// also run all simple call tests in echo mode

internal/jsonrpc2_v2/serve_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,26 @@ import (
88
"context"
99
"errors"
1010
"fmt"
11+
"runtime"
1112
"runtime/debug"
1213
"testing"
1314
"time"
1415

1516
jsonrpc2 "golang.org/x/tools/internal/jsonrpc2_v2"
16-
"golang.org/x/tools/internal/stack/stacktest"
17-
"golang.org/x/tools/internal/testenv"
1817
)
1918

19+
// needsLocalhostNet skips t if networking does not work for ports opened
20+
// with "localhost".
21+
// forked from golang.org/x/tools/internal/testenv.
22+
func needsLocalhostNet(t testing.TB) {
23+
switch runtime.GOOS {
24+
case "js", "wasip1":
25+
t.Skipf(`Listening on "localhost" fails on %s; see https://go.dev/issue/59718`, runtime.GOOS)
26+
}
27+
}
28+
2029
func TestIdleTimeout(t *testing.T) {
21-
testenv.NeedsLocalhostNet(t)
22-
stacktest.NoLeak(t)
30+
needsLocalhostNet(t)
2331

2432
// Use a panicking time.AfterFunc instead of context.WithTimeout so that we
2533
// get a goroutine dump on failure. We expect the test to take on the order of
@@ -158,15 +166,14 @@ func (fakeHandler) Handle(ctx context.Context, req *jsonrpc2.Request) (any, erro
158166
}
159167

160168
func TestServe(t *testing.T) {
161-
stacktest.NoLeak(t)
162169
ctx := context.Background()
163170

164171
tests := []struct {
165172
name string
166173
factory func(context.Context, testing.TB) (jsonrpc2.Listener, error)
167174
}{
168175
{"tcp", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {
169-
testenv.NeedsLocalhostNet(t)
176+
needsLocalhostNet(t)
170177
return jsonrpc2.NetListener(ctx, "tcp", "localhost:0", jsonrpc2.NetListenOptions{})
171178
}},
172179
{"pipe", func(ctx context.Context, t testing.TB) (jsonrpc2.Listener, error) {

internal/mcp/cmd_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"log"
1010
"os"
1111
"os/exec"
12+
"runtime"
1213
"testing"
1314

1415
"github.com/google/go-cmp/cmp"
1516
"golang.org/x/tools/internal/mcp"
16-
"golang.org/x/tools/internal/testenv"
1717
)
1818

1919
const runAsServer = "_MCP_RUN_AS_SERVER"
@@ -39,7 +39,13 @@ func runServer() {
3939
}
4040

4141
func TestCmdTransport(t *testing.T) {
42-
testenv.NeedsExec(t)
42+
// Conservatively, limit to major OS where we know that os.Exec is
43+
// supported.
44+
switch runtime.GOOS {
45+
case "darwin", "linux", "windows":
46+
default:
47+
t.Skip("unsupported OS")
48+
}
4349

4450
ctx, cancel := context.WithCancel(context.Background())
4551
defer cancel()

0 commit comments

Comments
 (0)