Skip to content

Commit 3fb02dd

Browse files
committed
changed withFix to containsFix in DiagnosticsTest to ignore NOLINT fix
1 parent f4c9f99 commit 3fb02dd

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ ::testing::Matcher<const Diag &> withFix(::testing::Matcher<Fix> FixMatcher1,
6969
return Field(&Diag::Fixes, UnorderedElementsAre(FixMatcher1, FixMatcher2));
7070
}
7171

72+
::testing::Matcher<const Diag &>
73+
containsFix(::testing::Matcher<Fix> FixMatcher) {
74+
return Field(&Diag::Fixes, Contains(FixMatcher));
75+
}
76+
7277
::testing::Matcher<const Diag &> withID(unsigned ID) {
7378
return Field(&Diag::ID, ID);
7479
}
@@ -1290,18 +1295,20 @@ TEST(IncludeFixerTest, IncompleteType) {
12901295
{"call_incomplete_argument", "int m(ns::X); int i = m([[*x]]);"},
12911296
{"switch_incomplete_class_type", "void a() { [[switch]](*x) {} }"},
12921297
{"delete_incomplete_class_type", "void f() { [[delete]] *x; }"},
1298+
// TODO: Add to test case
12931299
{"-Wdelete-incomplete", "void f() { [[delete]] x; }"},
12941300
{"dereference_incomplete_type",
12951301
R"cpp(void f() { asm("" : "=r"([[*]]x)::); })cpp"},
12961302
};
12971303
for (auto Case : Tests) {
12981304
Annotations Main(Case.second);
12991305
TU.Code = Main.code().str() + "\n // error-ok";
1300-
EXPECT_THAT(
1301-
TU.build().getDiagnostics(),
1302-
ElementsAre(AllOf(diagName(Case.first), hasRange(Main.range()),
1303-
withFix(Fix(Range{}, "#include \"x.h\"\n",
1304-
"Include \"x.h\" for symbol ns::X")))))
1306+
// TODO: maybe only do containsFix on -Wdelete-incomplete
1307+
EXPECT_THAT(TU.build().getDiagnostics(),
1308+
ElementsAre(AllOf(
1309+
diagName(Case.first), hasRange(Main.range()),
1310+
containsFix(Fix(Range{}, "#include \"x.h\"\n",
1311+
"Include \"x.h\" for symbol ns::X")))))
13051312
<< Case.second;
13061313
}
13071314
}
@@ -1662,17 +1669,18 @@ TEST(IncludeFixerTest, HeaderNamedInDiag) {
16621669
"with type 'int (const char *, ...)'; ISO C99 "
16631670
"and later do not support implicit function "
16641671
"declarations"),
1665-
withFix(Fix(Test.range("insert"), "#include <stdio.h>\n",
1666-
"Include <stdio.h> for symbol printf")))));
1672+
// TODO: Add to test case
1673+
containsFix(Fix(Test.range("insert"), "#include <stdio.h>\n",
1674+
"Include <stdio.h> for symbol printf")))));
16671675

16681676
TU.ExtraArgs = {"-xc", "-std=c89"};
16691677
EXPECT_THAT(
16701678
TU.build().getDiagnostics(),
16711679
ElementsAre(AllOf(
16721680
Diag(Test.range(), "implicitly declaring library function 'printf' "
16731681
"with type 'int (const char *, ...)'"),
1674-
withFix(Fix(Test.range("insert"), "#include <stdio.h>\n",
1675-
"Include <stdio.h> for symbol printf")))));
1682+
containsFix(Fix(Test.range("insert"), "#include <stdio.h>\n",
1683+
"Include <stdio.h> for symbol printf")))));
16761684
}
16771685

16781686
TEST(IncludeFixerTest, CImplicitFunctionDecl) {
@@ -1698,15 +1706,15 @@ TEST(IncludeFixerTest, CImplicitFunctionDecl) {
16981706
Diag(Test.range(),
16991707
"call to undeclared function 'foo'; ISO C99 and later do not "
17001708
"support implicit function declarations"),
1701-
withFix(Fix(Range{}, "#include \"foo.h\"\n",
1702-
"Include \"foo.h\" for symbol foo")))));
1709+
containsFix(Fix(Range{}, "#include \"foo.h\"\n",
1710+
"Include \"foo.h\" for symbol foo")))));
17031711

17041712
TU.ExtraArgs = {"-std=c89", "-Wall"};
17051713
EXPECT_THAT(TU.build().getDiagnostics(),
17061714
ElementsAre(AllOf(
17071715
Diag(Test.range(), "implicit declaration of function 'foo'"),
1708-
withFix(Fix(Range{}, "#include \"foo.h\"\n",
1709-
"Include \"foo.h\" for symbol foo")))));
1716+
containsFix(Fix(Range{}, "#include \"foo.h\"\n",
1717+
"Include \"foo.h\" for symbol foo")))));
17101718
}
17111719

17121720
TEST(DiagsInHeaders, DiagInsideHeader) {
@@ -1930,10 +1938,10 @@ TEST(ParsedASTTest, ModuleSawDiag) {
19301938
TestTU TU;
19311939

19321940
auto AST = TU.build();
1933-
#if 0
1941+
#if 0
19341942
EXPECT_THAT(AST.getDiagnostics(),
19351943
testing::Contains(Diag(Code.range(), KDiagMsg.str())));
1936-
#endif
1944+
#endif
19371945
}
19381946

19391947
TEST(Preamble, EndsOnNonEmptyLine) {

0 commit comments

Comments
 (0)