@matheusbsbs / matheus-bagliano / commits / 989eea958b
Fork 0

lib-log-graph: consolidate test_cmp_graph logic

Log graph comparision logic is duplicated many times in: - t3430-rebase-merges.sh - t4202-log.sh - t4214-log-graph-octopus.sh - t4215-log-skewed-merges.sh Consolidate the core of the comparision and sanitization logic in lib-log-graph, and use it to replace the existing tests. While at it, lose the singular/plural transition magic from the sanitize_output helper, which was necessary around 7f814632 ("Use correct grammar in diffstat summary line", 2012-02-01), that has long outlived its usefulness. Signed-off-by: Abhishek Kumar <abhishekkumar8222@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Abhishek Kumar committed Feb 24, 2020 at 19:08 UTC 989eea958bb3a334c73abcfffb9aa3ec3ed56766
5 files changed +54 -77
t/lib-log-graph.sh new
+22
@@ -0,0 +1,22 @@
1 +# Helps shared by the test scripts for comparing log graphs.
2 +
3 +sanitize_log_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/index [0-9a-f]*\.\.[0-9a-f]*/index BEFORE..AFTER/'
10 +}
11 +
12 +lib_test_cmp_graph () {
13 + git log --graph "$@" >output &&
14 + sed 's/ *$//' >output.sanitized <output &&
15 + test_i18ncmp expect output.sanitized
16 +}
17 +
18 +lib_test_cmp_short_graph () {
19 + git log --graph --pretty=short "$@" >output &&
20 + sanitize_log_output >output.sanitized <output &&
21 + test_i18ncmp expect output.sanitized
22 +}
t/t3430-rebase-merges.sh
+2 -3
@@ -20,12 +20,11 @@ Initial setup:
20 '
21 . ./test-lib.sh
22 . "$TEST_DIRECTORY"/lib-rebase.sh
23 +. "$TEST_DIRECTORY"/lib-log-graph.sh
24
25 test_cmp_graph () {
26 cat >expect &&
26 - git log --graph --boundary --format=%s "$@" >output &&
27 - sed "s/ *$//" <output >output.trimmed &&
28 - test_cmp expect output.trimmed
27 + lib_test_cmp_graph --boundary --format=%s "$@"
28 }
29
30 test_expect_success 'setup' '
t/t4202-log.sh
+14 -39
@@ -5,6 +5,11 @@ test_description='git log'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY/lib-gpg.sh"
7 . "$TEST_DIRECTORY/lib-terminal.sh"
8 +. "$TEST_DIRECTORY/lib-log-graph.sh"
9 +
10 +test_cmp_graph () {
11 + lib_test_cmp_graph --format=%s "$@"
12 +}
13
14 test_expect_success setup '
15
@@ -452,8 +457,7 @@ cat > expect <<EOF
457 EOF
458
459 test_expect_success 'simple log --graph' '
455 - git log --graph --pretty=tformat:%s >actual &&
456 - test_cmp expect actual
460 + test_cmp_graph
461 '
462
463 cat > expect <<EOF
@@ -467,8 +471,7 @@ cat > expect <<EOF
471 EOF
472
473 test_expect_success 'simple log --graph --line-prefix="123 "' '
470 - git log --graph --line-prefix="123 " --pretty=tformat:%s >actual &&
471 - test_cmp expect actual
474 + test_cmp_graph --line-prefix="123 "
475 '
476
477 test_expect_success 'set up merge history' '
@@ -495,9 +498,7 @@ cat > expect <<\EOF
498 EOF
499
500 test_expect_success 'log --graph with merge' '
498 - git log --graph --date-order --pretty=tformat:%s |
499 - sed "s/ *\$//" >actual &&
500 - test_cmp expect actual
501 + test_cmp_graph --date-order
502 '
503
504 cat > expect <<\EOF
@@ -516,9 +517,7 @@ cat > expect <<\EOF
517 EOF
518
519 test_expect_success 'log --graph --line-prefix="| | | " with merge' '
519 - git log --line-prefix="| | | " --graph --date-order --pretty=tformat:%s |
520 - sed "s/ *\$//" >actual &&
521 - test_cmp expect actual
520 + test_cmp_graph --line-prefix="| | | " --date-order
521 '
522
523 cat > expect.colors <<\EOF
@@ -676,9 +675,7 @@ cat > expect <<\EOF
675 EOF
676
677 test_expect_success 'log --graph with merge' '
679 - git log --graph --date-order --pretty=tformat:%s |
680 - sed "s/ *\$//" >actual &&
681 - test_cmp expect actual
678 + test_cmp_graph --date-order
679 '
680
681 test_expect_success 'log.decorate configuration' '
@@ -1213,24 +1210,8 @@ cat >expect <<\EOF
1210 +one
1211 EOF
1212
1216 -sanitize_output () {
1217 - sed -e 's/ *$//' \
1218 - -e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \
1219 - -e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \
1220 - -e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \
1221 - -e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \
1222 - -e 's/, 0 deletions(-)//' \
1223 - -e 's/, 0 insertions(+)//' \
1224 - -e 's/ 1 files changed, / 1 file changed, /' \
1225 - -e 's/, 1 deletions(-)/, 1 deletion(-)/' \
1226 - -e 's/, 1 insertions(+)/, 1 insertion(+)/' \
1227 - -e 's/index [0-9a-f]*\.\.[0-9a-f]*/index BEFORE..AFTER/'
1228 -}
1229 -
1213 test_expect_success 'log --graph with diff and stats' '
1231 - git log --no-renames --graph --pretty=short --stat -p >actual &&
1232 - sanitize_output >actual.sanitized <actual &&
1233 - test_i18ncmp expect actual.sanitized
1214 + lib_test_cmp_short_graph --no-renames --stat -p
1215 '
1216
1217 cat >expect <<\EOF
@@ -1505,9 +1486,7 @@ cat >expect <<\EOF
1486 EOF
1487
1488 test_expect_success 'log --line-prefix="*** " --graph with diff and stats' '
1508 - git log --line-prefix="*** " --no-renames --graph --pretty=short --stat -p >actual &&
1509 - sanitize_output >actual.sanitized <actual &&
1510 - test_i18ncmp expect actual.sanitized
1489 + lib_test_cmp_short_graph --line-prefix="*** " --no-renames --stat -p
1490 '
1491
1492 cat >expect <<-\EOF
@@ -1529,9 +1508,7 @@ cat >expect <<-\EOF
1508 EOF
1509
1510 test_expect_success 'log --graph with --name-status' '
1532 - git log --graph --format=%s --name-status tangle..reach >actual &&
1533 - sanitize_output <actual >actual.sanitized &&
1534 - test_cmp expect actual.sanitized
1511 + test_cmp_graph --name-status tangle..reach
1512 '
1513
1514 cat >expect <<-\EOF
@@ -1553,9 +1530,7 @@ cat >expect <<-\EOF
1530 EOF
1531
1532 test_expect_success 'log --graph with --name-only' '
1556 - git log --graph --format=%s --name-only tangle..reach >actual &&
1557 - sanitize_output <actual >actual.sanitized &&
1558 - test_cmp expect actual.sanitized
1533 + test_cmp_graph --name-only tangle..reach
1534 '
1535
1536 test_expect_success 'dotdot is a parent directory' '
t/t4214-log-graph-octopus.sh
+14 -32
@@ -3,6 +3,12 @@
3 test_description='git log --graph of skewed left octopus merge.'
4
5 . ./test-lib.sh
6 +. "$TEST_DIRECTORY"/lib-log-graph.sh
7 +
8 +test_cmp_graph () {
9 + cat >expect &&
10 + lib_test_cmp_graph --color=never --date-order --format=%s "$@"
11 +}
12
13 test_expect_success 'set up merge history' '
14 test_commit initial &&
@@ -24,7 +30,7 @@ test_expect_success 'set up merge history' '
30 '
31
32 test_expect_success 'log --graph with tricky octopus merge, no color' '
27 - cat >expect.uncolored <<-\EOF &&
33 + test_cmp_graph left octopus-merge <<-\EOF
34 * left
35 | *-. octopus-merge
36 |/|\ \
@@ -37,9 +43,6 @@ test_expect_success 'log --graph with tricky octopus merge, no color' '
43 |/
44 * initial
45 EOF
40 - git log --color=never --graph --date-order --pretty=tformat:%s left octopus-merge >actual.raw &&
41 - sed "s/ *\$//" actual.raw >actual &&
42 - test_cmp expect.uncolored actual
46 '
47
48 test_expect_success 'log --graph with tricky octopus merge with colors' '
@@ -66,7 +69,7 @@ test_expect_success 'log --graph with tricky octopus merge with colors' '
69 # without the first parent skewing to the "left" branch column).
70
71 test_expect_success 'log --graph with normal octopus merge, no color' '
69 - cat >expect.uncolored <<-\EOF &&
72 + test_cmp_graph octopus-merge <<-\EOF
73 *---. octopus-merge
74 |\ \ \
75 | | | * 4
@@ -78,9 +81,6 @@ test_expect_success 'log --graph with normal octopus merge, no color' '
81 |/
82 * initial
83 EOF
81 - git log --color=never --graph --date-order --pretty=tformat:%s octopus-merge >actual.raw &&
82 - sed "s/ *\$//" actual.raw >actual &&
83 - test_cmp expect.uncolored actual
84 '
85
86 test_expect_success 'log --graph with normal octopus merge with colors' '
@@ -103,7 +103,7 @@ test_expect_success 'log --graph with normal octopus merge with colors' '
103 '
104
105 test_expect_success 'log --graph with normal octopus merge and child, no color' '
106 - cat >expect.uncolored <<-\EOF &&
106 + test_cmp_graph after-merge <<-\EOF
107 * after-merge
108 *---. octopus-merge
109 |\ \ \
@@ -116,9 +116,6 @@ test_expect_success 'log --graph with normal octopus merge and child, no color'
116 |/
117 * initial
118 EOF
119 - git log --color=never --graph --date-order --pretty=tformat:%s after-merge >actual.raw &&
120 - sed "s/ *\$//" actual.raw >actual &&
121 - test_cmp expect.uncolored actual
119 '
120
121 test_expect_success 'log --graph with normal octopus and child merge with colors' '
@@ -142,7 +139,7 @@ test_expect_success 'log --graph with normal octopus and child merge with colors
139 '
140
141 test_expect_success 'log --graph with tricky octopus merge and its child, no color' '
145 - cat >expect.uncolored <<-\EOF &&
142 + test_cmp_graph left after-merge <<-\EOF
143 * left
144 | * after-merge
145 | *-. octopus-merge
@@ -156,9 +153,6 @@ test_expect_success 'log --graph with tricky octopus merge and its child, no col
153 |/
154 * initial
155 EOF
159 - git log --color=never --graph --date-order --pretty=tformat:%s left after-merge >actual.raw &&
160 - sed "s/ *\$//" actual.raw >actual &&
161 - test_cmp expect.uncolored actual
156 '
157
158 test_expect_success 'log --graph with tricky octopus merge and its child with colors' '
@@ -183,7 +177,7 @@ test_expect_success 'log --graph with tricky octopus merge and its child with co
177 '
178
179 test_expect_success 'log --graph with crossover in octopus merge, no color' '
186 - cat >expect.uncolored <<-\EOF &&
180 + test_cmp_graph after-4 octopus-merge <<-\EOF
181 * after-4
182 | *---. octopus-merge
183 | |\ \ \
@@ -200,9 +194,6 @@ test_expect_success 'log --graph with crossover in octopus merge, no color' '
194 |/
195 * initial
196 EOF
203 - git log --color=never --graph --date-order --pretty=tformat:%s after-4 octopus-merge >actual.raw &&
204 - sed "s/ *\$//" actual.raw >actual &&
205 - test_cmp expect.uncolored actual
197 '
198
199 test_expect_success 'log --graph with crossover in octopus merge with colors' '
@@ -230,7 +221,7 @@ test_expect_success 'log --graph with crossover in octopus merge with colors' '
221 '
222
223 test_expect_success 'log --graph with crossover in octopus merge and its child, no color' '
233 - cat >expect.uncolored <<-\EOF &&
224 + test_cmp_graph after-4 after-merge <<-\EOF
225 * after-4
226 | * after-merge
227 | *---. octopus-merge
@@ -248,9 +239,6 @@ test_expect_success 'log --graph with crossover in octopus merge and its child,
239 |/
240 * initial
241 EOF
251 - git log --color=never --graph --date-order --pretty=tformat:%s after-4 after-merge >actual.raw &&
252 - sed "s/ *\$//" actual.raw >actual &&
253 - test_cmp expect.uncolored actual
242 '
243
244 test_expect_success 'log --graph with crossover in octopus merge and its child with colors' '
@@ -279,7 +267,7 @@ test_expect_success 'log --graph with crossover in octopus merge and its child w
267 '
268
269 test_expect_success 'log --graph with unrelated commit and octopus tip, no color' '
282 - cat >expect.uncolored <<-\EOF &&
270 + test_cmp_graph after-initial octopus-merge <<-\EOF
271 * after-initial
272 | *---. octopus-merge
273 | |\ \ \
@@ -296,9 +284,6 @@ test_expect_success 'log --graph with unrelated commit and octopus tip, no color
284 |/
285 * initial
286 EOF
299 - git log --color=never --graph --date-order --pretty=tformat:%s after-initial octopus-merge >actual.raw &&
300 - sed "s/ *\$//" actual.raw >actual &&
301 - test_cmp expect.uncolored actual
287 '
288
289 test_expect_success 'log --graph with unrelated commit and octopus tip with colors' '
@@ -326,7 +311,7 @@ test_expect_success 'log --graph with unrelated commit and octopus tip with colo
311 '
312
313 test_expect_success 'log --graph with unrelated commit and octopus child, no color' '
329 - cat >expect.uncolored <<-\EOF &&
314 + test_cmp_graph after-initial after-merge <<-\EOF
315 * after-initial
316 | * after-merge
317 | *---. octopus-merge
@@ -344,9 +329,6 @@ test_expect_success 'log --graph with unrelated commit and octopus child, no col
329 |/
330 * initial
331 EOF
347 - git log --color=never --graph --date-order --pretty=tformat:%s after-initial after-merge >actual.raw &&
348 - sed "s/ *\$//" actual.raw >actual &&
349 - test_cmp expect.uncolored actual
332 '
333
334 test_expect_success 'log --graph with unrelated commit and octopus child with colors' '
t/t4215-log-skewed-merges.sh
+2 -3
@@ -3,12 +3,11 @@
3 test_description='git log --graph of skewed merges'
4
5 . ./test-lib.sh
6 +. "$TEST_DIRECTORY"/lib-log-graph.sh
7
8 check_graph () {
9 cat >expect &&
9 - git log --graph --pretty=tformat:%s "$@" >actual.raw &&
10 - sed "s/ *$//" actual.raw >actual &&
11 - test_cmp expect actual
10 + lib_test_cmp_graph --format=%s "$@"
11 }
12
13 test_expect_success 'log --graph with merge fusing with its left and right neighbors' '