summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp
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/IncludeExcludeTest.cpp
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/IncludeExcludeTest.cpp')
-rw-r--r--clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp63
1 files changed, 56 insertions, 7 deletions
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"));
+}
OpenPOWER on IntegriCloud