mirror of
https://github.com/golang/go
synced 2024-11-05 14:56:10 -07:00
internal/lsp/regtest: move and re-enable TestRegenerateCgo
Revert https://golang.org/cl/234480, which was unnecessary, and move it to a more appropriate file. Change-Id: I3f5a3eccaf0ffe324fee8e27945a2e5ece2ff12c Reviewed-on: https://go-review.googlesource.com/c/tools/+/238597 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
6222995d07
commit
87be026d38
@ -1,58 +0,0 @@
|
|||||||
//+build go1.15
|
|
||||||
|
|
||||||
package regtest
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"golang.org/x/tools/internal/lsp/protocol"
|
|
||||||
"golang.org/x/tools/internal/lsp/source"
|
|
||||||
"golang.org/x/tools/internal/testenv"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRegenerateCgo(t *testing.T) {
|
|
||||||
t.Skip("This test fails in some environments: see golang.org/issues/39135")
|
|
||||||
testenv.NeedsTool(t, "cgo")
|
|
||||||
|
|
||||||
const workspace = `
|
|
||||||
-- go.mod --
|
|
||||||
module example.com
|
|
||||||
-- cgo.go --
|
|
||||||
package x
|
|
||||||
|
|
||||||
/*
|
|
||||||
int fortythree() { return 42; }
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
func Foo() {
|
|
||||||
print(C.fortytwo())
|
|
||||||
}
|
|
||||||
`
|
|
||||||
runner.Run(t, workspace, func(t *testing.T, env *Env) {
|
|
||||||
// Open the file. We should have a nonexistant symbol.
|
|
||||||
env.OpenFile("cgo.go")
|
|
||||||
env.Await(env.DiagnosticAtRegexp("cgo.go", `C\.(fortytwo)`)) // could not determine kind of name for C.fortytwo
|
|
||||||
|
|
||||||
// Fix the C function name. We haven't regenerated cgo, so nothing should be fixed.
|
|
||||||
env.RegexpReplace("cgo.go", `int fortythree`, "int fortytwo")
|
|
||||||
env.SaveBuffer("cgo.go")
|
|
||||||
env.Await(env.DiagnosticAtRegexp("cgo.go", `C\.(fortytwo)`))
|
|
||||||
|
|
||||||
// Regenerate cgo, fixing the diagnostic.
|
|
||||||
lenses := env.CodeLens("cgo.go")
|
|
||||||
var lens protocol.CodeLens
|
|
||||||
for _, l := range lenses {
|
|
||||||
if l.Command.Command == source.CommandRegenerateCgo {
|
|
||||||
lens = l
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, err := env.Editor.Server.ExecuteCommand(env.Ctx, &protocol.ExecuteCommandParams{
|
|
||||||
Command: lens.Command.Command,
|
|
||||||
Arguments: lens.Command.Arguments,
|
|
||||||
}); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
env.Await(EmptyDiagnostics("cgo.go"))
|
|
||||||
})
|
|
||||||
}
|
|
@ -10,6 +10,7 @@ import (
|
|||||||
"golang.org/x/tools/internal/lsp/fake"
|
"golang.org/x/tools/internal/lsp/fake"
|
||||||
"golang.org/x/tools/internal/lsp/protocol"
|
"golang.org/x/tools/internal/lsp/protocol"
|
||||||
"golang.org/x/tools/internal/lsp/source"
|
"golang.org/x/tools/internal/lsp/source"
|
||||||
|
"golang.org/x/tools/internal/testenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDisablingCodeLens(t *testing.T) {
|
func TestDisablingCodeLens(t *testing.T) {
|
||||||
@ -118,3 +119,50 @@ func main() {
|
|||||||
}
|
}
|
||||||
}, WithProxy(proxyWithLatest))
|
}, WithProxy(proxyWithLatest))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRegenerateCgo(t *testing.T) {
|
||||||
|
testenv.NeedsTool(t, "cgo")
|
||||||
|
testenv.NeedsGo1Point(t, 15)
|
||||||
|
|
||||||
|
const workspace = `
|
||||||
|
-- go.mod --
|
||||||
|
module example.com
|
||||||
|
-- cgo.go --
|
||||||
|
package x
|
||||||
|
|
||||||
|
/*
|
||||||
|
int fortythree() { return 42; }
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
func Foo() {
|
||||||
|
print(C.fortytwo())
|
||||||
|
}
|
||||||
|
`
|
||||||
|
runner.Run(t, workspace, func(t *testing.T, env *Env) {
|
||||||
|
// Open the file. We should have a nonexistant symbol.
|
||||||
|
env.OpenFile("cgo.go")
|
||||||
|
env.Await(env.DiagnosticAtRegexp("cgo.go", `C\.(fortytwo)`)) // could not determine kind of name for C.fortytwo
|
||||||
|
|
||||||
|
// Fix the C function name. We haven't regenerated cgo, so nothing should be fixed.
|
||||||
|
env.RegexpReplace("cgo.go", `int fortythree`, "int fortytwo")
|
||||||
|
env.SaveBuffer("cgo.go")
|
||||||
|
env.Await(env.DiagnosticAtRegexp("cgo.go", `C\.(fortytwo)`))
|
||||||
|
|
||||||
|
// Regenerate cgo, fixing the diagnostic.
|
||||||
|
lenses := env.CodeLens("cgo.go")
|
||||||
|
var lens protocol.CodeLens
|
||||||
|
for _, l := range lenses {
|
||||||
|
if l.Command.Command == source.CommandRegenerateCgo {
|
||||||
|
lens = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := env.Editor.Server.ExecuteCommand(env.Ctx, &protocol.ExecuteCommandParams{
|
||||||
|
Command: lens.Command.Command,
|
||||||
|
Arguments: lens.Command.Arguments,
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
env.Await(EmptyDiagnostics("cgo.go"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user