diff options
author | Ellis Hoag <ellis.sparky.hoag@gmail.com> | 2023-08-14 13:46:03 -0700 |
---|---|---|
committer | Ellis Hoag <ellis.sparky.hoag@gmail.com> | 2023-08-14 13:46:21 -0700 |
commit | 9e11d6850a5a5a3518f300769724a5c13d2e6ec6 (patch) | |
tree | 1a43e72ab1686ce27d1ad0ae98b65bf74ce1f1ff /clang/unittests/Tooling/CompilationDatabaseTest.cpp | |
parent | 00bc5008307c3e9daccf5cbc08ee875c74c25431 (diff) | |
download | llvm-9e11d6850a5a5a3518f300769724a5c13d2e6ec6.zip llvm-9e11d6850a5a5a3518f300769724a5c13d2e6ec6.tar.gz llvm-9e11d6850a5a5a3518f300769724a5c13d2e6ec6.tar.bz2 |
Improve reliability of CompilationDatabaseTest
We've seen `CompilationDatabaseTest.cpp` fail because the order of the files returned by `getAllFiles()` was in a different order than expected. Use `UnorderedElementsAreArray()` to handle different file orders.
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D157904
Diffstat (limited to 'clang/unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/CompilationDatabaseTest.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp index ee91af7a..5173d47 100644 --- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp @@ -6,9 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "clang/AST/DeclCXX.h" -#include "clang/AST/DeclGroup.h" -#include "clang/Frontend/FrontendAction.h" #include "clang/Tooling/CompilationDatabase.h" #include "clang/Tooling/FileMatchTrie.h" #include "clang/Tooling/JSONCompilationDatabase.h" @@ -24,6 +21,8 @@ namespace tooling { using testing::ElementsAre; using testing::EndsWith; +using testing::IsEmpty; +using testing::UnorderedElementsAreArray; static void expectFailure(StringRef JSONDatabase, StringRef Explanation) { std::string ErrorMessage; @@ -83,8 +82,8 @@ getAllCompileCommands(JSONCommandLineSyntax Syntax, StringRef JSONDatabase, TEST(JSONCompilationDatabase, GetAllFiles) { std::string ErrorMessage; - EXPECT_EQ(std::vector<std::string>(), - getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu)) + EXPECT_THAT(getAllFiles("[]", ErrorMessage, JSONCommandLineSyntax::Gnu), + IsEmpty()) << ErrorMessage; std::vector<std::string> expected_files; @@ -97,8 +96,7 @@ TEST(JSONCompilationDatabase, GetAllFiles) { expected_files.push_back(std::string(PathStorage.str())); llvm::sys::path::native("//net/file1", PathStorage); expected_files.push_back(std::string(PathStorage.str())); - EXPECT_EQ(expected_files, - getAllFiles(R"json( + EXPECT_THAT(getAllFiles(R"json( [ { "directory": "//net/dir", @@ -121,7 +119,8 @@ TEST(JSONCompilationDatabase, GetAllFiles) { "file": "//net/dir/foo/../file3" } ])json", - ErrorMessage, JSONCommandLineSyntax::Gnu)) + ErrorMessage, JSONCommandLineSyntax::Gnu), + UnorderedElementsAreArray(expected_files)) << ErrorMessage; } @@ -550,7 +549,7 @@ TEST(FixedCompilationDatabase, GetAllFiles) { CommandLine.push_back("two"); FixedCompilationDatabase Database(".", CommandLine); - EXPECT_EQ(0ul, Database.getAllFiles().size()); + EXPECT_THAT(Database.getAllFiles(), IsEmpty()); } TEST(FixedCompilationDatabase, GetAllCompileCommands) { |