Skip to content

Commit 30defe5

Browse files
committed
Merge branch 'ak/test-log-graph' into pu
Test update. The first half of it seems a bit of unnecessary chrun, while the latter half looks improvement. * ak/test-log-graph: t4202: use lib-log-graph functions t4214: use lib-log-graph functions t4215: use lib-log-graph functions t3430: use lib-log-graph functions SQUASH??? lib-log-graph.sh: consolidate test_cmp_graph logic
2 parents 50b6dbf + f192a1d commit 30defe5

File tree

5 files changed

+93
-137
lines changed

5 files changed

+93
-137
lines changed

t/lib-log-graph.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Helpers shared by the test scripts for comparing log graphs.
2+
3+
sanitize_output () {
4+
# Versions of Git that predate 7f814632 ("Use correct grammar
5+
# in diffstat summary line", 2012-02-01) did not correctly use
6+
# singular when one path was involved, and a handful of rules
7+
# were added to work with both older and newer versions of Git
8+
# back then. These are probably not relevant anymore, and
9+
# we'd want to lose them someday...
10+
sed -e 's/ *$//' \
11+
-e 's/commit [0-9a-f]*$/commit COMMIT_OBJECT_NAME/' \
12+
-e 's/Merge: [ 0-9a-f]*$/Merge: MERGE_PARENTS/' \
13+
-e 's/Merge tag.*/Merge HEADS DESCRIPTION/' \
14+
-e 's/Merge commit.*/Merge HEADS DESCRIPTION/' \
15+
-e 's/, 0 deletions(-)//' \
16+
-e 's/, 0 insertions(+)//' \
17+
-e 's/ 1 files changed, / 1 file changed, /' \
18+
-e 's/, 1 deletions(-)/, 1 deletion(-)/' \
19+
-e 's/, 1 insertions(+)/, 1 insertion(+)/' \
20+
-e 's/index [0-9a-f]*\.\.[0-9a-f]*/index BEFORE..AFTER/'
21+
}
22+
23+
# Assume expected graph is in file `expect`
24+
test_cmp_graph_file () {
25+
git log --graph "$@" >output &&
26+
sanitize_output >output.sanitized <output &&
27+
test_i18ncmp expect output.sanitized
28+
}
29+
30+
test_cmp_graph () {
31+
cat >expect &&
32+
test_cmp_graph_file "$@"
33+
}
34+
35+
# Assume expected graph is in file `expect.colors`
36+
test_cmp_colored_graph_file () {
37+
git log --graph --color=always "$@" >output.colors.raw &&
38+
test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors &&
39+
test_cmp expect.colors output.colors
40+
}
41+
42+
test_cmp_colored_graph () {
43+
cat >expect.colors &&
44+
test_cmp_colored_graph_file "$@"
45+
}

t/t3430-rebase-merges.sh

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ Initial setup:
2020
'
2121
. ./test-lib.sh
2222
. "$TEST_DIRECTORY"/lib-rebase.sh
23-
24-
test_cmp_graph () {
25-
cat >expect &&
26-
git log --graph --boundary --format=%s "$@" >output &&
27-
sed "s/ *$//" <output >output.trimmed &&
28-
test_cmp expect output.trimmed
29-
}
23+
. "$TEST_DIRECTORY"/lib-log-graph.sh
3024

