|
21 | 21 | #include "llvm/Support/VirtualFileSystem.h" |
22 | 22 | #include "gmock/gmock.h" |
23 | 23 | #include "gtest/gtest.h" |
| 24 | +#include <algorithm> |
24 | 25 | #include <memory> |
25 | 26 | #include <optional> |
26 | 27 | #include <vector> |
@@ -295,23 +296,35 @@ TEST_F(SuppressionMappingTest, EmitCategoryIsExcluded) { |
295 | 296 | } |
296 | 297 |
|
297 | 298 | TEST_F(SuppressionMappingTest, LongestMatchWins) { |
298 | | - llvm::StringLiteral SuppressionMappingFile = R"( |
299 | | - [unused] |
300 | | - src:*clang/* |
301 | | - src:*clang/lib/Sema/*=emit |
302 | | - src:*clang/lib/Sema/foo*)"; |
303 | | - Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt"; |
304 | | - FS->addFile("foo.txt", /*ModificationTime=*/{}, |
305 | | - llvm::MemoryBuffer::getMemBuffer(SuppressionMappingFile)); |
306 | | - clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS); |
307 | | - EXPECT_THAT(diags(), IsEmpty()); |
308 | | - |
309 | | - EXPECT_TRUE(Diags.isSuppressedViaMapping( |
310 | | - diag::warn_unused_function, locForFile("clang/lib/Basic/foo.h"))); |
311 | | - EXPECT_FALSE(Diags.isSuppressedViaMapping( |
312 | | - diag::warn_unused_function, locForFile("clang/lib/Sema/bar.h"))); |
313 | | - EXPECT_TRUE(Diags.isSuppressedViaMapping(diag::warn_unused_function, |
314 | | - locForFile("clang/lib/Sema/foo.h"))); |
| 299 | + StringRef Lines[] = { |
| 300 | + "[unused]", |
| 301 | + "src:*clang/*", |
| 302 | + "src:*clang/lib/Sema/*", |
| 303 | + "src:*clang/lib/Sema/*=emit", |
| 304 | + "src:*clang/lib/Sema/foo*", |
| 305 | + }; |
| 306 | + llvm::MutableArrayRef<StringRef> Rules = Lines; |
| 307 | + Rules = Rules.drop_front(); |
| 308 | + llvm::sort(Rules); |
| 309 | + |
| 310 | + do { |
| 311 | + Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt"; |
| 312 | + std::string Contents = join(std::begin(Lines), std::end(Lines), "\n"); |
| 313 | + FS->addFile("foo.txt", /*ModificationTime=*/{}, |
| 314 | + llvm::MemoryBuffer::getMemBuffer(Contents)); |
| 315 | + clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS); |
| 316 | + EXPECT_THAT(diags(), IsEmpty()); |
| 317 | + |
| 318 | + EXPECT_TRUE(Diags.isSuppressedViaMapping( |
| 319 | + diag::warn_unused_function, locForFile("clang/lib/Basic/foo.h"))) |
| 320 | + << Contents; |
| 321 | + EXPECT_FALSE(Diags.isSuppressedViaMapping( |
| 322 | + diag::warn_unused_function, locForFile("clang/lib/Sema/bar.h"))) |
| 323 | + << Contents; |
| 324 | + EXPECT_TRUE(Diags.isSuppressedViaMapping( |
| 325 | + diag::warn_unused_function, locForFile("clang/lib/Sema/foo.h"))) |
| 326 | + << Contents; |
| 327 | + } while (std::next_permutation(Rules.begin(), Rules.end())); |
315 | 328 | } |
316 | 329 |
|
317 | 330 | TEST_F(SuppressionMappingTest, LongShortMatch) { |
|
0 commit comments