summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/cpp11-migrate
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-05-02 19:02:02 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-05-02 19:02:02 +0000
commitc049c929333be7c0b48fe89bfc786e8950d496e9 (patch)
treeb9553d75354bd5a5725d72c1f28773300cd9d60e /clang-tools-extra/unittests/cpp11-migrate
parenta9a50ffb02f13aa0516761d157a9e1fae38fa971 (diff)
downloadbcm5719-llvm-c049c929333be7c0b48fe89bfc786e8950d496e9.tar.gz
bcm5719-llvm-c049c929333be7c0b48fe89bfc786e8950d496e9.zip
Add support to read include/exclude paths from file
Files containing the list of paths to be included and excluded can now be specified through -include-from=<filename> and -exclude-from=<filename> command line options in cpp11-migrate. Added support for data files for cpp11-migrate unittests. The Cpp11MigrateTests executable just requires a DATADIR environment variable to be set which specifies the directory where data files are stored. This is handled automatically when using LIT. Author: Jack Yang <jack.yang@intel.com>, Edwin Vane <edwin.vane@intel.com> llvm-svn: 180939
Diffstat (limited to 'clang-tools-extra/unittests/cpp11-migrate')
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt2
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/Data/ExcludeData.in4
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/Data/ExcludeDataCRLF.in4
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/Data/IncludeData.in3
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/Data/IncludeDataCRLF.in3
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp63
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/Makefile5
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/lit.local.cfg4
8 files changed, 81 insertions, 7 deletions
diff --git a/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt b/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt
index 77b81585d65..e6698403c17 100644
--- a/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt
+++ b/clang-tools-extra/unittests/cpp11-migrate/CMakeLists.txt
@@ -17,3 +17,5 @@ target_link_libraries(Cpp11MigrateTests
clangASTMatchers
)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/lit.local.cfg
+ ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
diff --git a/clang-tools-extra/unittests/cpp11-migrate/Data/ExcludeData.in b/clang-tools-extra/unittests/cpp11-migrate/Data/ExcludeData.in
new file mode 100644
index 00000000000..c2bce59fd89
--- /dev/null
+++ b/clang-tools-extra/unittests/cpp11-migrate/Data/ExcludeData.in
@@ -0,0 +1,4 @@
+a/af.cpp
+a/a2
+b/b2/b2f.cpp
+c/c2
diff --git a/clang-tools-extra/unittests/cpp11-migrate/Data/ExcludeDataCRLF.in b/clang-tools-extra/unittests/cpp11-migrate/Data/ExcludeDataCRLF.in
new file mode 100644
index 00000000000..1c8bca2cf66
--- /dev/null
+++ b/clang-tools-extra/unittests/cpp11-migrate/Data/ExcludeDataCRLF.in
@@ -0,0 +1,4 @@
+a/af.cpp
+a/a2
+b/b2/b2f.cpp
+c/c2
diff --git a/clang-tools-extra/unittests/cpp11-migrate/Data/IncludeData.in b/clang-tools-extra/unittests/cpp11-migrate/Data/IncludeData.in
new file mode 100644
index 00000000000..7753bac7ebd
--- /dev/null
+++ b/clang-tools-extra/unittests/cpp11-migrate/Data/IncludeData.in
@@ -0,0 +1,3 @@
+a
+b/b2
+c/c2
diff --git a/clang-tools-extra/unittests/cpp11-migrate/Data/IncludeDataCRLF.in b/clang-tools-extra/unittests/cpp11-migrate/Data/IncludeDataCRLF.in
new file mode 100644
index 00000000000..9f004ef6876
--- /dev/null
+++ b/clang-tools-extra/unittests/cpp11-migrate/Data/IncludeDataCRLF.in
@@ -0,0 +1,3 @@
+a
+b/b2
+c/c2
diff --git a/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp b/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp
index a4b270b2ce2..4be92f790b2 100644
--- a/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp
+++ b/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp
@@ -1,24 +1,25 @@
#include "Core/IncludeExcludeInfo.h"
#include "gtest/gtest.h"
+#include "llvm/Support/Path.h"
-IncludeExcludeInfo IEManager(/*include=*/ "a,b/b2,c/c2/c3",
- /*exclude=*/ "a/af.cpp,a/a2,b/b2/b2f.cpp,c/c2/c3");
+TEST(IncludeExcludeTest, ParseString) {
+ IncludeExcludeInfo IEManager;
+ llvm::error_code Err = IEManager.readListFromString(
+ /*include=*/ "a,b/b2,c/c2",
+ /*exclude=*/ "a/af.cpp,a/a2,b/b2/b2f.cpp,c/c2");
+
+ ASSERT_EQ(Err, llvm::error_code::success());
-TEST(IncludeExcludeTest, NoMatchOnIncludeList) {
// If the file does not appear on the include list then it is not safe to
// transform. Files are not safe to transform by default.
EXPECT_FALSE(IEManager.isFileIncluded("f.cpp"));
EXPECT_FALSE(IEManager.isFileIncluded("b/dir/f.cpp"));
-}
-TEST(IncludeExcludeTest, MatchOnIncludeList) {
// If the file appears on only the include list then it is safe to transform.
EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));
EXPECT_TRUE(IEManager.isFileIncluded("a/dir/f.cpp"));
EXPECT_TRUE(IEManager.isFileIncluded("b/b2/f.cpp"));
-}
-TEST(IncludeExcludeTest, MatchOnBothLists) {
// If the file appears on both the include or exclude list then it is not
// safe to transform.
EXPECT_FALSE(IEManager.isFileIncluded("a/af.cpp"));
@@ -27,3 +28,51 @@ TEST(IncludeExcludeTest, MatchOnBothLists) {
EXPECT_FALSE(IEManager.isFileIncluded("b/b2/b2f.cpp"));
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.";
+ }
+ }
+
+ const char *DataDir;
+};
+
+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");
+
+ IncludeExcludeInfo IEManager;
+ llvm::error_code Err = IEManager.readListFromFile(IncludeData, ExcludeData);
+
+ ASSERT_EQ(Err, llvm::error_code::success());
+
+ EXPECT_FALSE(IEManager.isFileIncluded("f.cpp"));
+ EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));
+ 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");
+
+ IncludeExcludeInfo IEManager;
+ llvm::error_code Err = IEManager.readListFromFile(IncludeData, ExcludeData);
+
+ ASSERT_EQ(Err, llvm::error_code::success());
+
+ EXPECT_FALSE(IEManager.isFileIncluded("f.cpp"));
+ EXPECT_TRUE(IEManager.isFileIncluded("a/f.cpp"));
+ EXPECT_FALSE(IEManager.isFileIncluded("a/af.cpp"));
+}
diff --git a/clang-tools-extra/unittests/cpp11-migrate/Makefile b/clang-tools-extra/unittests/cpp11-migrate/Makefile
index 4779c49cf34..1ea8b9351c0 100644
--- a/clang-tools-extra/unittests/cpp11-migrate/Makefile
+++ b/clang-tools-extra/unittests/cpp11-migrate/Makefile
@@ -22,3 +22,8 @@ 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
diff --git a/clang-tools-extra/unittests/cpp11-migrate/lit.local.cfg b/clang-tools-extra/unittests/cpp11-migrate/lit.local.cfg
new file mode 100644
index 00000000000..ffb4ec22f3f
--- /dev/null
+++ b/clang-tools-extra/unittests/cpp11-migrate/lit.local.cfg
@@ -0,0 +1,4 @@
+# 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'))
OpenPOWER on IntegriCloud