Skip to content

Commit a721062

Browse files
committed
gopls/internal/regtest/workspace: fix TestQuickFix_AddGoWork for go1.21
Make this test compatible with the forward compatibility proposal, which includes patch versions and prerelease version information in the go directive line. Fixes golang/go#61307 Change-Id: I7abb615e650a30d712c2ad8645f927dabe7c41ee Reviewed-on: https://go-review.googlesource.com/c/tools/+/508801 Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent ba23fc4 commit a721062

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

gopls/internal/regtest/workspace/quickfix_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package workspace
66

77
import (
8-
"fmt"
98
"strings"
109
"testing"
1110

@@ -104,7 +103,6 @@ use (
104103
func TestQuickFix_AddGoWork(t *testing.T) {
105104
testenv.NeedsGo1Point(t, 18) // needs go.work
106105

107-
v := goVersion(t)
108106
const files = `
109107
-- a/go.mod --
110108
module mod.com/a
@@ -148,37 +146,34 @@ const C = "b"
148146
name string
149147
file string
150148
title string
151-
want string
149+
want string // expected go.work content, excluding go directive line
152150
}{
153151
{
154152
"use b",
155153
"b/main.go",
156154
"Add a go.work file using this module",
157-
fmt.Sprintf(`go 1.%d
158-
155+
`
159156
use ./b
160-
`, v),
157+
`,
161158
},
162159
{
163160
"use a",
164161
"a/main.go",
165162
"Add a go.work file using this module",
166-
fmt.Sprintf(`go 1.%d
167-
163+
`
168164
use ./a
169-
`, v),
165+
`,
170166
},
171167
{
172168
"use all",
173169
"a/main.go",
174170
"Add a go.work file using all modules",
175-
fmt.Sprintf(`go 1.%d
176-
171+
`
177172
use (
178173
./a
179174
./b
180175
)
181-
`, v),
176+
`,
182177
},
183178
}
184179

@@ -204,6 +199,9 @@ use (
204199
)
205200

206201
got := env.ReadWorkspaceFile("go.work")
202+
// Ignore the `go` directive, which we assume is on the first line of
203+
// the go.work file. This allows the test to be independent of go version.
204+
got = strings.Join(strings.Split(got, "\n")[1:], "\n")
207205
if diff := compare.Text(test.want, got); diff != "" {
208206
t.Errorf("unexpected go.work content:\n%s", diff)
209207
}

0 commit comments

Comments
 (0)