diff options
| author | Alex Lorenz <arphaman@gmail.com> | 2019-07-25 21:47:11 +0000 |
|---|---|---|
| committer | Alex Lorenz <arphaman@gmail.com> | 2019-07-25 21:47:11 +0000 |
| commit | b680422ef809942767cb0bfec4f00af197c3d2c4 (patch) | |
| tree | c15e73df95b01fa4e50f2e928b665edb59dd7d89 /llvm/unittests | |
| parent | e54dc6b8b58d7b94c2737adb941c25fea54b6a70 (diff) | |
| download | bcm5719-llvm-b680422ef809942767cb0bfec4f00af197c3d2c4.tar.gz bcm5719-llvm-b680422ef809942767cb0bfec4f00af197c3d2c4.zip | |
[FileCollector] add support for recording empty directories
The file collector class is useful for constructing reproducers by
creating a snapshot of the files that are accessed. Sometimes it might
also be important to construct directories that don't necessarily have files,
but are still accessed by some tool that we want to make a reproducer for.
This is useful for instance for modeling the behavior of Clang's header search,
which scans through a number of directories it doesn't actually access when
looking for framework headers. This commit extends the file collector to allow
it to work with paths that are just directories, by constructing them as the
files are copied over.
Differential Revision: https://reviews.llvm.org/D65297
llvm-svn: 367061
Diffstat (limited to 'llvm/unittests')
| -rw-r--r-- | llvm/unittests/Support/FileCollectorTest.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/unittests/Support/FileCollectorTest.cpp b/llvm/unittests/Support/FileCollectorTest.cpp index 38d8ff9dad8..07e745ce8f2 100644 --- a/llvm/unittests/Support/FileCollectorTest.cpp +++ b/llvm/unittests/Support/FileCollectorTest.cpp @@ -148,6 +148,37 @@ TEST(FileCollectorTest, copyFiles) { EXPECT_FALSE(ec); } +TEST(FileCollectorTest, recordAndConstructDirectory) { + ScopedDir file_root("dir_root", true); + ScopedDir subdir(file_root + "/subdir"); + ScopedDir subdir2(file_root + "/subdir2"); + ScopedFile a(subdir2 + "/a"); + + // Create file collector and add files. + ScopedDir root("copy_files_root", true); + std::string root_fs = root.Path.str(); + TestingFileCollector FileCollector(root_fs, root_fs); + FileCollector.addFile(a.Path); + + // The empty directory isn't seen until we add it. + EXPECT_TRUE(FileCollector.hasSeen(a.Path)); + EXPECT_FALSE(FileCollector.hasSeen(subdir.Path)); + + FileCollector.addFile(subdir.Path); + EXPECT_TRUE(FileCollector.hasSeen(subdir.Path)); + + // Make sure we can construct the directory. + std::error_code ec = FileCollector.copyFiles(true); + EXPECT_FALSE(ec); + bool IsDirectory = false; + llvm::SmallString<128> SubdirInRoot = root.Path; + llvm::sys::path::append(SubdirInRoot, + llvm::sys::path::relative_path(subdir.Path)); + ec = sys::fs::is_directory(SubdirInRoot, IsDirectory); + EXPECT_FALSE(ec); + ASSERT_TRUE(IsDirectory); +} + #ifndef _WIN32 TEST(FileCollectorTest, Symlinks) { // Root where the original files live. |

