Skip to content

Commit 59b054c

Browse files
committed
index::crlf: better error reporting in core git tests
Don't simply fail when the expected output does not match the data in the index; instead, provide a detailed output about the system, file, and settings that caused the failure so that developers can better isolate the problem(s).
1 parent 021a08b commit 59b054c

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

tests/index/crlf.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void test_index_crlf__cleanup(void)
3535

3636
struct compare_data
3737
{
38+
const char *systype;
3839
const char *dirname;
3940
const char *safecrlf;
4041
const char *autocrlf;
@@ -50,11 +51,14 @@ static int add_and_check_file(void *payload, git_buf *actual_path)
5051
char *basename;
5152
const git_index_entry *entry;
5253
git_blob *blob;
54+
bool failed = true;
5355

5456
basename = git_path_basename(actual_path->ptr);
5557

56-
if (!strcmp(basename, ".git") || !strcmp(basename, ".gitattributes"))
57-
return 0;
58+
if (!strcmp(basename, ".git") || !strcmp(basename, ".gitattributes")) {
59+
failed = false;
60+
goto done;
61+
}
5862

5963
cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, basename));
6064

@@ -68,16 +72,19 @@ static int add_and_check_file(void *payload, git_buf *actual_path)
6872
cl_git_pass(git_blob_lookup(&blob, g_repo, &entry->id));
6973

7074
cl_git_pass(git_futils_readbuffer(&expected_contents, expected_path.ptr));
71-
cl_assert_equal_s(expected_contents, git_blob_rawcontent(blob));
75+
76+
if (strcmp(expected_contents.ptr, git_blob_rawcontent(blob)) != 0)
77+
goto done;
7278

7379
git_blob_free(blob);
7480
} else if (git_path_isfile(expected_path_fail.ptr)) {
7581
cl_git_pass(git_futils_readbuffer(&expected_contents, expected_path_fail.ptr));
7682
git_buf_rtrim(&expected_contents);
7783

78-
cl_git_fail(git_index_add_bypath(g_index, basename));
79-
cl_assert_equal_i(GITERR_FILTER, giterr_last()->klass);
80-
cl_assert_equal_s(expected_contents.ptr, giterr_last()->message);
84+
if (git_index_add_bypath(g_index, basename) == 0 ||
85+
giterr_last()->klass != GITERR_FILTER ||
86+
strcmp(expected_contents.ptr, giterr_last()->message) != 0)
87+
goto done;
8188
} else {
8289
cl_fail("unexpected index failure");
8390
}
@@ -101,13 +108,21 @@ static int add_and_check_file(void *payload, git_buf *actual_path)
101108
return 0;
102109
}
103110

111+
static const char *system_type(void)
112+
{
113+
if (GIT_EOL_NATIVE == GIT_EOL_CRLF)
114+
return "windows";
115+
else
116+
return "posix";
117+
}
118+
104119
static void test_add_index(const char *safecrlf, const char *autocrlf, const char *attrs)
105120
{
106121
git_buf attrbuf = GIT_BUF_INIT;
107122
git_buf expected_dirname = GIT_BUF_INIT;
108123
git_buf sandboxname = GIT_BUF_INIT;
109124
git_buf reponame = GIT_BUF_INIT;
110-
struct compare_data compare_data = { NULL, safecrlf, autocrlf, attrs };
125+
struct compare_data compare_data = { system_type(), NULL, safecrlf, autocrlf, attrs };
111126
const char *c;
112127

113128
git_buf_puts(&reponame, "crlf");
@@ -139,7 +154,9 @@ static void test_add_index(const char *safecrlf, const char *autocrlf, const cha
139154

140155
cl_git_pass(git_index_clear(g_index));
141156

142-
git_buf_joinpath(&expected_dirname, "crlf_data", "posix_to_odb");
157+
git_buf_joinpath(&expected_dirname, "crlf_data", system_type());
158+
git_buf_puts(&expected_dirname, "_to_odb");
159+
143160
git_buf_joinpath(&expected_fixture, expected_dirname.ptr, sandboxname.ptr);
144161
cl_fixture_sandbox(expected_fixture.ptr);
145162

0 commit comments

Comments
 (0)