diff options
author | Argyrios Kyrtzidis <kyrtzidis@apple.com> | 2022-07-15 17:31:49 -0700 |
---|---|---|
committer | Argyrios Kyrtzidis <kyrtzidis@apple.com> | 2022-07-18 09:37:17 -0700 |
commit | fbbabd4ca06a030b714220f17b1c6e74a9ea3c4d (patch) | |
tree | 96dfa3fb7ca5f37fb1a9fa9605af9ad094576613 /clang/unittests | |
parent | b3fd3a9ac3eb31bc478abeefe64c05bfbecd3233 (diff) | |
download | llvm-fbbabd4ca06a030b714220f17b1c6e74a9ea3c4d.zip llvm-fbbabd4ca06a030b714220f17b1c6e74a9ea3c4d.tar.gz llvm-fbbabd4ca06a030b714220f17b1c6e74a9ea3c4d.tar.bz2 |
[Tooling/DependencyScanning] Enable passing a `vfs::FileSystem` object to `DependencyScanningTool`
Also include a unit test to validate that the `vfs::FileSystem` object is properly used.
Differential Revision: https://reviews.llvm.org/D129912
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/Tooling/DependencyScannerTest.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/clang/unittests/Tooling/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScannerTest.cpp index 6480cea..0e24980 100644 --- a/clang/unittests/Tooling/DependencyScannerTest.cpp +++ b/clang/unittests/Tooling/DependencyScannerTest.cpp @@ -14,19 +14,21 @@ #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Tooling/CompilationDatabase.h" -#include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h" +#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h" #include "clang/Tooling/Tooling.h" #include "llvm/ADT/STLExtras.h" #include "llvm/MC/TargetRegistry.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/Path.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include <algorithm> #include <string> using namespace clang; using namespace tooling; +using namespace dependencies; namespace { @@ -203,3 +205,33 @@ TEST(DependencyScanner, ScanDepsReuseFilemanagerHasInclude) { EXPECT_EQ(convert_to_slash(Deps[4]), "/root/header.h"); EXPECT_EQ(convert_to_slash(Deps[5]), "/root/symlink.h"); } + +TEST(DependencyScanner, ScanDepsWithFS) { + std::vector<std::string> CommandLine = {"clang", "-c", "test.cpp", + "-o" + "test.cpp.o"}; + StringRef CWD = "/root"; + + auto VFS = new llvm::vfs::InMemoryFileSystem(); + VFS->setCurrentWorkingDirectory(CWD); + auto Sept = llvm::sys::path::get_separator(); + std::string HeaderPath = + std::string(llvm::formatv("{0}root{0}header.h", Sept)); + std::string TestPath = std::string(llvm::formatv("{0}root{0}test.cpp", Sept)); + + VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("\n")); + VFS->addFile(TestPath, 0, + llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n")); + + DependencyScanningService Service(ScanningMode::DependencyDirectivesScan, + ScanningOutputFormat::Make); + DependencyScanningTool ScanTool(Service, VFS); + + std::string DepFile; + ASSERT_THAT_ERROR( + ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile), + llvm::Succeeded()); + using llvm::sys::path::convert_to_slash; + EXPECT_EQ(convert_to_slash(DepFile), + "test.cpp.o: /root/test.cpp /root/header.h\n"); +} |