mirror of
https://github.com/golang/go
synced 2024-11-05 14:56:10 -07:00
46bd65c853
This change attempts to fix a concurrency error that would cause textDocument/CodeLens, textDocument/Formatting, textDocument/DocumentLink, and textDocument/Hover from failing on go.mod files. The issue was that the go command would return a potential concurrency error since the ModHandle and the ModTidyHandle are both using the temporary go.mod file. Updates golang/go#37824 Change-Id: I6cd63c1f75817c7308e033aec473966536a2a3bd Reviewed-on: https://go-review.googlesource.com/c/tools/+/224917 Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
85 lines
1.5 KiB
Go
85 lines
1.5 KiB
Go
package imports
|
|
|
|
import (
|
|
"go/build"
|
|
"os"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/gocommand"
|
|
"golang.org/x/tools/internal/testenv"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
testenv.ExitIfSmallMachine()
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
// TestNilOpts tests that process does not crash with nil opts.
|
|
func TestNilOpts(t *testing.T) {
|
|
var testOpts = []struct {
|
|
name string
|
|
opt *Options
|
|
}{
|
|
{
|
|
name: "nil",
|
|
opt: nil,
|
|
},
|
|
{
|
|
name: "nil env",
|
|
opt: &Options{Comments: true, TabIndent: true, TabWidth: 8},
|
|
},
|
|
{
|
|
name: "default",
|
|
opt: &Options{
|
|
Env: &ProcessEnv{
|
|
GOPATH: build.Default.GOPATH,
|
|
GOROOT: build.Default.GOROOT,
|
|
GocmdRunner: &gocommand.Runner{},
|
|
},
|
|
Comments: true,
|
|
TabIndent: true,
|
|
TabWidth: 8,
|
|
},
|
|
},
|
|
}
|
|
|
|
input := `package p
|
|
|
|
func _() {
|
|
fmt.Println()
|
|
}
|
|
`
|
|
want := `package p
|
|
|
|
import "fmt"
|
|
|
|
func _() {
|
|
fmt.Println()
|
|
}
|
|
`
|
|
for _, test := range testOpts {
|
|
// Test Process
|
|
got, err := Process("", []byte(input), test.opt)
|
|
if err != nil {
|
|
t.Errorf("%s: %s", test.name, err.Error())
|
|
}
|
|
if string(got) != want {
|
|
t.Errorf("%s: Process: Got:\n%s\nWant:\n%s\n", test.name, string(got), want)
|
|
}
|
|
|
|
// Test FixImports and ApplyFixes
|
|
fixes, err := FixImports("", []byte(input), test.opt)
|
|
if err != nil {
|
|
t.Errorf("%s: %s", test.name, err.Error())
|
|
}
|
|
|
|
got, err = ApplyFixes(fixes, "", []byte(input), test.opt, 0)
|
|
if err != nil {
|
|
t.Errorf("%s: %s", test.name, err.Error())
|
|
}
|
|
if string(got) != want {
|
|
t.Errorf("%s: ApplyFix: Got:\n%s\nWant:\n%s\n", test.name, string(got), want)
|
|
}
|
|
}
|
|
}
|