mirror of
https://github.com/golang/go
synced 2024-11-05 18:26:10 -07:00
84d0e3d1cc
A bunch of options are added to enable long-running performance-oriented tests in existing directories. They will be used in a later CL to implement a simple stress test, as an example of what is possible. Change-Id: I531b201b415362ea135978238b3d64b903226359 Reviewed-on: https://go-review.googlesource.com/c/tools/+/244440 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
109 lines
2.2 KiB
Go
109 lines
2.2 KiB
Go
// Copyright 2020 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 regtest
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
const workspaceProxy = `
|
|
-- example.com@v1.2.3/go.mod --
|
|
module example.com
|
|
|
|
go 1.12
|
|
-- example.com@v1.2.3/blah/blah.go --
|
|
package blah
|
|
|
|
func SaySomething() {
|
|
fmt.Println("something")
|
|
}
|
|
`
|
|
|
|
// TODO: Add a replace directive.
|
|
const workspaceModule = `
|
|
-- go.mod --
|
|
module mod.com
|
|
|
|
go 1.14
|
|
|
|
require example.com v1.2.3
|
|
-- main.go --
|
|
package main
|
|
|
|
import (
|
|
"example.com/blah"
|
|
"mod.com/inner"
|
|
)
|
|
|
|
func main() {
|
|
blah.SaySomething()
|
|
inner.Hi()
|
|
}
|
|
-- main2.go --
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func _() {
|
|
fmt.Print("%s")
|
|
}
|
|
-- inner/inner.go --
|
|
package inner
|
|
|
|
import "example.com/blah"
|
|
|
|
func Hi() {
|
|
blah.SaySomething()
|
|
}
|
|
`
|
|
|
|
// Confirm that find references returns all of the references in the module,
|
|
// regardless of what the workspace root is.
|
|
func TestReferences(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name, rootPath string
|
|
}{
|
|
{
|
|
name: "module root",
|
|
},
|
|
{
|
|
name: "subdirectory",
|
|
rootPath: "inner",
|
|
},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
opts := []RunOption{WithProxyFiles(workspaceProxy)}
|
|
if tt.rootPath != "" {
|
|
opts = append(opts, WithRootPath(tt.rootPath))
|
|
}
|
|
withOptions(opts...).run(t, workspaceModule, func(t *testing.T, env *Env) {
|
|
env.OpenFile("inner/inner.go")
|
|
locations := env.ReferencesAtRegexp("inner/inner.go", "SaySomething")
|
|
want := 3
|
|
if got := len(locations); got != want {
|
|
t.Fatalf("expected %v locations, got %v", want, got)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
// Make sure that analysis diagnostics are cleared for the whole package when
|
|
// the only opened file is closed. This test was inspired by the experience in
|
|
// VS Code, where clicking on a reference result triggers a
|
|
// textDocument/didOpen without a corresponding textDocument/didClose.
|
|
func TestClearAnalysisDiagnostics(t *testing.T) {
|
|
withOptions(WithProxyFiles(workspaceProxy), WithRootPath("inner")).run(t, workspaceModule, func(t *testing.T, env *Env) {
|
|
env.OpenFile("main.go")
|
|
env.Await(
|
|
env.DiagnosticAtRegexp("main2.go", "fmt.Print"),
|
|
)
|
|
env.CloseBuffer("main.go")
|
|
env.Await(
|
|
EmptyDiagnostics("main2.go"),
|
|
)
|
|
})
|
|
}
|