3 test_description='Test diff-highlight'
6 TEST_OUTPUT_DIRECTORY=$(pwd)
7 TEST_DIRECTORY="$CURR_DIR"/../../../t
8 DIFF_HIGHLIGHT="$CURR_DIR"/../diff-highlight
10 CW="$(printf "\033[7m")" # white
11 CR="$(printf "\033[27m")" # reset
13 . "$TEST_DIRECTORY"/test-lib.sh
15 if ! test_have_prereq PERL
17 skip_all='skipping diff-highlight tests; perl not available'
21 # dh_test is a test helper function which takes 3 file names as parameters. The
22 # first 2 files are used to generate diff and commit output, which is then
23 # piped through diff-highlight. The 3rd file should contain the expected output
24 # of diff-highlight (minus the diff/commit header, ie. everything after and
25 # including the first @@ line).
34 git commit -m "Add a file" &&
37 git diff file >diff.raw &&
38 git commit -a -m "Update a file" &&
42 "$DIFF_HIGHLIGHT" <diff.raw | test_strip_patch_header >diff.act &&
43 "$DIFF_HIGHLIGHT" <commit.raw | test_strip_patch_header >commit.act &&
44 test_cmp patch.exp diff.act &&
45 test_cmp patch.exp commit.act
48 test_strip_patch_header () {
52 # dh_test_setup_history generates a contrived graph such that we have at least
53 # 1 nesting (E) and 2 nestings (F).
59 # git log --all --graph
70 dh_test_setup_history () {
71 echo "file1" >file1 &&
72 echo "file2" >file2 &&
73 echo "file3" >file3 &&
79 git checkout -b branch &&
81 git commit -a -m "A" &&
83 git checkout master &&
85 git commit -a -m "E" &&
92 "$PERL_PATH" -pe 's/^\s+//'
96 # graphs start with * or |
97 # followed by a space or / or \
98 "$PERL_PATH" -pe 's@^((\*|\|)( |/|\\))+@@'
101 test_expect_success 'diff-highlight highlights the beginning of a line' '
123 test_expect_success 'diff-highlight highlights the end of a line' '
145 test_expect_success 'diff-highlight highlights the middle of a line' '
167 test_expect_success 'diff-highlight does not highlight whole line' '
189 test_expect_failure 'diff-highlight highlights mismatched hunk size' '
210 # TODO add multi-byte test
212 test_expect_success 'diff-highlight works with the --graph option' '
213 dh_test_setup_history &&
215 # topo-order so that the order of the commits is the same as with --graph
216 # trim graph elements so we can do a diff
217 # trim leading space because our trim_graph is not perfect
218 git log --branches -p --topo-order |
219 "$DIFF_HIGHLIGHT" | left_trim >graph.exp &&
220 git log --branches -p --graph |
221 "$DIFF_HIGHLIGHT" | trim_graph | left_trim >graph.act &&
222 test_cmp graph.exp graph.act