Skip to content

Commit 4670305

Browse files
committed
Merge branch 'ak/test-log-graph'
Test update. * ak/test-log-graph: lib-log-graph: consolidate colored graph cmp logic lib-log-graph: consolidate test_cmp_graph logic
2 parents 777815f + ffe0055 commit 4670305

File tree

5 files changed

+74
-107
lines changed

5 files changed

+74
-107
lines changed

t/lib-log-graph.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
23+
24+
lib_test_cmp_colored_graph () {
25+
git log --graph --color=always "$@" >output.colors.raw &&
26+
test_decode_color <output.colors.raw | sed "s/ *\$//" >output.colors &&
27+
test_cmp expect.colors output.colors
28+
}

t/t3430-rebase-merges.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ Initial setup:
2020
'
2121
. ./test-lib.sh
2222
. "$TEST_DIRECTORY"/lib-rebase.sh
23+
. "$TEST_DIRECTORY"/lib-log-graph.sh
2324

2425
test_cmp_graph () {
2526
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 "$@"
2928
}
3029

3130
test_expect_success 'setup' '

t/t4202-log.sh

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ 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"
9+
10+
test_cmp_graph () {
11+
lib_test_cmp_graph --format=%s "$@"
12+
}
813

914
test_expect_success setup '
1015
@@ -452,8 +457,7 @@ cat > expect <<EOF
452457
EOF
453458

454459
test_expect_success 'simple log --graph' '
455-
git log --graph --pretty=tformat:%s >actual &&
456-
test_cmp expect actual
460+
test_cmp_graph
457461
'
458462

459463
cat > expect <<EOF
@@ -467,8 +471,7 @@ cat > expect <<EOF
467471
EOF
468472

469473
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 "
472475
'
473476

474477
test_expect_success 'set up merge history' '
@@ -495,9 +498,7 @@ cat > expect <<\EOF
495498
EOF
496499

497500
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
501502
'
502503

503504
cat > expect <<\EOF
@@ -516,9 +517,7 @@ cat > expect <<\EOF
516517
EOF
517518

518519
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
522521
'
523522

524523
cat > expect.colors <<\EOF
@@ -538,9 +537,7 @@ EOF
538537

539538
test_expect_success 'log --graph with merge with log.graphColors' '
540539
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
540+
lib_test_cmp_colored_graph --date-order --format=%s
544541
'
545542

546543
test_expect_success 'log --raw --graph -m with merge' '
@@ -676,9 +673,7 @@ cat > expect <<\EOF
676673
EOF
677674

678675
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
676+
test_cmp_graph --date-order
682677
'
683678

684679
test_expect_success 'log.decorate configuration' '
@@ -1213,24 +1208,8 @@ cat >expect <<\EOF
12131208
+one
12141209
EOF
12151210

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-
12301211
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
1212+
lib_test_cmp_short_graph --no-renames --stat -p
12341213
'
12351214

12361215
cat >expect <<\EOF
@@ -1505,9 +1484,7 @@ cat >expect <<\EOF
15051484
EOF
15061485

15071486
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
1487+
lib_test_cmp_short_graph --line-prefix="*** " --no-renames --stat -p
15111488
'
15121489

15131490
cat >expect <<-\EOF
@@ -1529,9 +1506,7 @@ cat >expect <<-\EOF
15291506
EOF
15301507

15311508
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
1509+
test_cmp_graph --name-status tangle..reach
15351510
'
15361511

15371512
cat >expect <<-\EOF
@@ -1553,9 +1528,7 @@ cat >expect <<-\EOF
15531528
EOF
15541529

15551530
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
1531+
test_cmp_graph --name-only tangle..reach
15591532
'
15601533

15611534
test_expect_success 'dotdot is a parent directory' '

0 commit comments

Comments
 (0)