summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/testSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-01-24 14:52:25 (GMT)
committerBrad King <brad.king@kitware.com>2019-01-24 14:52:25 (GMT)
commitd67ce0a61e6a4c8b639cb19f575b4f0a5b2d033f (patch)
treebbc71ae1f140a3f99bd7398829c5d9ee3f1d410c /Source/kwsys/testSystemTools.cxx
parent1d02491950b0aa05d2053e7fa32b39dca31e537b (diff)
parentbee32e96b392ff4e0f2baf8fdc831a9e5240c7d9 (diff)
downloadCMake-d67ce0a61e6a4c8b639cb19f575b4f0a5b2d033f.zip
CMake-d67ce0a61e6a4c8b639cb19f575b4f0a5b2d033f.tar.gz
CMake-d67ce0a61e6a4c8b639cb19f575b4f0a5b2d033f.tar.bz2
Merge branch 'upstream-KWSys' into update-kwsys
* upstream-KWSys: KWSys 2019-01-24 (b9dd1636)
Diffstat (limited to 'Source/kwsys/testSystemTools.cxx')
-rw-r--r--Source/kwsys/testSystemTools.cxx46
1 files changed, 46 insertions, 0 deletions
diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
index 0477d59..9a40b53 100644
--- a/Source/kwsys/testSystemTools.cxx
+++ b/Source/kwsys/testSystemTools.cxx
@@ -984,6 +984,50 @@ static bool CheckGetLineFromStreamLongLine()
return true;
}
+static bool writeFile(const char* fileName, const char* data)
+{
+ kwsys::ofstream out(fileName, std::ios::binary);
+ out << data;
+ if (!out) {
+ std::cerr << "Failed to write file: " << fileName << std::endl;
+ return false;
+ }
+ return true;
+}
+
+static bool CheckTextFilesDiffer()
+{
+ struct
+ {
+ const char* a;
+ const char* b;
+ bool differ;
+ } test_cases[] = { { "one", "one", false },
+ { "one", "two", true },
+ { "", "", false },
+ { "\n", "\r\n", false },
+ { "one\n", "one\n", false },
+ { "one\r\n", "one\n", false },
+ { "one\n", "one", false },
+ { "one\ntwo", "one\ntwo", false },
+ { "one\ntwo", "one\r\ntwo", false } };
+ const int num_test_cases = sizeof(test_cases) / sizeof(test_cases[0]);
+ for (int i = 0; i < num_test_cases; ++i) {
+ if (!writeFile("file_a", test_cases[i].a) ||
+ !writeFile("file_b", test_cases[i].b)) {
+ return false;
+ }
+ if (kwsys::SystemTools::TextFilesDiffer("file_a", "file_b") !=
+ test_cases[i].differ) {
+ std::cerr << "Incorrect TextFilesDiffer result for test case " << i + 1
+ << "." << std::endl;
+ return false;
+ }
+ }
+
+ return true;
+}
+
int testSystemTools(int, char* [])
{
bool res = true;
@@ -1027,5 +1071,7 @@ int testSystemTools(int, char* [])
res &= CheckGetFilenameName();
+ res &= CheckTextFilesDiffer();
+
return res ? 0 : 1;
}