gopls/internal/lsp/regtest: fix TestRunGovulncheckError2
Changes CompletedProgress to take an optional WorkState
which is filled when the expectation is met (i.e. completed progress)
Fixes golang/go#57032
Change-Id: Ie876d4d5a739e31b758b5affa2e9d6e4fb772dd5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/454775
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
diff --git a/gopls/internal/lsp/regtest/env.go b/gopls/internal/lsp/regtest/env.go
index 96c3db3..192e8ed 100644
--- a/gopls/internal/lsp/regtest/env.go
+++ b/gopls/internal/lsp/regtest/env.go
@@ -125,9 +125,9 @@
}
type workProgress struct {
- title, msg string
- percent float64
- complete bool
+ title, msg, endMsg string
+ percent float64
+ complete bool // seen 'end'.
}
// This method, provided for debugging, accesses mutable fields without a lock,
@@ -247,6 +247,9 @@
}
case "end":
work.complete = true
+ if msg, ok := v["message"]; ok {
+ work.endMsg = msg.(string)
+ }
}
a.checkConditionsLocked()
return nil
diff --git a/gopls/internal/lsp/regtest/expectation.go b/gopls/internal/lsp/regtest/expectation.go
index c365ae9..c30a075 100644
--- a/gopls/internal/lsp/regtest/expectation.go
+++ b/gopls/internal/lsp/regtest/expectation.go
@@ -380,18 +380,30 @@
}
}
+type WorkStatus struct {
+ // Last seen message from either `begin` or `report` progress.
+ Msg string
+ // Message sent with `end` progress message.
+ EndMsg string
+}
+
// CompletedProgress expects that workDone progress is complete for the given
-// progress token.
+// progress token. When non-nil WorkStatus is provided, it will be filled
+// when the expectation is met.
//
// If the token is not a progress token that the client has seen, this
// expectation is Unmeetable.
-func CompletedProgress(token protocol.ProgressToken) SimpleExpectation {
+func CompletedProgress(token protocol.ProgressToken, into *WorkStatus) SimpleExpectation {
check := func(s State) Verdict {
work, ok := s.work[token]
if !ok {
return Unmeetable // TODO(rfindley): refactor to allow the verdict to explain this result
}
if work.complete {
+ if into != nil {
+ into.Msg = work.msg
+ into.EndMsg = work.endMsg
+ }
return Met
}
return Unmet
diff --git a/gopls/internal/regtest/misc/vuln_test.go b/gopls/internal/regtest/misc/vuln_test.go
index 18e500c..12492d2 100644
--- a/gopls/internal/regtest/misc/vuln_test.go
+++ b/gopls/internal/regtest/misc/vuln_test.go
@@ -57,7 +57,6 @@
}
func TestRunGovulncheckError2(t *testing.T) {
- t.Skip("skipping due to go.dev/issues/57032")
const files = `
-- go.mod --
module mod.com
@@ -81,13 +80,14 @@
env.OpenFile("go.mod")
var result command.RunVulncheckResult
env.ExecuteCodeLensCommand("go.mod", command.RunGovulncheck, &result)
+ var ws WorkStatus
env.Await(
- OnceMet(
- CompletedProgress(result.Token),
- // TODO(hyangah): find a way to inspect $/progress 'report' message.
- LogMatching(protocol.Info, "failed to load packages due to errors", 1, false),
- ),
+ CompletedProgress(result.Token, &ws),
)
+ wantEndMsg, wantMsgPart := "failed", "failed to load packages due to errors"
+ if ws.EndMsg != "failed" || !strings.Contains(ws.Msg, wantMsgPart) {
+ t.Errorf("work status = %+v, want {EndMessage: %q, Message: %q}", ws, wantEndMsg, wantMsgPart)
+ }
})
}
@@ -227,7 +227,7 @@
env.Await(
OnceMet(
- CompletedProgress(result.Token),
+ CompletedProgress(result.Token, nil),
ShownMessage("Found GOSTDLIB"),
EmptyOrNoDiagnostics("go.mod"),
),
@@ -588,7 +588,7 @@
gotDiagnostics := &protocol.PublishDiagnosticsParams{}
env.Await(
OnceMet(
- CompletedProgress(result.Token),
+ CompletedProgress(result.Token, nil),
ShownMessage("Found"),
),
)
@@ -638,7 +638,7 @@
gotDiagnostics := &protocol.PublishDiagnosticsParams{}
env.Await(
OnceMet(
- CompletedProgress(result.Token),
+ CompletedProgress(result.Token, nil),
ShownMessage("Found"),
),
)
@@ -799,7 +799,7 @@
gotDiagnostics := &protocol.PublishDiagnosticsParams{}
env.Await(
OnceMet(
- CompletedProgress(result.Token),
+ CompletedProgress(result.Token, nil),
ShownMessage("No vulnerabilities found"), // only count affecting vulnerabilities.
),
)