Skip to content

Commit 9a17454

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 (cherry picked from commit 55b0e9c)
1 parent 684c216 commit 9a17454

File tree

1 file changed

+28
-43
lines changed

1 file changed

+28
-43
lines changed

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

Lines changed: 28 additions & 43 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
ASSERT_TRUE(AST.getDiagnostics().empty());
586591

@@ -1590,6 +1595,26 @@ TEST(Hover, All) {
15901595
HI.Parameters = {
15911596
{std::string("int"), std::string("x"), llvm::None}};
15921597
}},
1598+
{
1599+
R"cpp(// sizeof expr
1600+
void foo() {
1601+
(void)[[size^of]](char);
1602+
})cpp",
1603+
[](HoverInfo &HI) {
1604+
HI.Name = "expression";
1605+
HI.Type = "unsigned long";
1606+
HI.Value = "1";
1607+
}},
1608+
{
1609+
R"cpp(// alignof expr
1610+
void foo() {
1611+
(void)[[align^of]](char);
1612+
})cpp",
1613+
[](HoverInfo &HI) {
1614+
HI.Name = "expression";
1615+
HI.Type = "unsigned long";
1616+
HI.Value = "1";
1617+
}},
15931618
};
15941619

15951620
// Create a tiny index, so tests above can verify documentation is fetched.
@@ -1607,6 +1632,9 @@ TEST(Hover, All) {
16071632
TestTU TU = TestTU::withCode(T.code());
16081633
TU.ExtraArgs.push_back("-std=c++17");
16091634
TU.ExtraArgs.push_back("-Wno-gnu-designator");
1635+
// Types might be different depending on the target triplet, we chose a
1636+
// fixed one to make sure tests passes on different platform.
1637+
TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
16101638
auto AST = TU.build();
16111639
for (const auto &D : AST.getDiagnostics())
16121640
ADD_FAILURE() << D;
@@ -1854,49 +1882,6 @@ Value = val
18541882
def)pt";
18551883
EXPECT_EQ(HI.present().asPlainText(), ExpectedPlaintext);
18561884
}
1857-
1858-
TEST(Hover, ExprTests) {
1859-
struct {
1860-
const char *const Code;
1861-
const std::function<void(HoverInfo &)> ExpectedBuilder;
1862-
} Cases[] = {
1863-
{
1864-
R"cpp(// sizeof expr
1865-
void foo() {
1866-
(void)[[size^of]](char);
1867-
})cpp",
1868-
[](HoverInfo &HI) {
1869-
HI.Name = "expression";
1870-
HI.Type = "unsigned long";
1871-
HI.Value = "1";
1872-
}},
1873-
{
1874-
R"cpp(// alignof expr
1875-
void foo() {
1876-
(void)[[align^of]](char);
1877-
})cpp",
1878-
[](HoverInfo &HI) {
1879-
HI.Name = "expression";
1880-
HI.Type = "unsigned long";
1881-
HI.Value = "1";
1882-
}},
1883-
};
1884-
for (const auto &C : Cases) {
1885-
Annotations T(C.Code);
1886-
TestTU TU = TestTU::withCode(T.code());
1887-
auto AST = TU.build();
1888-
for (const auto &D : AST.getDiagnostics())
1889-
ADD_FAILURE() << D;
1890-
1891-
auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
1892-
ASSERT_TRUE(H);
1893-
HoverInfo ExpectedHover;
1894-
C.ExpectedBuilder(ExpectedHover);
1895-
// We don't check for Type as it might differ on different platforms.
1896-
EXPECT_EQ(H->Name, ExpectedHover.Name);
1897-
EXPECT_EQ(H->Value, ExpectedHover.Value);
1898-
}
1899-
}
19001885
} // namespace
19011886
} // namespace clangd
19021887
} // namespace clang

0 commit comments

Comments
 (0)