Skip to content

Commit 12d7e15

Browse files
committed
gopls/internal/analysis/modernize: add test of no gopls imports
This CL adds a test to prevent dependency backsliding. For golang/go#75266 Change-Id: I8d74993be22052d0574ba5e6aa7cee77f22c06d2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/701779 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 263a769 commit 12d7e15

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

gopls/internal/analysis/modernize/modernize_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
package modernize_test
66

77
import (
8+
"os/exec"
9+
"strings"
810
"testing"
911

1012
. "golang.org/x/tools/go/analysis/analysistest"
1113
"golang.org/x/tools/gopls/internal/analysis/modernize"
14+
"golang.org/x/tools/internal/testenv"
1215
)
1316

1417
func TestAppendClipped(t *testing.T) {
@@ -80,3 +83,20 @@ func TestTestingContext(t *testing.T) {
8083
func TestWaitGroup(t *testing.T) {
8184
RunWithSuggestedFixes(t, TestData(), modernize.WaitGroupAnalyzer, "waitgroup")
8285
}
86+
87+
// TestNoGoplsImports ensures modernize acquires no gopls dependencies,
88+
// in preparation for moving it to x/tools/go/analysis (#75266).
89+
func TestNoGoplsImports(t *testing.T) {
90+
testenv.NeedsTool(t, "go")
91+
92+
cmd := exec.Command("go", "list", "-f", `{{join .Imports "\n"}}`)
93+
out, err := cmd.Output()
94+
if err != nil {
95+
t.Fatal(err)
96+
}
97+
for imp := range strings.SplitSeq(string(out), "\n") {
98+
if strings.HasPrefix(imp, "golang.org/x/tools/gopls/") {
99+
t.Errorf("modernize imports %q", imp)
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)