Move userdiff tests to be data driven

This moves the expected and actual test data along with the source
data for the userdiff tests into the tests/resources/userdiff test
repo and updates the test to use that.
This commit is contained in:
Russell Belfer 2014-01-24 15:45:49 -08:00
parent 3b19d2fdcb
commit 027b8edac7
22 changed files with 57 additions and 54 deletions

View File

@ -176,70 +176,73 @@ void test_diff_drivers__long_lines(void)
void test_diff_drivers__builtins(void)
{
git_index *idx;
git_diff *diff;
git_patch *patch;
git_buf actual = GIT_BUF_INIT;
git_buf file = GIT_BUF_INIT, actual = GIT_BUF_INIT, expected = GIT_BUF_INIT;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
const char *base =
"<html>\n<body>\n"
" <h1 id=\"first section\">\n <ol>\n <li>item 1.1</li>\n <li>item 1.2</li>\n <li>item 1.3</li>\n <li>item 1.4</li>\n <li>item 1.5</li>\n <li>item 1.6</li>\n <li>item 1.7</li>\n <li>item 1.8</li>\n <li>item 1.9</li>\n </ol>\n </h1>\n"
" <h1 id=\"second section\">\n <ol>\n <li>item 2.1</li>\n <li>item 2.2</li>\n <li>item 2.3</li>\n <li>item 2.4</li>\n <li>item 2.5</li>\n <li>item 2.6</li>\n <li>item 2.7</li>\n <li>item 2.8</li>\n </ol>\n </h1>\n"
" <h1 id=\"third section\">\n <ol>\n <li>item 3.1</li>\n <li>item 3.2</li>\n <li>item 3.3</li>\n <li>item 3.4</li>\n <li>item 3.5</li>\n <li>item 3.6</li>\n <li>item 3.7</li>\n <li>item 3.8</li>\n </ol>\n </h1>\n"
"</body></html>\n";
const char *modified =
"<html>\n<body>\n"
" <h1 id=\"first section\">\n <ol>\n <li>item 1.1</li>\n <li>item 1.2 changed</li>\n <li>item 1.3 changed</li>\n <li>item 1.4</li>\n <li>item 1.5</li>\n <li>item 1.6</li>\n <li>item 1.7</li>\n <li>item 1.8</li>\n <li>item 1.9</li>\n <li>item 1.10 added</li>\n </ol>\n </h1>\n"
" <h1 id=\"second section\">\n <ol>\n <li>item 2.1</li>\n <li>item 2.2</li>\n <li>item 2.3</li>\n <li>item 2.4</li>\n <li>item 2.5</li>\n <li>item 2.6</li>\n <li>item 2.7 changed</li>\n <li>item 2.7.1 added</li>\n <li>item 2.8</li>\n </ol>\n </h1>\n"
" <h1 id=\"third section\">\n <ol>\n <li>item 3.1</li>\n <li>item 3.2</li>\n <li>item 3.3</li>\n <li>item 3.4</li>\n <li>item 3.5</li>\n <li>item 3.6</li>\n </ol>\n </h1>\n"
"</body></html>\n";
const char *expected_nodriver =
"diff --git a/file.html b/file.html\nindex 97b34db..c7dbed3 100644\n--- a/file.html\n+++ b/file.html\n@@ -5,4 +5,4 @@\n <li>item 1.1</li>\n- <li>item 1.2</li>\n- <li>item 1.3</li>\n+ <li>item 1.2 changed</li>\n+ <li>item 1.3 changed</li>\n <li>item 1.4</li>\n@@ -13,2 +13,3 @@\n <li>item 1.9</li>\n+ <li>item 1.10 added</li>\n </ol>\n@@ -23,3 +24,4 @@\n <li>item 2.6</li>\n- <li>item 2.7</li>\n+ <li>item 2.7 changed</li>\n+ <li>item 2.7.1 added</li>\n <li>item 2.8</li>\n@@ -35,4 +37,2 @@\n <li>item 3.6</li>\n- <li>item 3.7</li>\n- <li>item 3.8</li>\n </ol>\n";
const char *expected_driver =
"diff --git a/file.html b/file.html\nindex 97b34db..c7dbed3 100644\n--- a/file.html\n+++ b/file.html\n@@ -5,4 +5,4 @@ <h1 id=\"first section\">\n <li>item 1.1</li>\n- <li>item 1.2</li>\n- <li>item 1.3</li>\n+ <li>item 1.2 changed</li>\n+ <li>item 1.3 changed</li>\n <li>item 1.4</li>\n@@ -13,2 +13,3 @@ <h1 id=\"first section\">\n <li>item 1.9</li>\n+ <li>item 1.10 added</li>\n </ol>\n@@ -23,3 +24,4 @@ <h1 id=\"second section\">\n <li>item 2.6</li>\n- <li>item 2.7</li>\n+ <li>item 2.7 changed</li>\n+ <li>item 2.7.1 added</li>\n <li>item 2.8</li>\n@@ -35,4 +37,2 @@ <h1 id=\"third section\">\n <li>item 3.6</li>\n- <li>item 3.7</li>\n- <li>item 3.8</li>\n </ol>\n";
int i;
static const char *files[] = {
"html",
NULL
};
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_mkfile("empty_standard_repo/file.html", base);
cl_git_pass(git_repository_index(&idx, g_repo));
cl_git_pass(git_index_add_bypath(idx, "file.html"));
cl_git_pass(git_index_write(idx));
git_index_free(idx);
cl_git_rewritefile("empty_standard_repo/file.html", modified);
/* do diff with no special driver */
g_repo = cl_git_sandbox_init("userdiff");
opts.interhunk_lines = 1;
opts.context_lines = 1;
opts.pathspec.count = 1;
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_sz(1, git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_to_buf(&actual, patch));
for (i = 0; files[i]; ++i) {
git_buf_sets(&file, "files/file.");
git_buf_puts(&file, files[i]);
opts.pathspec.strings = &file.ptr;
overwrite_filemode(expected_nodriver, &actual);
/* do diff with no special driver */
cl_assert_equal_s(expected_nodriver, actual.ptr);
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_sz(1, git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_to_buf(&actual, patch));
git_buf_sets(&expected, "userdiff/expected/nodriver/diff.");
git_buf_puts(&expected, files[i]);
cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
overwrite_filemode(expected.ptr, &actual);
cl_assert_equal_s(expected.ptr, actual.ptr);
git_buf_clear(&actual);
git_patch_free(patch);
git_diff_free(diff);
/* do diff with driver */
{
FILE *fp = fopen("userdiff/.gitattributes", "w");
fprintf(fp, "*.%s diff=%s\n", files[i], files[i]);
fclose(fp);
}
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_sz(1, git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_to_buf(&actual, patch));
git_buf_sets(&expected, "userdiff/expected/driver/diff.");
git_buf_puts(&expected, files[i]);
cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
overwrite_filemode(expected.ptr, &actual);
cl_assert_equal_s(expected.ptr, actual.ptr);
git_buf_clear(&actual);
git_patch_free(patch);
git_diff_free(diff);
}
git_buf_free(&file);
git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
/* do diff with HTML driver */
cl_git_mkfile("empty_standard_repo/.gitattributes", "*.html diff=html\n");
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
cl_assert_equal_sz(1, git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_to_buf(&actual, patch));
overwrite_filemode(expected_driver, &actual);
cl_assert_equal_s(expected_driver, actual.ptr);
git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
git_buf_free(&expected);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.