mirror of https://github.com/golang/go.git
internal/lsp/regtest: add regtest for golang/go#38207
Fixes golang/go#38207 Change-Id: I78396814a2e6a3ccecc860953ac6892ffa1b68e8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/226960 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
504fe87a53
commit
4e4aced336
|
|
@ -9,9 +9,21 @@ package regtest
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/internal/lsp/fake"
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
)
|
||||
|
||||
const ardanLabsProxy = `
|
||||
-- github.com/ardanlabs/conf@v1.2.3/go.mod --
|
||||
module github.com/ardanlabs/conf
|
||||
|
||||
go 1.12
|
||||
-- github.com/ardanlabs/conf@v1.2.3/conf.go --
|
||||
package conf
|
||||
|
||||
var ErrHelpWanted error
|
||||
`
|
||||
|
||||
// -modfile flag that is used to provide modfile diagnostics is only available
|
||||
// with 1.14.
|
||||
func Test_Issue38211(t *testing.T) {
|
||||
|
|
@ -29,17 +41,6 @@ func main() {
|
|||
_ = conf.ErrHelpWanted
|
||||
}
|
||||
`
|
||||
const proxy = `
|
||||
-- github.com/ardanlabs/conf@v1.2.3/go.mod --
|
||||
module github.com/ardanlabs/conf
|
||||
|
||||
go 1.12
|
||||
-- github.com/ardanlabs/conf@v1.2.3/conf.go --
|
||||
package conf
|
||||
|
||||
var ErrHelpWanted error
|
||||
`
|
||||
|
||||
runner.Run(t, ardanLabs, func(t *testing.T, env *Env) {
|
||||
// Expect a diagnostic with a suggested fix to add
|
||||
// "github.com/ardanlabs/conf" to the go.mod file.
|
||||
|
|
@ -84,5 +85,40 @@ var ErrHelpWanted error
|
|||
env.Await(
|
||||
env.DiagnosticAtRegexp("main.go", `"github.com/ardanlabs/conf"`),
|
||||
)
|
||||
}, WithProxy(proxy))
|
||||
}, WithProxy(ardanLabsProxy))
|
||||
}
|
||||
|
||||
// Test for golang/go#38207.
|
||||
func TestNewModule_Issue38207(t *testing.T) {
|
||||
const emptyFile = `
|
||||
-- go.mod --
|
||||
module mod.com
|
||||
|
||||
go 1.12
|
||||
-- main.go --
|
||||
`
|
||||
runner.Run(t, emptyFile, func(t *testing.T, env *Env) {
|
||||
env.OpenFile("main.go")
|
||||
env.OpenFile("go.mod")
|
||||
env.EditBuffer("main.go", fake.NewEdit(0, 0, 0, 0, `package main
|
||||
|
||||
import "github.com/ardanlabs/conf"
|
||||
|
||||
func main() {
|
||||
_ = conf.ErrHelpWanted
|
||||
}
|
||||
`))
|
||||
env.SaveBuffer("main.go")
|
||||
metBy := env.Await(
|
||||
env.DiagnosticAtRegexp("main.go", `"github.com/ardanlabs/conf"`),
|
||||
)
|
||||
d, ok := metBy[0].(*protocol.PublishDiagnosticsParams)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected type for diagnostics (%T)", d)
|
||||
}
|
||||
env.ApplyQuickFixes("main.go", d.Diagnostics)
|
||||
env.Await(
|
||||
EmptyDiagnostics("main.go"),
|
||||
)
|
||||
}, WithProxy(ardanLabsProxy))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue