mirror of
https://github.com/golang/go
synced 2024-10-01 07:38:32 -06:00
2529d2857a
This change standardizes the folder structure for testdata that are used for testing the lsp. In particular, it uses the following format: - dir - primarymod - .go files - packages - go.mod (optional) - modules - repoa - mod1 - .go files - packages - go.mod (optional) As we can see, any folder inside of testdata should be of this format, where the primary test files with the markers are all located inside the primarymod folder. The modules folder is used to hold any potential dependencies that are used for testing. A consequence of this change is that we can have one directory separated by folders, where each folder is it's own module, this allows us to use internal/lsp/tests with go.mod files. Now, tests.Load() will return an array of Data objects, where each object corresponds to one of the directories structured above. Updates golang/go#36091 Change-Id: I437cc2a2a9fc1bac93779845737aa74383fbf9c3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/217541 Run-TryBot: Rohan Challa <rohan@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package mod
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp/cache"
|
|
"golang.org/x/tools/internal/lsp/tests"
|
|
"golang.org/x/tools/internal/span"
|
|
"golang.org/x/tools/internal/testenv"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
testenv.ExitIfSmallMachine()
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
// TODO(golang/go#36091): This file can be refactored to look like lsp_test.go
|
|
// when marker support gets added for go.mod files.
|
|
func TestModfileRemainsUnchanged(t *testing.T) {
|
|
ctx := tests.Context(t)
|
|
cache := cache.New(nil)
|
|
session := cache.NewSession()
|
|
options := tests.DefaultOptions()
|
|
options.TempModfile = true
|
|
options.Env = append(os.Environ(), "GOPACKAGESDRIVER=off", "GOROOT=")
|
|
|
|
// Make sure to copy the test directory to a temporary directory so we do not
|
|
// modify the test code or add go.sum files when we run the tests.
|
|
folder, err := tests.CopyFolderToTempDir(filepath.Join("testdata", "unchanged"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(folder)
|
|
|
|
before, err := ioutil.ReadFile(filepath.Join(folder, "go.mod"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, snapshot, err := session.NewView(ctx, "diagnostics_test", span.FileURI(folder), options)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, t := snapshot.View().ModFiles(); t == "" {
|
|
return
|
|
}
|
|
after, err := ioutil.ReadFile(filepath.Join(folder, "go.mod"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(before) != string(after) {
|
|
t.Errorf("the real go.mod file was changed even when tempModfile=true")
|
|
}
|
|
}
|