Skip to content

Commit 27dfeb2

Browse files
committed
gopls/internal/regtest: replace NoDiagnostics with NoMatchingDiagnostics
Replace uses of NoDiagnostics with the more flexible NoMatchingDiagnostics, and rename NoMatchingDiagnostics to NoDiagnostics. Updates golang/go#39384 Change-Id: I15b19ad6c9b58c1ae88ec1b444bb589002f75a80 Reviewed-on: https://go-review.googlesource.com/c/tools/+/461936 gopls-CI: kokoro <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 87092c8 commit 27dfeb2

23 files changed

+130
-147
lines changed

gopls/internal/lsp/regtest/expectation.go

+5-22
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,10 @@ func Diagnostics(filters ...DiagnosticFilter) Expectation {
728728
}
729729
}
730730

731-
// NoMatchingDiagnostics asserts that there are no diagnostics matching the
732-
// given filters. Notably, if no filters are supplied this assertion checks
733-
// that there are no diagnostics at all, for any file.
734-
//
735-
// TODO(rfindley): replace NoDiagnostics with this, and rename.
736-
func NoMatchingDiagnostics(filters ...DiagnosticFilter) Expectation {
731+
// NoDiagnostics asserts that there are no diagnostics matching the given
732+
// filters. Notably, if no filters are supplied this assertion checks that
733+
// there are no diagnostics at all, for any file.
734+
func NoDiagnostics(filters ...DiagnosticFilter) Expectation {
737735
check := func(s State) Verdict {
738736
diags := flattenDiagnostics(s)
739737
for _, filter := range filters {
@@ -778,7 +776,7 @@ func flattenDiagnostics(state State) []flatDiagnostic {
778776
// -- Diagnostic filters --
779777

780778
// A DiagnosticFilter filters the set of diagnostics, for assertion with
781-
// Diagnostics or NoMatchingDiagnostics.
779+
// Diagnostics or NoDiagnostics.
782780
type DiagnosticFilter struct {
783781
desc string
784782
check func(name string, _ protocol.Diagnostic) bool
@@ -832,21 +830,6 @@ func WithMessageContaining(substring string) DiagnosticFilter {
832830

833831
// TODO(rfindley): eliminate all expectations below this point.
834832

835-
// NoDiagnostics asserts that either no diagnostics are sent for the
836-
// workspace-relative path name, or empty diagnostics are sent.
837-
func NoDiagnostics(name string) Expectation {
838-
check := func(s State) Verdict {
839-
if diags := s.diagnostics[name]; diags == nil || len(diags.Diagnostics) == 0 {
840-
return Met
841-
}
842-
return Unmet
843-
}
844-
return SimpleExpectation{
845-
check: check,
846-
description: fmt.Sprintf("empty or no diagnostics for %q", name),
847-
}
848-
}
849-
850833
// DiagnosticAtRegexp expects that there is a diagnostic entry at the start
851834
// position matching the regexp search string re in the buffer specified by
852835
// name. Note that this currently ignores the end position.

gopls/internal/regtest/codelens/codelens_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,13 @@ require golang.org/x/hello v1.2.3
215215
// but there may be some subtlety in timing here, where this
216216
// should always succeed, but may not actually test the correct
217217
// behavior.
218-
NoMatchingDiagnostics(env.AtRegexp("b/go.mod", `require`)),
218+
NoDiagnostics(env.AtRegexp("b/go.mod", `require`)),
219219
)
220220
// Check for upgrades in b/go.mod and then clear them.
221221
env.ExecuteCodeLensCommand("b/go.mod", command.CheckUpgrades, nil)
222222
env.Await(env.DiagnosticAtRegexpWithMessage("b/go.mod", `require`, "can be upgraded"))
223223
env.ExecuteCodeLensCommand("b/go.mod", command.ResetGoModDiagnostics, nil)
224-
env.Await(NoDiagnostics("b/go.mod"))
224+
env.Await(NoDiagnostics(ForFile("b/go.mod")))
225225

226226
// Apply the diagnostics to a/go.mod.
227227
env.ApplyQuickFixes("a/go.mod", d.Diagnostics)
@@ -331,6 +331,6 @@ func Foo() {
331331

332332
// Regenerate cgo, fixing the diagnostic.
333333
env.ExecuteCodeLensCommand("cgo.go", command.RegenerateCgo, nil)
334-
env.Await(NoDiagnostics("cgo.go"))
334+
env.Await(NoDiagnostics(ForFile("cgo.go")))
335335
})
336336
}

gopls/internal/regtest/codelens/gcdetails_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func main() {
6666
// Editing a buffer should cause gc_details diagnostics to disappear, since
6767
// they only apply to saved buffers.
6868
env.EditBuffer("main.go", fake.NewEdit(0, 0, 0, 0, "\n\n"))
69-
env.AfterChange(NoDiagnostics("main.go"))
69+
env.AfterChange(NoDiagnostics(ForFile("main.go")))
7070

7171
// Saving a buffer should re-format back to the original state, and
7272
// re-enable the gc_details diagnostics.
@@ -75,7 +75,7 @@ func main() {
7575

7676
// Toggle the GC details code lens again so now it should be off.
7777
env.ExecuteCodeLensCommand("main.go", command.GCDetails, nil)
78-
env.Await(NoDiagnostics("main.go"))
78+
env.Await(NoDiagnostics(ForFile("main.go")))
7979
})
8080
}
8181

gopls/internal/regtest/diagnostics/analysis_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ func main() {
4444
)
4545

4646
env.ApplyQuickFixes("main.go", d.Diagnostics)
47-
env.AfterChange(NoDiagnostics("main.go"))
47+
env.AfterChange(NoDiagnostics(ForFile("main.go")))
4848
})
4949
}

gopls/internal/regtest/diagnostics/builtin_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ const (
3030
if !strings.HasSuffix(name, "builtin.go") {
3131
t.Fatalf("jumped to %q, want builtin.go", name)
3232
}
33-
env.AfterChange(NoDiagnostics("builtin.go"))
33+
env.AfterChange(NoDiagnostics(ForFile("builtin.go")))
3434
})
3535
}

0 commit comments

Comments
 (0)