1111#include " ConfigTesting.h"
1212#include " Features.inc"
1313#include " TestFS.h"
14+ #include " clang/Basic/DiagnosticSema.h"
1415#include " llvm/ADT/None.h"
1516#include " llvm/ADT/Optional.h"
1617#include " llvm/ADT/StringRef.h"
@@ -30,6 +31,7 @@ using ::testing::ElementsAre;
3031using ::testing::IsEmpty;
3132using ::testing::SizeIs;
3233using ::testing::StartsWith;
34+ using ::testing::UnorderedElementsAre;
3335
3436class ConfigCompileTests : public ::testing::Test {
3537protected:
@@ -183,6 +185,39 @@ TEST_F(ConfigCompileTests, PathSpecMatch) {
183185 }
184186}
185187
188+ TEST_F (ConfigCompileTests, DiagnosticSuppression) {
189+ Frag.Diagnostics .Suppress .emplace_back (" bugprone-use-after-move" );
190+ Frag.Diagnostics .Suppress .emplace_back (" unreachable-code" );
191+ Frag.Diagnostics .Suppress .emplace_back (" -Wunused-variable" );
192+ Frag.Diagnostics .Suppress .emplace_back (" typecheck_bool_condition" );
193+ Frag.Diagnostics .Suppress .emplace_back (" err_unexpected_friend" );
194+ Frag.Diagnostics .Suppress .emplace_back (" warn_alloca" );
195+ EXPECT_TRUE (compileAndApply ());
196+ EXPECT_THAT (Conf.Diagnostics .Suppress .keys (),
197+ UnorderedElementsAre (" bugprone-use-after-move" ,
198+ " unreachable-code" , " unused-variable" ,
199+ " typecheck_bool_condition" ,
200+ " unexpected_friend" , " warn_alloca" ));
201+ EXPECT_TRUE (isBuiltinDiagnosticSuppressed (diag::warn_unreachable,
202+ Conf.Diagnostics .Suppress ));
203+ // Subcategory not respected/suppressed.
204+ EXPECT_FALSE (isBuiltinDiagnosticSuppressed (diag::warn_unreachable_break,
205+ Conf.Diagnostics .Suppress ));
206+ EXPECT_TRUE (isBuiltinDiagnosticSuppressed (diag::warn_unused_variable,
207+ Conf.Diagnostics .Suppress ));
208+ EXPECT_TRUE (isBuiltinDiagnosticSuppressed (diag::err_typecheck_bool_condition,
209+ Conf.Diagnostics .Suppress ));
210+ EXPECT_TRUE (isBuiltinDiagnosticSuppressed (diag::err_unexpected_friend,
211+ Conf.Diagnostics .Suppress ));
212+ EXPECT_TRUE (isBuiltinDiagnosticSuppressed (diag::warn_alloca,
213+ Conf.Diagnostics .Suppress ));
214+
215+ Frag.Diagnostics .Suppress .emplace_back (" *" );
216+ EXPECT_TRUE (compileAndApply ());
217+ EXPECT_TRUE (Conf.Diagnostics .SuppressAll );
218+ EXPECT_THAT (Conf.Diagnostics .Suppress , IsEmpty ());
219+ }
220+
186221TEST_F (ConfigCompileTests, Tidy) {
187222 Frag.ClangTidy .Add .emplace_back (" bugprone-use-after-move" );
188223 Frag.ClangTidy .Add .emplace_back (" llvm-*" );
0 commit comments