Skip to content

Commit 55b0e9c

Browse files
committed
[clangd][Hover] Make tests hermetic by setting target triplet
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
1 parent 0ee4b02 commit 55b0e9c

File tree

1 file changed

+28
-40
lines changed

1 file changed

+28
-40
lines changed

clang-tools-extra/clangd/unittests/HoverTests.cpp

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,12 @@ class Foo {})cpp";
580580
Annotations T(Case.Code);
581581
TestTU TU = TestTU::withCode(T.code());
582582
TU.ExtraArgs.push_back("-std=c++17");
583+
// FIXME: This is no longer necessary, as the default behavior is no delayed
584+
// parsing in the triplet below.
583585
TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
586+
// Types might be different depending on the target triplet, we chose a
587+
// fixed one to make sure tests passes on different platform.
588+
TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
584589
auto AST = TU.build();
585590

586591
auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
@@ -1587,6 +1592,26 @@ TEST(Hover, All) {
15871592
HI.Parameters = {
15881593
{std::string("int"), std::string("x"), llvm::None}};
15891594
}},
1595+
{
1596+
R"cpp(// sizeof expr
1597+
void foo() {
1598+
(void)[[size^of]](char);
1599+
})cpp",
1600+
[](HoverInfo &HI) {
1601+
HI.Name = "expression";
1602+
HI.Type = "unsigned long";
1603+
HI.Value = "1";
1604+
}},
1605+
{
1606+
R"cpp(// alignof expr
1607+
void foo() {
1608+
(void)[[align^of]](char);
1609+
})cpp",
1610+
[](HoverInfo &HI) {
1611+
HI.Name = "expression";
1612+
HI.Type = "unsigned long";
1613+
HI.Value = "1";
1614+
}},
15901615
};
15911616

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

16091637
auto H = getHover(AST, T.point(), format::getLLVMStyle(), Index.get());
@@ -1836,46 +1864,6 @@ Value = val
18361864
def)pt";
18371865
EXPECT_EQ(HI.present().asPlainText(), ExpectedPlaintext);
18381866
}
1839-
1840-
TEST(Hover, ExprTests) {
1841-
struct {
1842-
const char *const Code;
1843-
const std::function<void(HoverInfo &)> ExpectedBuilder;
1844-
} Cases[] = {
1845-
{
1846-
R"cpp(// sizeof expr
1847-
void foo() {
1848-
(void)[[size^of]](char);
1849-
})cpp",
1850-
[](HoverInfo &HI) {
1851-
HI.Name = "expression";
1852-
HI.Type = "unsigned long";
1853-
HI.Value = "1";
1854-
}},
1855-
{
1856-
R"cpp(// alignof expr
1857-
void foo() {
1858-
(void)[[align^of]](char);
1859-
})cpp",
1860-
[](HoverInfo &HI) {
1861-
HI.Name = "expression";
1862-
HI.Type = "unsigned long";
1863-
HI.Value = "1";
1864-
}},
1865-
};
1866-
for (const auto &C : Cases) {
1867-
Annotations T(C.Code);
1868-
TestTU TU = TestTU::withCode(T.code());
1869-
auto AST = TU.build();
1870-
auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
1871-
ASSERT_TRUE(H);
1872-
HoverInfo ExpectedHover;
1873-
C.ExpectedBuilder(ExpectedHover);
1874-
// We don't check for Type as it might differ on different platforms.
1875-
EXPECT_EQ(H->Name, ExpectedHover.Name);
1876-
EXPECT_EQ(H->Value, ExpectedHover.Value);
1877-
}
1878-
}
18791867
} // namespace
18801868
} // namespace clangd
18811869
} // namespace clang

0 commit comments

Comments
 (0)