Skip to content

Commit

Permalink
internal/lsp/regtest: simpler way to invert options
Browse files Browse the repository at this point in the history
This is an alternative to CL 241739, preserving the exiting variadic
options pattern and just adding a helper method to put the options up
front.

All things considered, I think this is better. CL 241739 was too
complicated, and being able to reuse "curried" runners isn't actually
important.

Updates golang/go#39384

Change-Id: I7ecd80d310cac879520b2d1feebcf5bd5e96e89b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/243057
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
  • Loading branch information
findleyr committed Jul 16, 2020
1 parent 43ed946 commit cf799ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/lsp/regtest/modfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import "example.com/blah"
func main() {
fmt.Println(blah.Name)
}`
runner.Run(t, untidyModule, func(t *testing.T, env *Env) {
withOptions(WithProxy(proxy)).run(t, untidyModule, func(t *testing.T, env *Env) {
// Open the file and make sure that the initial workspace load does not
// modify the go.mod file.
goModContent := env.ReadWorkspaceFile("go.mod")
Expand All @@ -59,7 +59,7 @@ func main() {
if got := env.ReadWorkspaceFile("go.mod"); got != goModContent {
t.Fatalf("go.mod changed on disk:\n%s", tests.Diff(goModContent, got))
}
}, WithProxy(proxy))
})
}

func TestIndirectDependencyFix(t *testing.T) {
Expand Down
16 changes: 16 additions & 0 deletions internal/lsp/regtest/reg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ var (

var runner *Runner

func run(t *testing.T, files string, f TestFunc) {
runner.Run(t, files, f)
}

func withOptions(opts ...RunOption) configuredRunner {
return configuredRunner{opts: opts}
}

type configuredRunner struct {
opts []RunOption
}

func (r configuredRunner) run(t *testing.T, files string, f TestFunc) {
runner.Run(t, files, f, r.opts...)
}

func TestMain(m *testing.M) {
flag.Parse()
if os.Getenv("_GOPLS_TEST_BINARY_RUN_AS_GOPLS") == "true" {
Expand Down
4 changes: 3 additions & 1 deletion internal/lsp/regtest/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ func InGOPATH() RunOption {
})
}

type TestFunc func(t *testing.T, env *Env)

// Run executes the test function in the default configured gopls execution
// modes. For each a test run, a new workspace is created containing the
// un-txtared files specified by filedata.
func (r *Runner) Run(t *testing.T, filedata string, test func(t *testing.T, e *Env), opts ...RunOption) {
func (r *Runner) Run(t *testing.T, filedata string, test TestFunc, opts ...RunOption) {
t.Helper()
config := r.defaultConfig()
for _, opt := range opts {
Expand Down

0 comments on commit cf799ca

Please sign in to comment.