Skip to content

Commit

Permalink
gopls/internal/regtest: eliminate EmptyDiagnostics
Browse files Browse the repository at this point in the history
It doesn't matter from the user's perspective whether gopls has sent
empty diagnostics, or no diagnostics. As long as we use an AfterChange
check (or have previously asserted that diagnostics are non-empty),
there is no problem replacing the EmptyDiagnostics expectation with
NoDiagnostics.

Using this principle, eliminate uses of EmptyDiagnostics.

Updates golang/go#39384

Change-Id: I5940c46bbb9943a930aeedbae74c3d3314b13574
Reviewed-on: https://go-review.googlesource.com/c/tools/+/461801
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
  • Loading branch information
findleyr committed Jan 13, 2023
1 parent e81af27 commit c9b82f2
Show file tree
Hide file tree
Showing 18 changed files with 237 additions and 286 deletions.
15 changes: 0 additions & 15 deletions gopls/internal/lsp/regtest/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,21 +717,6 @@ func NoOutstandingDiagnostics() Expectation {
}
}

// EmptyDiagnostics asserts that empty diagnostics are sent for the
// workspace-relative path name.
func EmptyDiagnostics(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 diagnostics for %q", name),
}
}

// NoDiagnostics asserts that either no diagnostics are sent for the
// workspace-relative path name, or empty diagnostics are sent.
func NoDiagnostics(name string) Expectation {
Expand Down
15 changes: 8 additions & 7 deletions gopls/internal/regtest/codelens/codelens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ require golang.org/x/hello v1.2.3
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(EmptyDiagnostics("b/go.mod"))
env.Await(NoDiagnostics("b/go.mod"))

// Apply the diagnostics to a/go.mod.
env.ApplyQuickFixes("a/go.mod", d.Diagnostics)
env.Await(env.DoneWithChangeWatchedFiles())
env.AfterChange()
if got := env.BufferText("a/go.mod"); got != wantGoModA {
t.Fatalf("a/go.mod upgrade failed:\n%s", compare.Text(wantGoModA, got))
}
Expand Down Expand Up @@ -320,18 +320,19 @@ func Foo() {
Run(t, workspace, func(t *testing.T, env *Env) {
// Open the file. We have a nonexistant symbol that will break cgo processing.
env.OpenFile("cgo.go")
env.Await(env.DiagnosticAtRegexpWithMessage("cgo.go", ``, "go list failed to return CompiledGoFiles"))
env.AfterChange(
env.DiagnosticAtRegexpWithMessage("cgo.go", ``, "go list failed to return CompiledGoFiles"),
)

// Fix the C function name. We haven't regenerated cgo, so nothing should be fixed.
env.RegexpReplace("cgo.go", `int fortythree`, "int fortytwo")
env.SaveBuffer("cgo.go")
env.Await(OnceMet(
env.DoneWithSave(),
env.AfterChange(
env.DiagnosticAtRegexpWithMessage("cgo.go", ``, "go list failed to return CompiledGoFiles"),
))
)

// Regenerate cgo, fixing the diagnostic.
env.ExecuteCodeLensCommand("cgo.go", command.RegenerateCgo, nil)
env.Await(EmptyDiagnostics("cgo.go"))
env.Await(NoDiagnostics("cgo.go"))
})
}
8 changes: 3 additions & 5 deletions gopls/internal/regtest/codelens/gcdetails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,16 @@ 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.Await(EmptyDiagnostics("main.go"))
env.AfterChange(NoDiagnostics("main.go"))

// Saving a buffer should re-format back to the original state, and
// re-enable the gc_details diagnostics.
env.SaveBuffer("main.go")
env.Await(DiagnosticAt("main.go", 5, 13))
env.AfterChange(DiagnosticAt("main.go", 5, 13))

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

Expand Down
13 changes: 4 additions & 9 deletions gopls/internal/regtest/diagnostics/analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,12 @@ func main() {
env.OpenFile("main.go")

var d protocol.PublishDiagnosticsParams
env.Await(
OnceMet(
env.DoneWithOpen(),
env.DiagnosticAtRegexp("main.go", "2006-02-01"),
ReadDiagnostics("main.go", &d),
),
env.AfterChange(
env.DiagnosticAtRegexp("main.go", "2006-02-01"),
ReadDiagnostics("main.go", &d),
)

env.ApplyQuickFixes("main.go", d.Diagnostics)
env.Await(
EmptyDiagnostics("main.go"),
)
env.AfterChange(NoDiagnostics("main.go"))
})
}
Loading

0 comments on commit c9b82f2

Please sign in to comment.