Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/clangd/unittests/PreambleTests.cpp
Show First 20 Lines • Show All 282 Lines • ▼ Show 20 Lines | struct { | ||||
const char *const Contents; | const char *const Contents; | ||||
const char *const ExpectedPatch; | const char *const ExpectedPatch; | ||||
} Cases[] = { | } Cases[] = { | ||||
{ | { | ||||
R"cpp( | R"cpp( | ||||
#define BAR | #define BAR | ||||
[[BAR]])cpp", | [[BAR]])cpp", | ||||
R"cpp(#line 0 ".*main.cpp" | R"cpp(#line 0 ".*main.cpp" | ||||
#undef BAR | |||||
#line 2 | #line 2 | ||||
#define BAR | #define BAR | ||||
)cpp", | )cpp", | ||||
}, | }, | ||||
// multiline macro | // multiline macro | ||||
{ | { | ||||
R"cpp( | R"cpp( | ||||
#define BAR \ | #define BAR \ | ||||
[[BAR]])cpp", | [[BAR]])cpp", | ||||
R"cpp(#line 0 ".*main.cpp" | R"cpp(#line 0 ".*main.cpp" | ||||
#undef BAR | |||||
#line 2 | #line 2 | ||||
#define BAR | #define BAR | ||||
)cpp", | )cpp", | ||||
}, | }, | ||||
// multiline macro | // multiline macro | ||||
{ | { | ||||
R"cpp( | R"cpp( | ||||
#define \ | #define \ | ||||
BAR | BAR | ||||
[[BAR]])cpp", | [[BAR]])cpp", | ||||
R"cpp(#line 0 ".*main.cpp" | R"cpp(#line 0 ".*main.cpp" | ||||
#undef BAR | |||||
#line 3 | #line 3 | ||||
#define BAR | #define BAR | ||||
)cpp", | )cpp", | ||||
}, | }, | ||||
}; | }; | ||||
for (const auto &Case : Cases) { | for (const auto &Case : Cases) { | ||||
SCOPED_TRACE(Case.Contents); | SCOPED_TRACE(Case.Contents); | ||||
Show All 16 Lines | TEST(PreamblePatchTest, OrderingPreserved) { | ||||
llvm::StringLiteral Baseline = "#define BAR(X) X"; | llvm::StringLiteral Baseline = "#define BAR(X) X"; | ||||
Annotations Modified(R"cpp( | Annotations Modified(R"cpp( | ||||
#define BAR(X, Y) X Y | #define BAR(X, Y) X Y | ||||
#define BAR(X) X | #define BAR(X) X | ||||
[[BAR]](int y); | [[BAR]](int y); | ||||
)cpp"); | )cpp"); | ||||
llvm::StringLiteral ExpectedPatch(R"cpp(#line 0 ".*main.cpp" | llvm::StringLiteral ExpectedPatch(R"cpp(#line 0 ".*main.cpp" | ||||
#undef BAR | |||||
#line 2 | #line 2 | ||||
#define BAR\(X, Y\) X Y | #define BAR\(X, Y\) X Y | ||||
#undef BAR | |||||
#line 3 | #line 3 | ||||
#define BAR\(X\) X | #define BAR\(X\) X | ||||
)cpp"); | )cpp"); | ||||
EXPECT_THAT(getPreamblePatch(Baseline, Modified.code()), | EXPECT_THAT(getPreamblePatch(Baseline, Modified.code()), | ||||
MatchesRegex(ExpectedPatch.str())); | MatchesRegex(ExpectedPatch.str())); | ||||
auto AST = createPatchedAST(Baseline, Modified.code()); | auto AST = createPatchedAST(Baseline, Modified.code()); | ||||
ASSERT_TRUE(AST); | ASSERT_TRUE(AST); | ||||
▲ Show 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | $foo[[#include "foo.h"]])"); | ||||
auto AST = createPatchedAST(Code.code(), NewCode.code(), AdditionalFiles); | auto AST = createPatchedAST(Code.code(), NewCode.code(), AdditionalFiles); | ||||
EXPECT_THAT( | EXPECT_THAT( | ||||
*AST->getDiagnostics(), | *AST->getDiagnostics(), | ||||
UnorderedElementsAre(Diag(NewCode.range("bar"), "unused-includes"), | UnorderedElementsAre(Diag(NewCode.range("bar"), "unused-includes"), | ||||
Diag(NewCode.range("foo"), "unused-includes"))); | Diag(NewCode.range("foo"), "unused-includes"))); | ||||
} | } | ||||
{ | { | ||||
Annotations Code("#define [[FOO]] 1\n"); | Annotations Code("#define [[FOO]] 1\n"); | ||||
// Check ranges for notes. | // Check ranges for notes. | ||||
Annotations NewCode(R"(#define $barxyz[[BARXYZ]] 1 | Annotations NewCode(R"(#define BARXYZ 1 | ||||
sammccall: as elsewhere, I think this writing this as a single raw string without reusing BaselinePreamble… | |||||
#define $foo1[[FOO]] 1 | #define $foo1[[FOO]] 1 | ||||
void foo(); | void foo(); | ||||
#define $foo2[[FOO]] 2)"); | #define $foo2[[FOO]] 2)"); | ||||
auto AST = createPatchedAST(Code.code(), NewCode.code(), AdditionalFiles); | auto AST = createPatchedAST(Code.code(), NewCode.code(), AdditionalFiles); | ||||
EXPECT_THAT( | EXPECT_THAT( | ||||
*AST->getDiagnostics(), | *AST->getDiagnostics(), | ||||
ElementsAre( | ElementsAre(AllOf( | ||||
// FIXME: This diagnostics shouldn't exist. It's emitted from the | |||||
// preamble patch to the stale location inside preamble. | |||||
AllOf(Field(&Diag::Name, Eq("-Wmacro-redefined")), | |||||
Field(&Diag::File, HasSubstr("_preamble_patch_")), | |||||
withNote(Diag(NewCode.range("barxyz")))), | |||||
AllOf( | |||||
Diag(NewCode.range("foo2"), "-Wmacro-redefined"), | Diag(NewCode.range("foo2"), "-Wmacro-redefined"), | ||||
// FIXME: This should be translated into main file. | // FIXME: This should be translated into main file. | ||||
withNote(Field(&Note::File, HasSubstr("_preamble_patch_")))))); | withNote(Field(&Note::File, HasSubstr("_preamble_patch_")))))); | ||||
named ranges sammccall: named ranges | |||||
} | } | ||||
} | } | ||||
TEST(PreamblePatch, TranslatesDiagnosticsInPreamble) { | TEST(PreamblePatch, TranslatesDiagnosticsInPreamble) { | ||||
Config Cfg; | Config Cfg; | ||||
Cfg.Diagnostics.AllowStalePreamble = true; | Cfg.Diagnostics.AllowStalePreamble = true; | ||||
WithContextValue WithCfg(Config::Key, std::move(Cfg)); | WithContextValue WithCfg(Config::Key, std::move(Cfg)); | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |
as elsewhere, I think this writing this as a single raw string without reusing BaselinePreamble is easier to follow