[clang-tools-extra] r181029 - Generate input files from within unit test

Vane, Edwin edwin.vane at intel.com
Fri May 3 12:25:45 PDT 2013


Nope. I was just following an example of using createTemporaryFileOnDisk() from lib/Archive/ArchiveWriter.cpp which happened to use std::ofstream.

> -----Original Message-----
> From: Manuel Klimek [mailto:klimek at google.com]
> Sent: Friday, May 03, 2013 3:14 PM
> To: Vane, Edwin
> Cc: cfe-commits at cs.uiuc.edu
> Subject: Re: [clang-tools-extra] r181029 - Generate input files from within unit
> test
> 
> Thanks!
> Any reason you used fstream instead of llvm's file streams?
> 
> Cheers,
> /Manuel
> 
> 
> On Fri, May 3, 2013 at 6:30 PM, Edwin Vane <edwin.vane at intel.com> wrote:
> 
> 
> 	Author: revane
> 	Date: Fri May  3 11:30:55 2013
> 	New Revision: 181029
> 
> 	URL: http://llvm.org/viewvc/llvm-project?rev=181029&view=rev
> 	Log:
> 	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.
> 
> 
> 	Removed:
> 	    clang-tools-extra/trunk/unittests/cpp11-migrate/Data/
> 	    clang-tools-extra/trunk/unittests/cpp11-migrate/lit.local.cfg
> 	Modified:
> 	    clang-tools-extra/trunk/unittests/cpp11-migrate/CMakeLists.txt
> 	    clang-tools-extra/trunk/unittests/cpp11-
> migrate/IncludeExcludeTest.cpp
> 	    clang-tools-extra/trunk/unittests/cpp11-migrate/Makefile
> 
> 	Modified: clang-tools-extra/trunk/unittests/cpp11-
> migrate/CMakeLists.txt
> 	URL: http://llvm.org/viewvc/llvm-project/clang-tools-
> extra/trunk/unittests/cpp11-
> migrate/CMakeLists.txt?rev=181029&r1=181028&r2=181029&view=diff
> 	==========================================================
> ====================
> 	--- clang-tools-extra/trunk/unittests/cpp11-migrate/CMakeLists.txt
> (original)
> 	+++ clang-tools-extra/trunk/unittests/cpp11-migrate/CMakeLists.txt Fri
> May  3 11:30:55 2013
> 	@@ -16,6 +16,3 @@ target_link_libraries(Cpp11MigrateTests
> 	   clangBasic
> 	   clangASTMatchers
> 	   )
> 	-
> 	-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lit.local.cfg
> 	-  ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
> 
> 	Modified: clang-tools-extra/trunk/unittests/cpp11-
> migrate/IncludeExcludeTest.cpp
> 	URL: http://llvm.org/viewvc/llvm-project/clang-tools-
> extra/trunk/unittests/cpp11-
> migrate/IncludeExcludeTest.cpp?rev=181029&r1=181028&r2=181029&view=dif
> f
> 	==========================================================
> ====================
> 	--- clang-tools-extra/trunk/unittests/cpp11-
> migrate/IncludeExcludeTest.cpp (original)
> 	+++ clang-tools-extra/trunk/unittests/cpp11-
> migrate/IncludeExcludeTest.cpp Fri May  3 11:30:55 2013
> 	@@ -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());
> 
> 
> 	Modified: clang-tools-extra/trunk/unittests/cpp11-migrate/Makefile
> 	URL: http://llvm.org/viewvc/llvm-project/clang-tools-
> extra/trunk/unittests/cpp11-
> migrate/Makefile?rev=181029&r1=181028&r2=181029&view=diff
> 	==========================================================
> ====================
> 	--- clang-tools-extra/trunk/unittests/cpp11-migrate/Makefile (original)
> 	+++ clang-tools-extra/trunk/unittests/cpp11-migrate/Makefile Fri May
> 3 11:30:55 2013
> 	@@ -22,8 +22,3 @@ include $(CLANG_LEVEL)/Makefile
> 	 MAKEFILE_UNITTEST_NO_INCLUDE_COMMON := 1
> 	 CPP.Flags += -I$(PROJ_SRC_DIR)/../../cpp11-migrate
> 	 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
> 	-
> 	-$(PROJ_OBJ_DIR)/lit.local.cfg: $(PROJ_SRC_DIR)/lit.local.cfg
> 	-       @cp $< $@
> 	-
> 	-all:: $(PROJ_OBJ_DIR)/lit.local.cfg
> 
> 	Removed: clang-tools-extra/trunk/unittests/cpp11-migrate/lit.local.cfg
> 	URL: http://llvm.org/viewvc/llvm-project/clang-tools-
> extra/trunk/unittests/cpp11-migrate/lit.local.cfg?rev=181028&view=auto
> 	==========================================================
> ====================
> 	--- clang-tools-extra/trunk/unittests/cpp11-migrate/lit.local.cfg
> (original)
> 	+++ clang-tools-extra/trunk/unittests/cpp11-migrate/lit.local.cfg
> (removed)
> 	@@ -1,4 +0,0 @@
> 	-# Some tests require access to data files which are stored in the 'Data'
> 	-# subdirectory. This environment variable indicates where to find those
> files.
> 	-config.environment['DATADIR'] =
> os.path.normpath(os.path.join(config.extra_tools_src_dir,
> 	-                                                              'cpp11-migrate', 'Data'))
> 
> 
> 	_______________________________________________
> 	cfe-commits mailing list
> 	cfe-commits at cs.uiuc.edu
> 	http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 
> 





More information about the cfe-commits mailing list