summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-02-23 13:56:14 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-02-23 13:56:14 +0000
commit589d6377251d39e5f4d866bcb495bf6e547b4372 (patch)
treeecfc6cb9f76c144d99f1389ca266ecff177af386 /unittests
parente4e42f7ff8c99fafeec556ee4b4d685b5896e9c8 (diff)
downloadllvm-589d6377251d39e5f4d866bcb495bf6e547b4372.tar.gz
llvm-589d6377251d39e5f4d866bcb495bf6e547b4372.tar.bz2
llvm-589d6377251d39e5f4d866bcb495bf6e547b4372.tar.xz
Simplify remove, create_directory and create_directories.
Before this patch they would take an boolean argument to say if the path already existed. This was redundant with the returned error_code which is able to represent that. This allowed for callers to incorrectly check only the existed flag instead of first checking the error code. Instead, pass in a boolean flag to say if the previous (non-)existence should be an error or not. Callers of the of the old simple versions are not affected. They still ignore the previous (non-)existence as they did before. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201979 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Support/Path.cpp41
-rw-r--r--unittests/Transforms/DebugIR/DebugIR.cpp7
2 files changed, 28 insertions, 20 deletions
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp
index 197e1c2f86..2d8141f737 100644
--- a/unittests/Support/Path.cpp
+++ b/unittests/Support/Path.cpp
@@ -318,8 +318,10 @@ TEST_F(FileSystemTest, TempFiles) {
::close(FD2);
// Remove Temp2.
- ASSERT_NO_ERROR(fs::remove(Twine(TempPath2), TempFileExists));
- EXPECT_TRUE(TempFileExists);
+ ASSERT_NO_ERROR(fs::remove(Twine(TempPath2)));
+ ASSERT_NO_ERROR(fs::remove(Twine(TempPath2)));
+ ASSERT_EQ(fs::remove(Twine(TempPath2), false),
+ errc::no_such_file_or_directory);
error_code EC = fs::status(TempPath2.c_str(), B);
EXPECT_EQ(EC, errc::no_such_file_or_directory);
@@ -344,12 +346,10 @@ TEST_F(FileSystemTest, TempFiles) {
// Remove Temp1.
::close(FileDescriptor);
- ASSERT_NO_ERROR(fs::remove(Twine(TempPath), TempFileExists));
- EXPECT_TRUE(TempFileExists);
+ ASSERT_NO_ERROR(fs::remove(Twine(TempPath)));
// Remove the hard link.
- ASSERT_NO_ERROR(fs::remove(Twine(TempPath2), TempFileExists));
- EXPECT_TRUE(TempFileExists);
+ ASSERT_NO_ERROR(fs::remove(Twine(TempPath2)));
// Make sure Temp1 doesn't exist.
ASSERT_NO_ERROR(fs::exists(Twine(TempPath), TempFileExists));
@@ -368,23 +368,30 @@ TEST_F(FileSystemTest, TempFiles) {
#endif
}
+TEST_F(FileSystemTest, CreateDir) {
+ ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo"));
+ ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory) + "foo"));
+ ASSERT_EQ(fs::create_directory(Twine(TestDirectory) + "foo", false),
+ errc::file_exists);
+ ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "foo"));
+}
+
TEST_F(FileSystemTest, DirectoryIteration) {
error_code ec;
for (fs::directory_iterator i(".", ec), e; i != e; i.increment(ec))
ASSERT_NO_ERROR(ec);
// Create a known hierarchy to recurse over.
- bool existed;
- ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
- + "/recursive/a0/aa1", existed));
- ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
- + "/recursive/a0/ab1", existed));
- ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
- + "/recursive/dontlookhere/da1", existed));
- ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
- + "/recursive/z0/za1", existed));
- ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory)
- + "/recursive/pop/p1", existed));
+ ASSERT_NO_ERROR(
+ fs::create_directories(Twine(TestDirectory) + "/recursive/a0/aa1"));
+ ASSERT_NO_ERROR(
+ fs::create_directories(Twine(TestDirectory) + "/recursive/a0/ab1"));
+ ASSERT_NO_ERROR(fs::create_directories(Twine(TestDirectory) +
+ "/recursive/dontlookhere/da1"));
+ ASSERT_NO_ERROR(
+ fs::create_directories(Twine(TestDirectory) + "/recursive/z0/za1"));
+ ASSERT_NO_ERROR(
+ fs::create_directories(Twine(TestDirectory) + "/recursive/pop/p1"));
typedef std::vector<std::string> v_t;
v_t visited;
for (fs::recursive_directory_iterator i(Twine(TestDirectory)
diff --git a/unittests/Transforms/DebugIR/DebugIR.cpp b/unittests/Transforms/DebugIR/DebugIR.cpp
index a0916a21d2..affdd762ba 100644
--- a/unittests/Transforms/DebugIR/DebugIR.cpp
+++ b/unittests/Transforms/DebugIR/DebugIR.cpp
@@ -55,9 +55,10 @@ void insertCUDescriptor(Module *M, StringRef File, StringRef Dir,
/// Attempts to remove file at Path and returns true if it existed, or false if
/// it did not.
bool removeIfExists(StringRef Path) {
- bool existed = false;
- sys::fs::remove(Path, existed);
- return existed;
+ // This is an approximation, on error we don't know in general if the file
+ // existed or not.
+ llvm::error_code EC = sys::fs::remove(Path, false);
+ return EC != llvm::errc::no_such_file_or_directory;
}
char * current_dir() {