Debian Codegraph @

gopls/internal/test/integration/workspace/goversion_test.go

raw symbols SCIP
1 // Copyright 2024 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 workspace
6
7 import (
8 "flag"
9 "os"
10 "runtime"
11 "testing"
12
13 . "golang.org/x/tools/gopls/internal/test/integration"
14 )
15
16 var go121bin = flag.String("go121bin", "", "bin directory containing go 1.21 or later")
17
18 // TODO(golang/go#65917): delete this test once we no longer support building
19 // gopls with older Go versions.
20 func TestCanHandlePatchVersions(t *testing.T) {
21 // This test verifies the fixes for golang/go#66195 and golang/go#66636 --
22 // that gopls does not crash when encountering a go version with a patch
23 // number in the go.mod file.
24 //
25 // This is tricky to test, because the regression requires that gopls is
26 // built with an older go version, and then the environment is upgraded to
27 // have a more recent go. To set up this scenario, the test requires a path
28 // to a bin directory containing go1.21 or later.
29 if *go121bin == "" {
30 t.Skip("-go121bin directory is not set")
31 }
32
33 if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
34 t.Skip("requires linux or darwin") // for PATH separator
35 }
36
37 path := os.Getenv("PATH")
38 t.Setenv("PATH", *go121bin+":"+path)
39
40 const files = `
41 -- go.mod --
42 module example.com/bar
43
44 go 1.21.1
45
46 -- p.go --
47 package bar
48
49 type I interface { string }
50 `
51
52 WithOptions(
53 EnvVars{
54 "PATH": path,
55 },
56 ).Run(t, files, func(t *testing.T, env *Env) {
57 env.OpenFile("p.go")
58 env.AfterChange(
59 NoDiagnostics(ForFile("p.go")),
60 )
61 })
62 }