Skip to content

Commit

Permalink
gopls/internal/regtest: replace NoDiagnostics with NoMatchingDiagnostics
Browse files Browse the repository at this point in the history
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 <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
findleyr committed Jan 13, 2023
1 parent 87092c8 commit 27dfeb2
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 147 deletions.
27 changes: 5 additions & 22 deletions gopls/internal/lsp/regtest/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,10 @@ func Diagnostics(filters ...DiagnosticFilter) Expectation {
}
}

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

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

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

// NoDiagnostics asserts that either no diagnostics are sent for the
// workspace-relative path name, or empty diagnostics are sent.
func NoDiagnostics(name string) Expectation {
check := func(s State) Verdict {
if diags := s.diagnostics[name]; diags == nil || len(diags.Diagnostics) == 0 {
return Met
}
return Unmet
}
return SimpleExpectation{
check: check,
description: fmt.Sprintf("empty or no diagnostics for %q", name),
}
}

// DiagnosticAtRegexp expects that there is a diagnostic entry at the start
// position matching the regexp search string re in the buffer specified by
// name. Note that this currently ignores the end position.
Expand Down
6 changes: 3 additions & 3 deletions gopls/internal/regtest/codelens/codelens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ require golang.org/x/hello v1.2.3
// but there may be some subtlety in timing here, where this
// should always succeed, but may not actually test the correct
// behavior.
NoMatchingDiagnostics(env.AtRegexp("b/go.mod", `require`)),
NoDiagnostics(env.AtRegexp("b/go.mod", `require`)),
)
// Check for upgrades in b/go.mod and then clear them.
env.ExecuteCodeLensCommand("b/go.mod", command.CheckUpgrades, nil)
env.Await(env.DiagnosticAtRegexpWithMessage("b/go.mod", `require`, "can be upgraded"))
env.ExecuteCodeLensCommand("b/go.mod", command.ResetGoModDiagnostics, nil)
env.Await(NoDiagnostics("b/go.mod"))
env.Await(NoDiagnostics(ForFile("b/go.mod")))

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

// Regenerate cgo, fixing the diagnostic.
env.ExecuteCodeLensCommand("cgo.go", command.RegenerateCgo, nil)
env.Await(NoDiagnostics("cgo.go"))
env.Await(NoDiagnostics(ForFile("cgo.go")))
})
}
4 changes: 2 additions & 2 deletions gopls/internal/regtest/codelens/gcdetails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func main() {
// Editing a buffer should cause gc_details diagnostics to disappear, since
// they only apply to saved buffers.
env.EditBuffer("main.go", fake.NewEdit(0, 0, 0, 0, "\n\n"))
env.AfterChange(NoDiagnostics("main.go"))
env.AfterChange(NoDiagnostics(ForFile("main.go")))

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

// Toggle the GC details code lens again so now it should be off.
env.ExecuteCodeLensCommand("main.go", command.GCDetails, nil)
env.Await(NoDiagnostics("main.go"))
env.Await(NoDiagnostics(ForFile("main.go")))
})
}

Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/regtest/diagnostics/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ func main() {
)

env.ApplyQuickFixes("main.go", d.Diagnostics)
env.AfterChange(NoDiagnostics("main.go"))
env.AfterChange(NoDiagnostics(ForFile("main.go")))
})
}
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 @@ -30,6 +30,6 @@ const (
if !strings.HasSuffix(name, "builtin.go") {
t.Fatalf("jumped to %q, want builtin.go", name)
}
env.AfterChange(NoDiagnostics("builtin.go"))
env.AfterChange(NoDiagnostics(ForFile("builtin.go")))
})
}
Loading

0 comments on commit 27dfeb2

Please sign in to comment.