Skip to content

Commit caf5ea7

Browse files
bhendersongitster
authored andcommitted
diff-highlight: add failing test for handling --graph output
Signed-off-by: Brian Henderson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 23b250a commit caf5ea7

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

contrib/diff-highlight/t/t9400-diff-highlight.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,55 @@ test_strip_patch_header () {
4949
sed -n '/^@@/,$p' $*
5050
}
5151

52+
# dh_test_setup_history generates a contrived graph such that we have at least
53+
# 1 nesting (E) and 2 nestings (F).
54+
#
55+
# A branch
56+
# /
57+
# D---E---F master
58+
#
59+
# git log --all --graph
60+
# * commit
61+
# | A
62+
# | * commit
63+
# | | F
64+
# | * commit
65+
# |/
66+
# | E
67+
# * commit
68+
# D
69+
#
70+
dh_test_setup_history () {
71+
echo "file1" >file1 &&
72+
echo "file2" >file2 &&
73+
echo "file3" >file3 &&
74+
75+
cat file1 >file &&
76+
git add file &&
77+
git commit -m "D" &&
78+
79+
git checkout -b branch &&
80+
cat file2 >file &&
81+
git commit -a -m "A" &&
82+
83+
git checkout master &&
84+
cat file2 >file &&
85+
git commit -a -m "E" &&
86+
87+
cat file3 >file &&
88+
git commit -a -m "F"
89+
}
90+
91+
left_trim () {
92+
"$PERL_PATH" -pe 's/^\s+//'
93+
}
94+
95+
trim_graph () {
96+
# graphs start with * or |
97+
# followed by a space or / or \
98+
"$PERL_PATH" -pe 's@^((\*|\|)( |/|\\))+@@'
99+
}
100+
52101
test_expect_success 'diff-highlight highlights the beginning of a line' '
53102
cat >a <<-\EOF &&
54103
aaa
@@ -160,4 +209,17 @@ test_expect_failure 'diff-highlight highlights mismatched hunk size' '
160209

161210
# TODO add multi-byte test
162211

212+
test_expect_failure 'diff-highlight works with the --graph option' '
213+
dh_test_setup_history &&
214+
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
223+
'
224+
163225
test_done

0 commit comments

Comments
 (0)