From df2eb9381fb80be786bc1f85fdeb3d941104d6e8 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Mon, 19 Sep 2022 17:38:47 -0400 Subject: [PATCH] gopls/test: fix erroneously skipped tests, remove redundant cmd tests When code was moved to the golang.org/x/tools/gopls module, the gopls/test package tests we silently skipped, because of logic that skipped the tests if the testdata directory was not found. Narrow that check to only skip tests on android, which is where we expect testdata to be missing. Also, now that gopls code lives in the gopls module, there is little reason to have two copies of the command-line tests. Delete gopls/internal/lsp/cmd/cmd_test.go. Change-Id: I6d57244dd77a983b1f83c1cf653d5345e4fa0434 Reviewed-on: https://go-review.googlesource.com/c/tools/+/431842 Run-TryBot: Robert Findley gopls-CI: kokoro TryBot-Result: Gopher Robot Reviewed-by: Alan Donovan --- gopls/internal/lsp/cmd/cmd_test.go | 25 ------------------------- gopls/internal/lsp/cmd/test/cmdtest.go | 7 ++++--- gopls/test/gopls_test.go | 2 +- 3 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 gopls/internal/lsp/cmd/cmd_test.go diff --git a/gopls/internal/lsp/cmd/cmd_test.go b/gopls/internal/lsp/cmd/cmd_test.go deleted file mode 100644 index 877ceb66eb..0000000000 --- a/gopls/internal/lsp/cmd/cmd_test.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package cmd_test - -import ( - "os" - "testing" - - "golang.org/x/tools/internal/bug" - cmdtest "golang.org/x/tools/gopls/internal/lsp/cmd/test" - "golang.org/x/tools/gopls/internal/lsp/tests" - "golang.org/x/tools/internal/testenv" -) - -func TestMain(m *testing.M) { - bug.PanicOnBugs = true - testenv.ExitIfSmallMachine() - os.Exit(m.Run()) -} - -func TestCommandLine(t *testing.T) { - cmdtest.TestCommandLine(t, "../testdata", tests.DefaultOptions) -} diff --git a/gopls/internal/lsp/cmd/test/cmdtest.go b/gopls/internal/lsp/cmd/test/cmdtest.go index 86608c7c95..e2a3e546e2 100644 --- a/gopls/internal/lsp/cmd/test/cmdtest.go +++ b/gopls/internal/lsp/cmd/test/cmdtest.go @@ -12,10 +12,10 @@ import ( "fmt" "io" "os" + "runtime" "sync" "testing" - "golang.org/x/tools/internal/jsonrpc2/servertest" "golang.org/x/tools/gopls/internal/lsp/cache" "golang.org/x/tools/gopls/internal/lsp/cmd" "golang.org/x/tools/gopls/internal/lsp/debug" @@ -23,6 +23,7 @@ import ( "golang.org/x/tools/gopls/internal/lsp/protocol" "golang.org/x/tools/gopls/internal/lsp/source" "golang.org/x/tools/gopls/internal/lsp/tests" + "golang.org/x/tools/internal/jsonrpc2/servertest" "golang.org/x/tools/internal/span" "golang.org/x/tools/internal/tool" ) @@ -37,8 +38,8 @@ type runner struct { func TestCommandLine(t *testing.T, testdata string, options func(*source.Options)) { // On Android, the testdata directory is not copied to the runner. - if stat, err := os.Stat(testdata); err != nil || !stat.IsDir() { - t.Skip("testdata directory not present") + if runtime.GOOS == "android" { + t.Skip("testdata directory not present on android") } tests.RunTests(t, testdata, false, func(t *testing.T, datum *tests.Data) { ctx := tests.Context(t) diff --git a/gopls/test/gopls_test.go b/gopls/test/gopls_test.go index 4f266baaa1..248a03b789 100644 --- a/gopls/test/gopls_test.go +++ b/gopls/test/gopls_test.go @@ -23,7 +23,7 @@ func TestMain(m *testing.M) { } func TestCommandLine(t *testing.T) { - cmdtest.TestCommandLine(t, "../../internal/lsp/testdata", commandLineOptions) + cmdtest.TestCommandLine(t, "../internal/lsp/testdata", commandLineOptions) } func commandLineOptions(options *source.Options) {