summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/cpp11-migrate/IncludeExcludeTest.cpp
diff options
context:
space:
mode:
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