[clang-tools-extra] Reland "[clangd] Add feature modules registry" (PR #154836)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 17 01:22:05 PDT 2025


================
@@ -0,0 +1,66 @@
+//===--- FeatureModulesRegistryTests.cpp  ---------------------------------===//
+//
+// 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 "FeatureModule.h"
+#include "feature-modules/ForceLinker.h" // IWYU pragma: keep
+#include "refactor/Tweak.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using testing::ElementsAre;
+
+namespace llvm {
+raw_ostream &operator<<(raw_ostream &OS,
+                        const clang::clangd::FeatureModuleRegistry::entry &E) {
+  OS << "(name = " << E.getName() << ", description = '" << E.getDesc() << "')";
+  return OS;
+}
+
+raw_ostream &operator<<(
+    raw_ostream &OS,
+    const iterator_range<Registry<clang::clangd::FeatureModule>::iterator>
+        &Rng) {
+  OS << "{ ";
+  bool First = true;
+  for (clang::clangd::FeatureModuleRegistry::entry E : Rng) {
+    if (First)
+      First = false;
+    else
+      OS << ", ";
+    OS << E;
+  }
+  OS << " }";
+  return OS;
+}
+
+raw_ostream &operator<<(raw_ostream &OS, const clang::clangd::Tweak &T) {
+  OS << "(id = " << T.id() << ", "
+     << "title = " << T.title() << ")";
+  return OS;
+}
+} // namespace llvm
+
+namespace clang::clangd {
+namespace {
+
+MATCHER_P(moduleName, Name, "") { return arg.getName() == Name; }
+MATCHER_P(tweakID, ID, "") { return arg->id() == ID; }
+
+TEST(FeatureModulesRegistryTest, DummyModule) {
----------------
kadircet wrote:

so this test will break if someone links in feature modules to `clangDemon` instead of `clangd/tool`. I think that's a good thing, but we should mention that this is a deliberate call. can you add a comment saying we shouldn't have any featremodules linked to the unittests or clangd-as-a-library, and people should link their feature-modules through clangd/tool/CMakeLists.txt instead?

this test is very `strict` and I think that's a good thing, but we should be explicit about it.

https://github.com/llvm/llvm-project/pull/154836


More information about the cfe-commits mailing list