1 // Copyright 2019 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.
13 "golang.org/x/tools/internal/lsp/cache"
14 "golang.org/x/tools/internal/lsp/source"
15 "golang.org/x/tools/internal/lsp/tests"
16 "golang.org/x/tools/internal/span"
17 "golang.org/x/tools/internal/testenv"
20 func TestMain(m *testing.M) {
21 testenv.ExitIfSmallMachine()
25 func TestModfileRemainsUnchanged(t *testing.T) {
26 testenv.NeedsGo1Point(t, 14)
28 ctx := tests.Context(t)
29 cache := cache.New(ctx, nil)
30 session := cache.NewSession(ctx)
31 options := source.DefaultOptions().Clone()
32 tests.DefaultOptions(options)
33 options.TempModfile = true
34 options.Env = map[string]string{"GOPACKAGESDRIVER": "off", "GOROOT": ""}
36 // Make sure to copy the test directory to a temporary directory so we do not
37 // modify the test code or add go.sum files when we run the tests.
38 folder, err := tests.CopyFolderToTempDir(filepath.Join("testdata", "unchanged"))
42 defer os.RemoveAll(folder)
44 before, err := ioutil.ReadFile(filepath.Join(folder, "go.mod"))
48 _, _, release, err := session.NewView(ctx, "diagnostics_test", span.URIFromPath(folder), "", options)
53 after, err := ioutil.ReadFile(filepath.Join(folder, "go.mod"))
57 if string(before) != string(after) {
58 t.Errorf("the real go.mod file was changed even when tempModfile=true")