3125
test_expect_success 'setup' '
3226
write_script replace-editor.sh <<-\EOF &&
@@ -84,7 +78,7 @@ test_expect_success 'create completely different structure' '
8478
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
8579
test_tick &&
8680
git rebase -i -r A master &&
87-
test_cmp_graph <<-\EOF
81+
test_cmp_graph --pretty=tformat:%s --boundary <<-\EOF
8882
* Merge the topic branch '\''onebranch'\''
8983
|\
9084
| * D
@@ -201,7 +195,7 @@ test_expect_success 'with a branch tip that was cherry-picked already' '
201195
git checkout already-upstream &&
202196
test_tick &&
203197
git rebase -i -r upstream-with-a2 &&
204-
test_cmp_graph upstream-with-a2.. <<-\EOF
198+
test_cmp_graph --pretty=tformat:%s --boundary upstream-with-a2.. <<-\EOF
205199
* Merge branch A
206200
|\
207201
| * A1
@@ -219,7 +213,7 @@ test_expect_success 'do not rebase cousins unless asked for' '
219213
test_cmp_rev HEAD $before &&
220214
test_tick &&
221215
git rebase --rebase-merges=rebase-cousins HEAD^ &&
222-
test_cmp_graph HEAD^.. <<-\EOF
216+
test_cmp_graph --pretty=tformat:%s --boundary HEAD^.. <<-\EOF
223217
* Merge the topic branch '\''onebranch'\''
224218
|\
225219
| * D
@@ -311,7 +305,7 @@ test_expect_success 'root commits' '
311305
test $(git rev-parse second-root^0) != $(git rev-parse HEAD^) &&
312306
test $(git rev-parse second-root:second-root.t) = \
313307
$(git rev-parse HEAD^:second-root.t) &&
314-
test_cmp_graph HEAD <<-\EOF &&
308+
test_cmp_graph --pretty=tformat:%s --boundary HEAD <<-\EOF &&
315309
* Merge the 3rd root
316310
|\
317311
| * third-root
@@ -347,15 +341,15 @@ test_expect_success 'A root commit can be a cousin, treat it that way' '
347341
test_tick &&
348342
git rebase -f -r HEAD^ &&
349343
test_cmp_rev ! HEAD^2 khnum &&
350-
test_cmp_graph HEAD^.. <<-\EOF &&
344+
test_cmp_graph --pretty=tformat:%s --boundary HEAD^.. <<-\EOF &&
351345
* Merge branch '\''khnum'\'' into asherah
352346
|\
353347
| * yama
354348
o shamkat
355349
EOF
356350
test_tick &&
357351
git rebase --rebase-merges=rebase-cousins HEAD^ &&
358-
test_cmp_graph HEAD^.. <<-\EOF
352+
test_cmp_graph --pretty=tformat:%s --boundary HEAD^.. <<-\EOF
359353
* Merge branch '\''khnum'\'' into asherah
360354
|\
361355
| * yama
@@ -402,7 +396,7 @@ test_expect_success 'octopus merges' '
402396
git rebase -i --force-rebase -r HEAD^^ &&
403397
test "Hank" = "$(git show -s --format=%an HEAD)" &&
404398
test "$before" != $(git rev-parse HEAD) &&
405-
test_cmp_graph HEAD^^.. <<-\EOF
399+
test_cmp_graph --pretty=tformat:%s --boundary HEAD^^.. <<-\EOF
406400
*-. Tüntenfüsch
407401
|\ \
408402
| | * three
@@ -478,7 +472,7 @@ test_expect_success '--rebase-merges with message matched with onto label' '
478472
git checkout -b onto-label E &&
479473
git merge -m onto G &&
480474
git rebase --rebase-merges --force-rebase E &&
481-
test_cmp_graph <<-\EOF
475+
test_cmp_graph --pretty=tformat:%s --boundary <<-\EOF
482476
* onto
483477
|\
484478
| * G

t/t4202-log.sh

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='git log'
55
. ./test-lib.sh
66
. "$TEST_DIRECTORY/lib-gpg.sh"
77
. "$TEST_DIRECTORY/lib-terminal.sh"
8+
. "$TEST_DIRECTORY/lib-log-graph.sh"
89

910
test_expect_success setup '
1011
@@ -452,8 +453,7 @@ cat > expect <<EOF
452453
EOF
453454

454455
test_expect_success 'simple log --graph' '
455-
git log --graph --pretty=tformat:%s >actual &&
456-
test_cmp expect actual
456+
test_cmp_graph_file --pretty=tformat:%s
457457
'
458458

459459
cat > expect <<EOF
@@ -467,8 +467,7 @@ cat > expect <<EOF
467467
EOF
468468

469469
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
470+
test_cmp_graph_file --line-prefix="123 " --pretty=tformat:%s
472471
'
473472

474473
test_expect_success 'set up merge history' '
@@ -495,9 +494,7 @@ cat > expect <<\EOF
495494
EOF
496495

497496
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
497+
test_cmp_graph_file --date-order --pretty=tformat:%s
501498
'
502499

503500
cat > expect <<\EOF
@@ -516,9 +513,7 @@ cat > expect <<\EOF
516513
EOF
517514

518515
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
516+
test_cmp_graph_file --line-prefix="| | | " --date-order --pretty=tformat:%s
522517
'
523518

524519
cat > expect.colors <<\EOF
@@ -538,9 +533,7 @@ EOF
538533

539534
test_expect_success 'log --graph with merge with log.graphColors' '
540535
test_config log.graphColors " blue,invalid-color, cyan, red , " &&
541-
git log --color=always --graph --date-order --pretty=tformat:%s |
542-
test_decode_color | sed "s/ *\$//" >actual &&
543-
test_cmp expect.colors actual
536+
test_cmp_colored_graph_file --date-order --pretty=tformat:%s
544537
'
545538

546539
test_expect_success 'log --raw --graph -m with merge' '
@@ -1213,24 +1206,8 @@ cat >expect <<\EOF
12131206
+one
12141207
EOF
12151208

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-
12301209
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
1210+
test_cmp_graph_file --no-renames --graph --pretty=short --stat -p
12341211
'
12351212

12361213
cat >expect <<\EOF
@@ -1505,9 +1482,7 @@ cat >expect <<\EOF
15051482
EOF
15061483

15071484
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
1485+
test_cmp_graph_file --line-prefix="*** " --no-renames --graph --pretty=short --stat -p
15111486
'
15121487

15131488
cat >expect <<-\EOF
@@ -1529,9 +1504,7 @@ cat >expect <<-\EOF
15291504
EOF
15301505

15311506
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
1507+
test_cmp_graph_file --pretty=tformat:%s --name-status tangle..reach
15351508
'
15361509

15371510
cat >expect <<-\EOF
@@ -1553,9 +1526,7 @@ cat >expect <<-\EOF
15531526
EOF
15541527

15551528
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
1529+
test_cmp_graph_file --pretty=tformat:%s --name-only tangle..reach
15591530
'
15601531

15611532
test_expect_success 'dotdot is a parent directory' '

0 commit comments

Comments
 (0)