Skip to content

Commit 2f04284

Browse files
committed
internal/lsp/regtest: allow for unsent diagnostics in TestResolveImportCycle
Gopls doesn't send empty diagnostics for open files in some cases (likely a race to context cancellation). This is probably a bug itself, but for now don't let this cause TestResolveImportCycle to fail. Added a TODO to investigate further. Fixes golang/go#46773 Change-Id: I197d9b09885951b47b3f90a0480ae75679d2a1a0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/333289 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 41a65bd commit 2f04284

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

gopls/internal/regtest/diagnostics/diagnostics_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,6 @@ import _ "mod.com/triple/a"
16181618
// Tests golang/go#46667: deleting a problematic import path should resolve
16191619
// import cycle errors.
16201620
func TestResolveImportCycle(t *testing.T) {
1621-
t.Skip("flaky test: see golang/go#46773")
16221621
const mod = `
16231622
-- go.mod --
16241623
module mod.test
@@ -1646,8 +1645,8 @@ const B = a.B
16461645
env.RegexpReplace("b/b.go", `const B = a\.B`, "")
16471646
env.SaveBuffer("b/b.go")
16481647
env.Await(
1649-
EmptyDiagnostics("a/a.go"),
1650-
EmptyDiagnostics("b/b.go"),
1648+
EmptyOrNoDiagnostics("a/a.go"),
1649+
EmptyOrNoDiagnostics("b/b.go"),
16511650
)
16521651
})
16531652
}

internal/lsp/regtest/expectation.go

+17
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,23 @@ func EmptyDiagnostics(name string) Expectation {
533533
}
534534
}
535535

536+
// EmptyOrNoDiagnostics asserts that either no diagnostics are sent for the
537+
// workspace-relative path name, or empty diagnostics are sent.
538+
// TODO(rFindley): this subtlety shouldn't be necessary. Gopls should always
539+
// send at least one diagnostic set for open files.
540+
func EmptyOrNoDiagnostics(name string) Expectation {
541+
check := func(s State) Verdict {
542+
if diags := s.diagnostics[name]; len(diags.Diagnostics) == 0 {
543+
return Met
544+
}
545+
return Unmet
546+
}
547+
return SimpleExpectation{
548+
check: check,
549+
description: fmt.Sprintf("empty or no diagnostics for %q", name),
550+
}
551+
}
552+
536553
// NoDiagnostics asserts that no diagnostics are sent for the
537554
// workspace-relative path name. It should be used primarily in conjunction
538555
// with a OnceMet, as it has to check that all outstanding diagnostics have

0 commit comments

Comments
 (0)