diff options
| author | Edwin Vane <edwin.vane@intel.com> | 2013-05-03 16:30:55 +0000 |
|---|---|---|
| committer | Edwin Vane <edwin.vane@intel.com> | 2013-05-03 16:30:55 +0000 |
| commit | 9924de1b288d82c78b84892973c6904c6b692ecf (patch) | |
| tree | 6647c627ad6fa782ae358f05139db5cf31af5f7d /clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp | |
| parent | 6991afe31b96efb507cfd376cb83f665404dea66 (diff) | |
| download | bcm5719-llvm-9924de1b288d82c78b84892973c6904c6b692ecf.tar.gz bcm5719-llvm-9924de1b288d82c78b84892973c6904c6b692ecf.zip | |
Generate input files from within unit test
It is preferable for a unit test to be responsible for creating its own input
data instead of relying on checked-in data files. Now the IncludeExcludeTest
for cpp11-migrate does this.
- Removed old data files.
- Updated build system and lit files to remove references to old data files.
llvm-svn: 181029
Diffstat (limited to 'clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp')
| -rw-r--r-- | clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp index 4be92f790b2..aba81213ac3 100644 --- a/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp +++ b/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp @@ -1,6 +1,7 @@ #include "Core/IncludeExcludeInfo.h" #include "gtest/gtest.h" #include "llvm/Support/Path.h" +#include <fstream> TEST(IncludeExcludeTest, ParseString) { IncludeExcludeInfo IEManager; @@ -29,30 +30,49 @@ TEST(IncludeExcludeTest, ParseString) { EXPECT_FALSE(IEManager.isFileIncluded("c/c2/c3/f.cpp")); } -// The IncludeExcludeTest suite requires data files. The location of these -// files must be provided in the 'DATADIR' environment variable. -class IncludeExcludeFileTest : public ::testing::Test { -public: - virtual void SetUp() { - DataDir = getenv("DATADIR"); - if (DataDir == 0) { - FAIL() - << "IncludeExcludeFileTest requires the DATADIR environment variable " - "to be set."; +// Utility for creating and filling files with data for IncludeExcludeFileTest +// tests. +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; + + 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_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");; } } - const char *DataDir; + static const char *IncludeData[3]; + static const char *ExcludeData[4]; + + llvm::sys::Path IncludeDataPath; + llvm::sys::Path ExcludeDataPath; }; -TEST_F(IncludeExcludeFileTest, UNIXFile) { - llvm::SmallString<128> IncludeData(DataDir); - llvm::SmallString<128> ExcludeData(IncludeData); - llvm::sys::path::append(IncludeData, "IncludeData.in"); - llvm::sys::path::append(ExcludeData, "ExcludeData.in"); +const char *InputFiles::IncludeData[3] = { "a", "b/b2", "c/c2" }; +const char *InputFiles::ExcludeData[4] = { "a/af.cpp", "a/a2", "b/b2/b2f.cpp", + "c/c2" }; + +TEST(IncludeExcludeFileTest, UNIXFile) { + InputFiles UnixFiles; + ASSERT_NO_FATAL_FAILURE(UnixFiles.CreateFiles(/* UnixMode= */true)); IncludeExcludeInfo IEManager; - llvm::error_code Err = IEManager.readListFromFile(IncludeData, ExcludeData); + llvm::error_code Err = IEManager.readListFromFile( + UnixFiles.IncludeDataPath.c_str(), UnixFiles.ExcludeDataPath.c_str()); ASSERT_EQ(Err, llvm::error_code::success()); @@ -61,14 +81,13 @@ TEST_F(IncludeExcludeFileTest, UNIXFile) { EXPECT_FALSE(IEManager.isFileIncluded("a/af.cpp")); } -TEST_F(IncludeExcludeFileTest, DOSFile) { - llvm::SmallString<128> IncludeData(DataDir); - llvm::SmallString<128> ExcludeData(IncludeData); - llvm::sys::path::append(IncludeData, "IncludeDataCRLF.in"); - llvm::sys::path::append(ExcludeData, "ExcludeDataCRLF.in"); +TEST(IncludeExcludeFileTest, DOSFile) { + InputFiles DOSFiles; + ASSERT_NO_FATAL_FAILURE(DOSFiles.CreateFiles(/* UnixMode= */false)); IncludeExcludeInfo IEManager; - llvm::error_code Err = IEManager.readListFromFile(IncludeData, ExcludeData); + llvm::error_code Err = IEManager.readListFromFile( + DOSFiles.IncludeDataPath.c_str(), DOSFiles.ExcludeDataPath.c_str()); ASSERT_EQ(Err, llvm::error_code::success()); |

