Skip to content

Commit

Permalink
gopls/internal/regtest: rename EmptyOrNoDiagnostics to NoDiagnostics
Browse files Browse the repository at this point in the history
Now that there is only one such expectation, give it the simpler name.

Change-Id: Ib5b7b55d2f20f9d9a034bce5eb01304bcdc65a2a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461877
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
Run-TryBot: Robert Findley <[email protected]>
  • Loading branch information
findleyr committed Jan 12, 2023
1 parent 7ec05ac commit 2be1a9a
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 39 deletions.
6 changes: 2 additions & 4 deletions gopls/internal/lsp/regtest/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,9 @@ func EmptyDiagnostics(name string) Expectation {
}
}

// EmptyOrNoDiagnostics asserts that either no diagnostics are sent for the
// NoDiagnostics asserts that either no diagnostics are sent for the
// workspace-relative path name, or empty diagnostics are sent.
// TODO(rFindley): this subtlety shouldn't be necessary. Gopls should always
// send at least one diagnostic set for open files.
func EmptyOrNoDiagnostics(name string) Expectation {
func NoDiagnostics(name string) Expectation {
check := func(s State) Verdict {
if diags := s.diagnostics[name]; diags == nil || len(diags.Diagnostics) == 0 {
return Met
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/regtest/diagnostics/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
}
env.Await(OnceMet(
env.DoneWithOpen(),
EmptyOrNoDiagnostics("builtin.go"),
NoDiagnostics("builtin.go"),
))
})
}
12 changes: 6 additions & 6 deletions gopls/internal/regtest/diagnostics/diagnostics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,8 @@ package foo_
env.Await(
OnceMet(
env.DoneWithChange(),
EmptyOrNoDiagnostics("foo/bar_test.go"),
EmptyOrNoDiagnostics("foo/foo.go"),
NoDiagnostics("foo/bar_test.go"),
NoDiagnostics("foo/foo.go"),
),
)
})
Expand Down Expand Up @@ -1092,7 +1092,7 @@ func main() {
env.Await(
OnceMet(
env.DoneWithChange(),
EmptyOrNoDiagnostics("foo/foo.go"),
NoDiagnostics("foo/foo.go"),
),
)
})
Expand Down Expand Up @@ -1218,7 +1218,7 @@ func main() {
).Run(t, mod, func(t *testing.T, env *Env) {
env.OpenFile("a/main.go")
env.AfterChange(
EmptyOrNoDiagnostics("main.go"),
NoDiagnostics("main.go"),
)
})
}
Expand Down Expand Up @@ -1636,8 +1636,8 @@ const B = a.B
env.RegexpReplace("b/b.go", `const B = a\.B`, "")
env.SaveBuffer("b/b.go")
env.Await(
EmptyOrNoDiagnostics("a/a.go"),
EmptyOrNoDiagnostics("b/b.go"),
NoDiagnostics("a/a.go"),
NoDiagnostics("b/b.go"),
)
})
}
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/regtest/misc/failures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ const a = 2
// Fix the error by editing the const name in b.go to `b`.
env.RegexpReplace("b.go", "(a) = 2", "b")
env.Await(
EmptyOrNoDiagnostics("a.go"),
EmptyOrNoDiagnostics("b.go"),
NoDiagnostics("a.go"),
NoDiagnostics("b.go"),
)
})
}
6 changes: 3 additions & 3 deletions gopls/internal/regtest/misc/vuln_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func main() {
OnceMet(
CompletedProgress(result.Token, nil),
ShownMessage("Found GOSTDLIB"),
EmptyOrNoDiagnostics("go.mod"),
NoDiagnostics("go.mod"),
),
)
testFetchVulncheckResult(t, env, map[string]fetchVulncheckResult{
Expand Down Expand Up @@ -276,7 +276,7 @@ func main() {
).Run(t, files, func(t *testing.T, env *Env) {
env.OpenFile("go.mod")
env.AfterChange(
EmptyOrNoDiagnostics("go.mod"),
NoDiagnostics("go.mod"),
// we don't publish diagnostics for standard library vulnerability yet.
)
testFetchVulncheckResult(t, env, map[string]fetchVulncheckResult{
Expand Down Expand Up @@ -868,7 +868,7 @@ func TestGovulncheckInfo(t *testing.T) {
}
env.ApplyCodeAction(reset)

env.Await(EmptyOrNoDiagnostics("go.mod"))
env.Await(NoDiagnostics("go.mod"))
})
}

Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/regtest/modfile/modfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,8 @@ func main() {
)
env.ApplyQuickFixes("main.go", d.Diagnostics)
env.Await(
EmptyOrNoDiagnostics("main.go"),
EmptyOrNoDiagnostics("go.mod"),
NoDiagnostics("main.go"),
NoDiagnostics("go.mod"),
)
})
}
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/regtest/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ B {{}} <-- missing body
OnceMet(
InitialWorkspaceLoad,
env.DiagnosticAtRegexp("a/a.tmpl", "()A"),
EmptyOrNoDiagnostics("b/b.tmpl"),
NoDiagnostics("b/b.tmpl"),
),
)
})
Expand All @@ -149,7 +149,7 @@ go 1.12
env.SetBufferContent("hello.tmpl", "{{range .Planets}}\nHello {{}}\n{{end}}")
env.Await(env.DiagnosticAtRegexp("hello.tmpl", "()Hello {{}}"))
env.RegexpReplace("hello.tmpl", "{{}}", "{{.}}")
env.Await(EmptyOrNoDiagnostics("hello.tmpl"))
env.Await(NoDiagnostics("hello.tmpl"))
})
}

