From b6d9c0001aaa1abb8978f7aa06665d54ee732619 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 26 Jun 2013 16:20:55 +0000 Subject: [PATCH] Don't use PathV1.h in IncludeExcludeTest.cpp. llvm-svn: 184959 --- .../cpp11-migrate/IncludeExcludeTest.cpp | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp index 19f9dbf2c299..06d585a187eb 100644 --- a/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp +++ b/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp @@ -1,9 +1,21 @@ #include "Core/IncludeExcludeInfo.h" #include "gtest/gtest.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/PathV1.h" #include +// FIXME: copied from unittests/Support/Path.cpp +#define ASSERT_NO_ERROR(x) \ + if (llvm::error_code ASSERT_NO_ERROR_ec = x) { \ + llvm::SmallString<128> MessageStorage; \ + llvm::raw_svector_ostream Message(MessageStorage); \ + Message << #x ": did not return errc::success.\n" \ + << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ + << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ + GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ + } else { \ + } + TEST(IncludeExcludeTest, ParseString) { IncludeExcludeInfo IEManager; llvm::error_code Err = IEManager.readListFromString( @@ -38,29 +50,35 @@ struct InputFiles { // This function uses fatal assertions. The caller is responsible for making // sure fatal assertions propagate. void CreateFiles(bool UnixMode) { - IncludeDataPath = llvm::sys::Path::GetTemporaryDirectory(); - ExcludeDataPath = IncludeDataPath; + llvm::SmallString<128> Path; + int FD; - ASSERT_FALSE(IncludeDataPath.createTemporaryFileOnDisk()); - std::ofstream IncludeDataFile(IncludeDataPath.c_str()); - ASSERT_TRUE(IncludeDataFile.good()); - for (unsigned i = 0; i < sizeof(IncludeData)/sizeof(char*); ++i) { - IncludeDataFile << IncludeData[i] << (UnixMode ? "\n" : "\r\n"); + ASSERT_NO_ERROR( + llvm::sys::fs::unique_file("include-%%%%%%", FD, Path)); + IncludeDataPath = Path.str(); + { + llvm::raw_fd_ostream IncludeDataFile(FD, true); + for (unsigned i = 0; i < sizeof(IncludeData) / sizeof(char *); ++i) { + IncludeDataFile << IncludeData[i] << (UnixMode ? "\n" : "\r\n"); + } } - ASSERT_FALSE(ExcludeDataPath.createTemporaryFileOnDisk()); - std::ofstream ExcludeDataFile(ExcludeDataPath.c_str()); - ASSERT_TRUE(ExcludeDataFile.good()); - for (unsigned i = 0; i < sizeof(ExcludeData)/sizeof(char*); ++i) { - ExcludeDataFile << ExcludeData[i] << (UnixMode ? "\n" : "\r\n");; + ASSERT_NO_ERROR( + llvm::sys::fs::unique_file("exclude-%%%%%%", FD, Path)); + ExcludeDataPath = Path.str(); + { + llvm::raw_fd_ostream ExcludeDataFile(FD, true); + for (unsigned i = 0; i < sizeof(ExcludeData) / sizeof(char *); ++i) { + ExcludeDataFile << ExcludeData[i] << (UnixMode ? "\n" : "\r\n"); + } } } static const char *IncludeData[3]; static const char *ExcludeData[4]; - llvm::sys::Path IncludeDataPath; - llvm::sys::Path ExcludeDataPath; + std::string IncludeDataPath; + std::string ExcludeDataPath; }; const char *InputFiles::IncludeData[3] = { "a", "b/b2", "c/c2" };