================
@@ -107,6 +113,52 @@ MATCHER_P(rangeIs, R, "") {
   return arg.beginOffset() == R.Begin && arg.endOffset() == R.End;
 }
 
+TEST(ReplayPreambleTest, MacroDefinitions) {
+  DefinedMacros.clear();
+
+  TestTU TU;
+  TU.ClangTidyProvider = addTidyChecks(CheckName);
+  TU.Code = R"cpp(
+      #ifndef _TEST_H
+      #define _TEST_H
+      #define _TEST_MACRO
+      #endif
+  )cpp";
+
+  Config Cfg;
+  Cfg.Diagnostics.ClangTidy.FastCheckFilter = Config::FastCheckPolicy::Loose;
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+
+  TU.build();
+
+  EXPECT_THAT(DefinedMacros, testing::Contains(std::string("_TEST_H")));
+  EXPECT_THAT(DefinedMacros, testing::Contains(std::string("_TEST_MACRO")));
----------------
ArcsinX wrote:

nit: I think we can use macros from the AST instead of manually writing 
`"_TEST_MACRO"` and `"_TEST_H"`.

Something like this:
```cpp
  auto AST = TU.build();
  EXPECT_THAT(AST.getMacros().Names.keys(),
              testing::UnorderedElementsAreArray(DefinedMacros));
```

We can assume that `AST.getMacros().Names` is correct, because we already have 
tests in `PreambleTest.cpp` for this.

https://github.com/llvm/llvm-project/pull/202495
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to