Support/FileSystem: Add unique_file and exists implementations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120776 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer
2010-12-03 01:21:28 +00:00
parent f4e7b167a0
commit 3cb84ef65d
5 changed files with 361 additions and 9 deletions

View File

@@ -7,11 +7,13 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/PathV2.h"
#include "gtest/gtest.h"
using namespace llvm;
using namespace llvm::sys;
#define TEST_OUT(func, result) outs() << " " #func ": " << result << '\n';
@@ -131,6 +133,22 @@ TEST(Support, Path) {
outs().flush();
}
int FileDescriptor;
SmallString<64> TempPath;
if (error_code ec = sys::fs::unique_file("%%-%%-%%-%%.temp",
FileDescriptor, TempPath))
ASSERT_FALSE(ec.message().c_str());
bool TempFileExists;
ASSERT_FALSE(sys::fs::exists(Twine(TempPath), TempFileExists));
EXPECT_TRUE(TempFileExists);
::close(FileDescriptor);
::remove(TempPath.begin());
ASSERT_FALSE(fs::exists(Twine(TempPath), TempFileExists));
EXPECT_FALSE(TempFileExists);
}
} // anonymous namespace