Skip to content

Commit

Permalink
[clangd][Hover] Make tests hermetic by setting target triplet
Browse files Browse the repository at this point in the history
Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=44696

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73613
  • Loading branch information
kadircet committed Jan 29, 2020
1 parent 0ee4b02 commit 55b0e9c
Showing 1 changed file with 28 additions and 40 deletions.
68 changes: 28 additions & 40 deletions clang-tools-extra/clangd/unittests/HoverTests.cpp
Expand Up @@ -580,7 +580,12 @@ class Foo {})cpp";
Annotations T(Case.Code);
TestTU TU = TestTU::withCode(T.code());
TU.ExtraArgs.push_back("-std=c++17");
// FIXME: This is no longer necessary, as the default behavior is no delayed
// parsing in the triplet below.
TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
// Types might be different depending on the target triplet, we chose a
// fixed one to make sure tests passes on different platform.
TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
auto AST = TU.build();

auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
Expand Down Expand Up @@ -1587,6 +1592,26 @@ TEST(Hover, All) {
HI.Parameters = {
{std::string("int"), std::string("x"), llvm::None}};
}},
{
R"cpp(// sizeof expr
void foo() {
(void)[[size^of]](char);
})cpp",
[](HoverInfo &HI) {
HI.Name = "expression";
HI.Type = "unsigned long";
HI.Value = "1";
}},
{
R"cpp(// alignof expr
void foo() {
(void)[[align^of]](char);
})cpp",
[](HoverInfo &HI) {
HI.Name = "expression";
HI.Type = "unsigned long";
HI.Value = "1";
}},
};

// Create a tiny index, so tests above can verify documentation is fetched.
Expand All @@ -1604,6 +1629,9 @@ TEST(Hover, All) {
TestTU TU = TestTU::withCode(T.code());
TU.ExtraArgs.push_back("-std=c++17");
TU.ExtraArgs.push_back("-Wno-gnu-designator");
// Types might be different depending on the target triplet, we chose a
// fixed one to make sure tests passes on different platform.
TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
auto AST = TU.build();

auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get());
Expand Down Expand Up @@ -1836,46 +1864,6 @@ Value = val
def)pt";
EXPECT_EQ(HI.present().asPlainText(), ExpectedPlaintext);
}

TEST(Hover, ExprTests) {
struct {
const char *const Code;
const std::function<void(HoverInfo &)> ExpectedBuilder;
} Cases[] = {
{
R"cpp(// sizeof expr
void foo() {
(void)[[size^of]](char);
})cpp",
[](HoverInfo &HI) {
HI.Name = "expression";
HI.Type = "unsigned long";
HI.Value = "1";
}},
{
R"cpp(// alignof expr
void foo() {
(void)[[align^of]](char);
})cpp",
[](HoverInfo &HI) {
HI.Name = "expression";
HI.Type = "unsigned long";
HI.Value = "1";
}},
};
for (const auto &C : Cases) {
Annotations T(C.Code);
TestTU TU = TestTU::withCode(T.code());
auto AST = TU.build();
auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
ASSERT_TRUE(H);
HoverInfo ExpectedHover;
C.ExpectedBuilder(ExpectedHover);
// We don't check for Type as it might differ on different platforms.
EXPECT_EQ(H->Name, ExpectedHover.Name);
EXPECT_EQ(H->Value, ExpectedHover.Value);
}
}
} // namespace
} // namespace clangd
} // namespace clang

0 comments on commit 55b0e9c

Please sign in to comment.