| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package workspace |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
"path/filepath" |
| 10 |
"testing" |
| 11 |
|
| 12 |
. "golang.org/x/tools/gopls/internal/test/integration" |
| 13 |
) |
| 14 |
|
| 15 |
|
| 16 |
func TestUseGoWorkOutsideTheWorkspace(t *testing.T) { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
var files = fmt.Sprintf(` |
| 22 |
-- work/a/go.mod -- |
| 23 |
module a.com |
| 24 |
|
| 25 |
go 1.12 |
| 26 |
-- work/a/a.go -- |
| 27 |
package a |
| 28 |
-- work/b/go.mod -- |
| 29 |
module b.com |
| 30 |
|
| 31 |
go 1.12 |
| 32 |
-- work/b/b.go -- |
| 33 |
package b |
| 34 |
|
| 35 |
func _() { |
| 36 |
x := 1 // unused |
| 37 |
} |
| 38 |
-- other/c/go.mod -- |
| 39 |
module c.com |
| 40 |
|
| 41 |
go 1.18 |
| 42 |
-- other/c/c.go -- |
| 43 |
package c |
| 44 |
-- config/go.work -- |
| 45 |
go 1.18 |
| 46 |
|
| 47 |
use ( |
| 48 |
%s |
| 49 |
%s |
| 50 |
%s |
| 51 |
) |
| 52 |
`, |
| 53 |
filepath.Join("$SANDBOX_WORKDIR", "work", "a"), |
| 54 |
filepath.Join("$SANDBOX_WORKDIR", "work", "b"), |
| 55 |
filepath.Join("$SANDBOX_WORKDIR", "other", "c"), |
| 56 |
) |
| 57 |
|
| 58 |
WithOptions( |
| 59 |
WorkspaceFolders("work"), |
| 60 |
EnvVars{"GOWORK": filepath.Join("$SANDBOX_WORKDIR", "config", "go.work")}, |
| 61 |
).Run(t, files, func(t *testing.T, env *Env) { |
| 62 |
|
| 63 |
env.OnceMet( |
| 64 |
InitialWorkspaceLoad, |
| 65 |
FileWatchMatching(`other`), |
| 66 |
FileWatchMatching(`config.go\.work`), |
| 67 |
) |
| 68 |
env.Await(FileWatchMatching(`config.go\.work`)) |
| 69 |
|
| 70 |
|
| 71 |
env.OpenFile("work/a/a.go") |
| 72 |
env.AfterChange( |
| 73 |
Diagnostics(env.AtRegexp("work/b/b.go", "x := 1"), WithMessage("not used")), |
| 74 |
) |
| 75 |
}) |
| 76 |
} |