Commit 402b92cfe98882693a062bd94305383c55777619

Russell Belfer 2012-11-14T22:44:17

Fix reset hard tests on platforms with CRLF The reset hard tests had hardcoded expected file content and was not correctly compensating for CRLF filtering when a file needed to be reverted by the reset hard. This fixes that.

diff --git a/tests-clar/reset/hard.c b/tests-clar/reset/hard.c
index 4b49ca3..bddbd17 100644
--- a/tests-clar/reset/hard.c
+++ b/tests-clar/reset/hard.c
@@ -19,6 +19,21 @@ void test_reset_hard__cleanup(void)
 	cl_git_sandbox_cleanup();
 }
 
+static int strequal_ignore_eol(const char *exp, const char *str)
+{
+	while (*exp && *str) {
+		if (*exp != *str) {
+			while (*exp == '\r' || *exp == '\n') ++exp;
+			while (*str == '\r' || *str == '\n') ++str;
+			if (*exp != *str)
+				return false;
+		} else {
+			exp++; str++;
+		}
+	}
+	return (!*exp && !*str);
+}
+
 void test_reset_hard__resetting_reverts_modified_files(void)
 {
 	git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
@@ -61,7 +76,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
 		cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
 		if (after[i]) {
 			cl_git_pass(git_futils_readbuffer(&content, path.ptr));
-			cl_assert_equal_s(after[i], content.ptr);
+			cl_assert(strequal_ignore_eol(after[i], content.ptr));
 		} else {
 			cl_assert(!git_path_exists(path.ptr));
 		}