[Lldb-commits] [lldb] [lldb-dap] Refactor handling progress events. (PR #224957)
Sergei Druzhkov via lldb-commits
lldb-commits at lists.llvm.org
Mon Sep 21 00:49:21 PDT 2026
================
@@ -0,0 +1,254 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "ProgressEvent.h"
+#include "Protocol/ProtocolBase.h"
+#include "TestingSupport/TestUtilities.h"
+#include "llvm/Support/JSON.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include <chrono>
+#include <string>
+#include <utility>
+#include <vector>
+
+using namespace lldb_dap;
+using namespace lldb_dap::protocol;
+using namespace std::chrono_literals;
+
+using ::testing::AllOf;
+using ::testing::ElementsAre;
+using ::testing::IsEmpty;
+
+namespace lldb_dap::protocol {
+// For formatted error messages.
+// see https://google.github.io/googletest/advanced.html.
+void PrintTo(const Event &e, std::ostream *os) {
+ *os << lldb_private::PrettyPrint(toJSON(e));
+}
+} // namespace lldb_dap::protocol
+
+namespace {
+
+const llvm::json::Value *BodyField(const Event &e, llvm::StringRef key) {
+ if (!e.body)
+ return nullptr;
+ const auto *obj = e.body->getAsObject();
+ if (!obj)
+ return nullptr;
+ return obj->get(key);
+}
+
+std::string BodyFieldStr(const Event &e, llvm::StringRef key) {
+ const auto *v = BodyField(e, key);
+ if (!v)
+ return {};
+ return v->getAsString().value_or("").str();
+}
+
+MATCHER_P(ProgressKind, kind,
+ "event.event is " + testing::PrintToString(kind)) {
+ return arg.event == std::string(kind);
+}
+
+MATCHER_P(HasId, id, "body.progressId is " + testing::PrintToString(id)) {
+ return BodyFieldStr(arg, "progressId") == std::to_string(id);
+}
+
+MATCHER_P(HasMessage, message,
+ "body.message is " + testing::PrintToString(message)) {
+ return BodyFieldStr(arg, "message") == std::string(message);
+}
+
+MATCHER_P(HasTitle, title, "body.title is " + testing::PrintToString(title)) {
+ return BodyFieldStr(arg, "title") == std::string(title);
+}
+
+MATCHER(HasNoPercentage, "body has no percentage field") {
+ return BodyField(arg, "percentage") == nullptr;
+}
+
+MATCHER_P(HasPercentage, expected,
+ "body.percentage is " + testing::PrintToString(expected)) {
+ const auto *v = BodyField(arg, "percentage");
+ if (!v)
+ return false;
+ auto n = v->getAsNumber();
+ return n && *n == expected;
+}
+
+template <typename... Fields>
+auto Progress(llvm::StringRef kind, Fields &&...fields) {
+ return AllOf(ProgressKind(kind), std::forward<Fields>(fields)...);
+}
+
+class ProgressEventReporterTest : public ::testing::Test {
+protected:
+ ProgressEventReporter::TimePoint now{std::chrono::seconds(0)};
+ std::vector<Event> sent_events;
+ protocol::Id seq_id;
----------------
DrSergei wrote:
`protocol::Id seq_id = 0`
https://github.com/llvm/llvm-project/pull/224957
More information about the lldb-commits
mailing list