Commit 027b8eda by Russell Belfer

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.
parent 3b19d2fd
......@@ -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");
g_repo = cl_git_sandbox_init("userdiff");
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);
opts.interhunk_lines = 1;
opts.context_lines = 1;
opts.pathspec.count = 1;
cl_git_rewritefile("empty_standard_repo/file.html", modified);
for (i = 0; files[i]; ++i) {
git_buf_sets(&file, "files/file.");
git_buf_puts(&file, files[i]);
opts.pathspec.strings = &file.ptr;
/* do diff with no special driver */
/* do diff with no special driver */
opts.interhunk_lines = 1;
opts.context_lines = 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));
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_nodriver, &actual);
overwrite_filemode(expected.ptr, &actual);
cl_assert_equal_s(expected_nodriver, actual.ptr);
cl_assert_equal_s(expected.ptr, actual.ptr);
git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
git_buf_clear(&actual);
git_patch_free(patch);
git_diff_free(diff);
/* do diff with HTML driver */
/* do diff with driver */
cl_git_mkfile("empty_standard_repo/.gitattributes", "*.html diff=html\n");
{
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));
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);
overwrite_filemode(expected_driver, &actual);
cl_assert_equal_s(expected.ptr, actual.ptr);
cl_assert_equal_s(expected_driver, 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);
git_buf_free(&expected);
}
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
Unnamed repository; edit this file 'description' to name the repository.
9db1d09ff9ad5190bcf12d72ea3c818ffca344c5
<html>
<body>
<h1 id="first section">
<ol>
<li>item 1.1</li>
<li>item 1.2 changed</li>
<li>item 1.3 changed</li>
<li>item 1.4</li>
<li>item 1.5</li>
<li>item 1.6</li>
<li>item 1.7</li>
<li>item 1.8</li>
<li>item 1.9</li>
<li>item 1.10 added</li>
</ol>
</h1>
<h1 id="second section">
<ol>
<li>item 2.1</li>
<li>item 2.2</li>
<li>item 2.3</li>
<li>item 2.4</li>
<li>item 2.5</li>
<li>item 2.6</li>
<li>item 2.7 changed</li>
<li>item 2.7.1 added</li>
<li>item 2.8</li>
</ol>
</h1>
<h1 id="third section">
<ol>
<li>item 3.1</li>
<li>item 3.2</li>
<li>item 3.3</li>
<li>item 3.4</li>
<li>item 3.5</li>
<li>item 3.6</li>
</ol>
</h1>
</body>
</html>
<html>
<body>
<h1 id="first section">
<ol>
<li>item 1.1</li>
<li>item 1.2</li>
<li>item 1.3</li>
<li>item 1.4</li>
<li>item 1.5</li>
<li>item 1.6</li>
<li>item 1.7</li>
<li>item 1.8</li>
<li>item 1.9</li>
</ol>
</h1>
<h1 id="second section">
<ol>
<li>item 2.1</li>
<li>item 2.2</li>
<li>item 2.3</li>
<li>item 2.4</li>
<li>item 2.5</li>
<li>item 2.6</li>
<li>item 2.7</li>
<li>item 2.8</li>
</ol>
</h1>
<h1 id="third section">
<ol>
<li>item 3.1</li>
<li>item 3.2</li>
<li>item 3.3</li>
<li>item 3.4</li>
<li>item 3.5</li>
<li>item 3.6</li>
<li>item 3.7</li>
<li>item 3.8</li>
</ol>
</h1>
</body>
</html>
diff --git a/files/file.html b/files/file.html
index 872d196..2320e2f 100644
--- a/files/file.html
+++ b/files/file.html
@@ -5,4 +5,4 @@ <h1 id="first section">
<li>item 1.1</li>
- <li>item 1.2</li>
- <li>item 1.3</li>
+ <li>item 1.2 changed</li>
+ <li>item 1.3 changed</li>
<li>item 1.4</li>
@@ -13,2 +13,3 @@ <h1 id="first section">
<li>item 1.9</li>
+ <li>item 1.10 added</li>
</ol>
@@ -23,3 +24,4 @@ <h1 id="second section">
<li>item 2.6</li>
- <li>item 2.7</li>
+ <li>item 2.7 changed</li>
+ <li>item 2.7.1 added</li>
<li>item 2.8</li>
@@ -35,4 +37,2 @@ <h1 id="third section">
<li>item 3.6</li>
- <li>item 3.7</li>
- <li>item 3.8</li>
</ol>
diff --git a/files/file.html b/files/file.html
index 872d196..2320e2f 100644
--- a/files/file.html
+++ b/files/file.html
@@ -5,4 +5,4 @@
<li>item 1.1</li>
- <li>item 1.2</li>
- <li>item 1.3</li>
+ <li>item 1.2 changed</li>
+ <li>item 1.3 changed</li>
<li>item 1.4</li>
@@ -13,2 +13,3 @@
<li>item 1.9</li>
+ <li>item 1.10 added</li>
</ol>
@@ -23,3 +24,4 @@
<li>item 2.6</li>
- <li>item 2.7</li>
+ <li>item 2.7 changed</li>
+ <li>item 2.7.1 added</li>
<li>item 2.8</li>
@@ -35,4 +37,2 @@
<li>item 3.6</li>
- <li>item 3.7</li>
- <li>item 3.8</li>
</ol>
<html>
<body>
<h1 id="first section">
<ol>
<li>item 1.1</li>
<li>item 1.2 changed</li>
<li>item 1.3 changed</li>
<li>item 1.4</li>
<li>item 1.5</li>
<li>item 1.6</li>
<li>item 1.7</li>
<li>item 1.8</li>
<li>item 1.9</li>
<li>item 1.10 added</li>
</ol>
</h1>
<h1 id="second section">
<ol>
<li>item 2.1</li>
<li>item 2.2</li>
<li>item 2.3</li>
<li>item 2.4</li>
<li>item 2.5</li>
<li>item 2.6</li>
<li>item 2.7 changed</li>
<li>item 2.7.1 added</li>
<li>item 2.8</li>
</ol>
</h1>
<h1 id="third section">
<ol>
<li>item 3.1</li>
<li>item 3.2</li>
<li>item 3.3</li>
<li>item 3.4</li>
<li>item 3.5</li>
<li>item 3.6</li>
</ol>
</h1>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment