Skip to content

Commit cf799ca

Browse files
committed
internal/lsp/regtest: simpler way to invert options
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent 43ed946 commit cf799ca

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

internal/lsp/regtest/modfile_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import "example.com/blah"
3939
func main() {
4040
fmt.Println(blah.Name)
4141
}`
42-
runner.Run(t, untidyModule, func(t *testing.T, env *Env) {
42+
withOptions(WithProxy(proxy)).run(t, untidyModule, func(t *testing.T, env *Env) {
4343
// Open the file and make sure that the initial workspace load does not
4444
// modify the go.mod file.
4545
goModContent := env.ReadWorkspaceFile("go.mod")
@@ -59,7 +59,7 @@ func main() {
5959
if got := env.ReadWorkspaceFile("go.mod"); got != goModContent {
6060
t.Fatalf("go.mod changed on disk:\n%s", tests.Diff(goModContent, got))
6161
}
62-
}, WithProxy(proxy))
62+
})
6363
}
6464

6565
func TestIndirectDependencyFix(t *testing.T) {

internal/lsp/regtest/reg_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ var (
2727

2828
var runner *Runner
2929

30+
func run(t *testing.T, files string, f TestFunc) {
31+
runner.Run(t, files, f)
32+
}
33+
34+
func withOptions(opts ...RunOption) configuredRunner {
35+
return configuredRunner{opts: opts}
36+
}
37+
38+
type configuredRunner struct {
39+
opts []RunOption
40+
}
41+
42+
func (r configuredRunner) run(t *testing.T, files string, f TestFunc) {
43+
runner.Run(t, files, f, r.opts...)
44+
}
45+
3046
func TestMain(m *testing.M) {
3147
flag.Parse()
3248
if os.Getenv("_GOPLS_TEST_BINARY_RUN_AS_GOPLS") == "true" {

internal/lsp/regtest/runner.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@ func InGOPATH() RunOption {
140140
})
141141
}
142142

143+
type TestFunc func(t *testing.T, env *Env)
144+
143145
// Run executes the test function in the default configured gopls execution
144146
// modes. For each a test run, a new workspace is created containing the
145147
// un-txtared files specified by filedata.
146-
func (r *Runner) Run(t *testing.T, filedata string, test func(t *testing.T, e *Env), opts ...RunOption) {
148+
func (r *Runner) Run(t *testing.T, filedata string, test TestFunc, opts ...RunOption) {
147149
t.Helper()
148150
config := r.defaultConfig()
149151
for _, opt := range opts {

0 commit comments

Comments
 (0)