From 402b92cfe98882693a062bd94305383c55777619 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 14 Nov 2012 22:44:17 -0800 Subject: [PATCH] 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. --- tests-clar/reset/hard.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests-clar/reset/hard.c b/tests-clar/reset/hard.c index 4b49ca362..bddbd17d7 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)); }