diff options
author | Russell Belfer <rb@github.com> | 2014-01-25 03:45:49 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-01-25 03:45:49 +0400 |
commit | 027b8edac7e91480623815193ed994db808064f6 (patch) | |
tree | f43daef6b20a8c46c1a677ac681841a3a773c51d /tests/diff | |
parent | 3b19d2fdcbd9f6185490fc10e7c4540758954321 (diff) |
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.
Diffstat (limited to 'tests/diff')
-rw-r--r-- | tests/diff/drivers.c | 97 |
1 files changed, 50 insertions, 47 deletions
diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c index 119132149..1cbf9e211 100644 --- a/tests/diff/drivers.c +++ b/tests/diff/drivers.c @@ -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); } |