Skip to content

Commit 8fd71c0

Browse files
committed
gopls/internal/lsp/mod: remove TestModfileRemainsUnchanged
Testdata for this test includes a go.mod file, which is problematic for a number of reasons (e.g. running from the mod cache; go work use -r). Replace it with a regtest. But really we should just delete the "tempModfile" setting (golang/go#61970). Fixes golang/go#57784 Change-Id: I79726c6106f3118d021a8f9ef52f385f1393d4a8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/518976 gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Peter Weinberger <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Robert Findley <[email protected]>
1 parent 2e5fc54 commit 8fd71c0

File tree

4 files changed

+41
-66
lines changed

4 files changed

+41
-66
lines changed

gopls/internal/lsp/mod/mod_test.go

-59
This file was deleted.

gopls/internal/lsp/mod/testdata/unchanged/go.mod

-1
This file was deleted.

gopls/internal/lsp/mod/testdata/unchanged/main.go

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package modfile
6+
7+
import (
8+
"testing"
9+
10+
. "golang.org/x/tools/gopls/internal/lsp/regtest"
11+
)
12+
13+
// This test replaces an older, problematic test (golang/go#57784). But it has
14+
// been a long time since the go command would mutate go.mod files.
15+
//
16+
// TODO(golang/go#61970): the tempModfile setting should be removed entirely.
17+
func TestTempModfileUnchanged(t *testing.T) {
18+
// badMod has a go.mod file that is missing a go directive.
19+
const badMod = `
20+
-- go.mod --
21+
module badmod.test/p
22+
-- p.go --
23+
package p
24+
`
25+
26+
WithOptions(
27+
Modes(Default), // no reason to test this with a remote gopls
28+
ProxyFiles(workspaceProxy),
29+
Settings{
30+
"tempModfile": true,
31+
},
32+
).Run(t, badMod, func(t *testing.T, env *Env) {
33+
env.OpenFile("p.go")
34+
env.AfterChange()
35+
want := "module badmod.test/p\n"
36+
got := env.ReadWorkspaceFile("go.mod")
37+
if got != want {
38+
t.Errorf("go.mod content:\n%s\nwant:\n%s", got, want)
39+
}
40+
})
41+
}

0 commit comments

Comments
 (0)