Expand Down
24 changes: 12 additions & 12 deletions gopls/internal/regtest/watch/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func _() {
})
env.Await(
EmptyDiagnostics("a/a.go"),
EmptyOrNoDiagnostics("b/b.go"),
NoDiagnostics("b/b.go"),
)
})
}
Expand Down Expand Up @@ -226,7 +226,7 @@ func _() {}
env.WriteWorkspaceFile("c/c.go", `package c; func C() {};`)
env.WriteWorkspaceFile("a/a.go", `package a; import "mod.com/c"; func _() { c.C() }`)
env.AfterChange(
EmptyOrNoDiagnostics("a/a.go"),
NoDiagnostics("a/a.go"),
)
})
}
Expand Down Expand Up @@ -341,12 +341,12 @@ func _() {
env.Await(
OnceMet(
env.DoneWithChangeWatchedFiles(),
EmptyOrNoDiagnostics("a/a.go"),
NoDiagnostics("a/a.go"),
),
)
env.WriteWorkspaceFile("b/b.go", newMethod)
env.Await(
EmptyOrNoDiagnostics("a/a.go"),
NoDiagnostics("a/a.go"),
)
})
})
Expand All @@ -360,9 +360,9 @@ func _() {
env.Await(
OnceMet(
env.DoneWithChangeWatchedFiles(),
EmptyOrNoDiagnostics("a/a.go"),
NoDiagnostics("a/a.go"),
),
EmptyOrNoDiagnostics("b/b.go"),
NoDiagnostics("b/b.go"),
)
})
})
Expand Down Expand Up @@ -490,7 +490,7 @@ func _() {}
env.RemoveWorkspaceFile("a/a1.go")
env.WriteWorkspaceFile("a/a2.go", "package a; func _() {};")
env.AfterChange(
EmptyOrNoDiagnostics("main.go"),
NoDiagnostics("main.go"),
)
})
}
Expand Down Expand Up @@ -567,7 +567,7 @@ func main() {
})
env.AfterChange(
env.DoneWithChangeWatchedFiles(),
EmptyOrNoDiagnostics("main.go"),
NoDiagnostics("main.go"),
)
})
}
Expand Down Expand Up @@ -694,11 +694,11 @@ func TestAll(t *testing.T) {
env.Await(
OnceMet(
env.DoneWithChangeWatchedFiles(),
EmptyOrNoDiagnostics("a/a.go"),
NoDiagnostics("a/a.go"),
),
OnceMet(
env.DoneWithChangeWatchedFiles(),
EmptyOrNoDiagnostics("a/a_test.go"),
NoDiagnostics("a/a_test.go"),
),
)
// Now, add a new file to the test variant and use its symbol in the
Expand Down Expand Up @@ -726,11 +726,11 @@ func TestSomething(t *testing.T) {}
env.Await(
OnceMet(
env.DoneWithChangeWatchedFiles(),
EmptyOrNoDiagnostics("a/a_test.go"),
NoDiagnostics("a/a_test.go"),
),
OnceMet(
env.DoneWithChangeWatchedFiles(),
EmptyOrNoDiagnostics("a/a2_test.go"),
NoDiagnostics("a/a2_test.go"),
),
)
})
Expand Down
6 changes: 3 additions & 3 deletions gopls/internal/regtest/workspace/directoryfilters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const _ = Nonexistant
env.Await(
OnceMet(
InitialWorkspaceLoad,
EmptyOrNoDiagnostics("exclude/x.go"),
NoDiagnostics("exclude/x.go"),
),
)
})
Expand Down Expand Up @@ -88,8 +88,8 @@ const X = 1
env.Await(
OnceMet(
InitialWorkspaceLoad,
EmptyOrNoDiagnostics("exclude/exclude.go"), // filtered out
EmptyOrNoDiagnostics("include/include.go"), // successfully builds
NoDiagnostics("exclude/exclude.go"), // filtered out
NoDiagnostics("include/include.go"), // successfully builds
),
)
})
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/regtest/workspace/standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func main() {}
OnceMet(
env.DoneWithOpen(),
env.DiagnosticAtRegexp("ignore.go", "package (main)"),
EmptyOrNoDiagnostics("standalone.go"),
NoDiagnostics("standalone.go"),
),
)

Expand All @@ -236,7 +236,7 @@ func main() {}
env.Await(
OnceMet(
env.DoneWithChange(),
EmptyOrNoDiagnostics("ignore.go"),
NoDiagnostics("ignore.go"),
env.DiagnosticAtRegexp("standalone.go", "package (main)"),
),
)
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/regtest/workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ use (

// This fails if guarded with a OnceMet(DoneWithSave(), ...), because it is
// debounced (and therefore not synchronous with the change).
env.Await(EmptyOrNoDiagnostics("modb/go.mod"))
env.Await(NoDiagnostics("modb/go.mod"))

// Test Formatting.
env.SetBufferContent("go.work", `go 1.18
Expand Down Expand Up @@ -1173,7 +1173,7 @@ import (
Run(t, ws, func(t *testing.T, env *Env) {
env.OpenFile("b/main.go")
env.AfterChange(
EmptyOrNoDiagnostics("a/main.go"),
NoDiagnostics("a/main.go"),
)
env.OpenFile("a/main.go")
env.Await(
Expand Down

0 comments on commit 2be1a9a

Please sign in to comment.