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.
This commit is contained in:
Russell Belfer 2012-11-14 22:44:17 -08:00
parent cccacac555
commit 402b92cfe9

View File

@ -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));
}