summaryrefslogtreecommitdiff
path: root/tests-clar/diff/rename.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-02-22 10:17:08 -0800
committerRussell Belfer <rb@github.com>2013-02-22 10:17:08 -0800
commit6f9d5ce818f76d305a7aecf727ecda8cff63259c (patch)
tree44efada03d76bb8f1e1ca695b49331d7bf4ba9bd /tests-clar/diff/rename.c
parentd4b747c1cb72119d783154f88640920d3a3fdb3d (diff)
downloadlibgit2-6f9d5ce818f76d305a7aecf727ecda8cff63259c.tar.gz
Fix tests for find_similar and related
This fixes both a test that I broke in diff::patch where I was relying on the current state of the working directory for the renames test data and fixes an unstable test in diff::rename where the environment setting for the "diff.renames" config was being allowed to influence the test results.
Diffstat (limited to 'tests-clar/diff/rename.c')
-rw-r--r--tests-clar/diff/rename.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
index ec99e4dbe..f27fd7d82 100644
--- a/tests-clar/diff/rename.c
+++ b/tests-clar/diff/rename.c
@@ -184,10 +184,14 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
- /* git diff 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
- * 2bc7f351d20b53f1c72c16c4b036e491c478c49a
+ /* git diff -M 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084
+ *
+ * must not pass NULL for opts because it will pick up environment
+ * values for "diff.renames" and test won't be consistent.
*/
- cl_git_pass(git_diff_find_similar(diff, NULL));
+ opts.flags = GIT_DIFF_FIND_RENAMES;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_foreach(
@@ -196,17 +200,40 @@ void test_diff_rename__not_exact_match(void)
cl_assert_equal_i(4, exp.files);
cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
git_diff_list_free(diff);
+ /* git diff -M -C 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
+ * 1c068dee5790ef1580cfc4cd670915b48d790084
+ *
+ * must not pass NULL for opts because it will pick up environment
+ * values for "diff.renames" and test won't be consistent.
+ */
cl_git_pass(git_diff_tree_to_tree(
&diff, g_repo, old_tree, new_tree, &diffopts));
- /* git diff --find-copies-harder --break-rewrites \
+ opts.flags = GIT_DIFF_FIND_RENAMES | GIT_DIFF_FIND_COPIES;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(4, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_UNMODIFIED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_COPIED]);
+
+ git_diff_list_free(diff);
+
+ /* git diff -M -C --find-copies-harder --break-rewrites \
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a \
* 1c068dee5790ef1580cfc4cd670915b48d790084
*/
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, old_tree, new_tree, &diffopts));
+
opts.flags = GIT_DIFF_FIND_ALL;
cl_git_pass(git_diff_find_similar(diff, &opts));