Skip to content

Commit 0b9ca46

Browse files
abhishekkumar2718gitster
authored andcommitted
lib-log-graph.sh: consolidate test_cmp_graph logic
Logic for comparing log graphs is duplicated across test scripts. This patchset consolidates such logic into lib-log-graph. Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: Abhishek Kumar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 51ebf55 commit 0b9ca46

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

t/lib-log-graph.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Helpers shared by the test scripts for comparing log graphs.
2+
3+
sanitize_output() {
4+
sed -e 's/ *$//' \
5+
-e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \
6+
-e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \
7+
-e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \
8+
-e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \
9+
-e 's/, 0 deletions(-)//' \
10+
-e 's/, 0 insertions(+)//' \
11+
-e 's/ 1 files changed, / 1 file changed, /' \
12+
-e 's/, 1 deletions(-)/, 1 deletion(-)/' \
13+
-e 's/, 1 insertions(+)/, 1 insertion(+)/' \
14+
-e 's/index [0-9a-f]*\.\.[0-9a-f]*/index BEFORE..AFTER/'
15+
}
16+
17+
# Assume expected graph is in file `expect`
18+
test_cmp_graph_file() {
19+
git log --graph "$@" >output &&
20+
sanitize_output >output.trimmed <output &&
21+
test_i18ncmp expect output.trimmed
22+
}
23+
24+
test_cmp_graph() {
25+
cat >expect &&
26+
test_cmp_graph_file "$@"
27+
}
28+
29+
# Assume expected graph is in file `expect.colors`
30+
test_cmp_colored_graph_file() {
31+
git log --graph --color=always "$@" >output.colors.raw &&
32+
test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors &&
33+
test_cmp expect.colors output.colors
34+
}
35+
36+
test_cmp_colored_graph() {
37+
cat >expect.colors &&
38+
test_cmp_colored_graph_file "$@"
39+
}

0 commit comments

Comments
 (0)