Skip to content

Commit 5d77298

Browse files
martinvonzgitster
authored andcommitted
tests: move test_cmp_rev to test-lib-functions
A function for checking that two given parameters refer to the same revision was defined in several places, so move the definition to test-lib-functions.sh instead. Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b3cf6f3 commit 5d77298

7 files changed

+15
-40
lines changed

t/t1505-rev-parse-last.sh

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,24 @@ test_expect_success 'setup' '
3232
#
3333
# and 'side' should be the last branch
3434

35-
test_rev_equivalent () {
36-
37-
git rev-parse "$1" > expect &&
38-
git rev-parse "$2" > output &&
39-
test_cmp expect output
40-
41-
}
42-
4335
test_expect_success '@{-1} works' '
44-
test_rev_equivalent side @{-1}
36+
test_cmp_rev side @{-1}
4537
'
4638

4739
test_expect_success '@{-1}~2 works' '
48-
test_rev_equivalent side~2 @{-1}~2
40+
test_cmp_rev side~2 @{-1}~2
4941
'
5042

5143
test_expect_success '@{-1}^2 works' '
52-
test_rev_equivalent side^2 @{-1}^2
44+
test_cmp_rev side^2 @{-1}^2
5345
'
5446

5547
test_expect_success '@{-1}@{1} works' '
56-
test_rev_equivalent side@{1} @{-1}@{1}
48+
test_cmp_rev side@{1} @{-1}@{1}
5749
'
5850

5951
test_expect_success '@{-2} works' '
60-
test_rev_equivalent master @{-2}
52+
test_cmp_rev master @{-2}
6153
'
6254

6355
test_expect_success '@{-3} fails' '

t/t3404-rebase-interactive.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ Initial setup:
2929

3030
. "$TEST_DIRECTORY"/lib-rebase.sh
3131

32-
test_cmp_rev () {
33-
git rev-parse --verify "$1" >expect.rev &&
34-
git rev-parse --verify "$2" >actual.rev &&
35-
test_cmp expect.rev actual.rev
36-
}
37-
3832
set_fake_editor
3933

4034
# WARNING: Modifications to the initial repository can change the SHA ID used

t/t3507-cherry-pick-conflict.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ test_description='test cherry-pick and revert with conflicts
1111

1212
. ./test-lib.sh
1313

14-
test_cmp_rev () {
15-
git rev-parse --verify "$1" >expect.rev &&
16-
git rev-parse --verify "$2" >actual.rev &&
17-
test_cmp expect.rev actual.rev
18-
}
19-
2014
pristine_detach () {
2115
git checkout -f "$1^0" &&
2216
git read-tree -u --reset HEAD &&

t/t3508-cherry-pick-many-commits.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ test_description='test cherry-picking many commits'
55
. ./test-lib.sh
66

77
check_head_differs_from() {
8-
head=$(git rev-parse --verify HEAD) &&
9-
arg=$(git rev-parse --verify "$1") &&
10-
test "$head" != "$arg"
8+
! test_cmp_rev HEAD "$1"
119
}
1210

1311
check_head_equals() {
14-
head=$(git rev-parse --verify HEAD) &&
15-
arg=$(git rev-parse --verify "$1") &&
16-
test "$head" = "$arg"
12+
test_cmp_rev HEAD "$1"
1713
}
1814

1915
test_expect_success setup '

t/t3510-cherry-pick-sequence.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ pristine_detach () {
2424
git clean -d -f -f -q -x
2525
}
2626

27-
test_cmp_rev () {
28-
git rev-parse --verify "$1" >expect.rev &&
29-
git rev-parse --verify "$2" >actual.rev &&
30-
test_cmp expect.rev actual.rev
31-
}
32-
3327
test_expect_success setup '
3428
git config advice.detachedhead false &&
3529
echo unrelated >unrelated &&

t/t6030-bisect-porcelain.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,7 @@ test_expect_success 'bisect fails if tree is broken on trial commit' '
676676
check_same()
677677
{
678678
echo "Checking $1 is the same as $2" &&
679-
git rev-parse "$1" > expected.same &&
680-
git rev-parse "$2" > expected.actual &&
681-
test_cmp expected.same expected.actual
679+
test_cmp_rev "$1" "$2"
682680
}
683681

684682
test_expect_success 'bisect: --no-checkout - start commit bad' '

t/test-lib-functions.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,13 @@ test_cmp() {
602602
$GIT_TEST_CMP "$@"
603603
}
604604

605+
# Tests that its two parameters refer to the same revision
606+
test_cmp_rev () {
607+
git rev-parse --verify "$1" >expect.rev &&
608+
git rev-parse --verify "$2" >actual.rev &&
609+
test_cmp expect.rev actual.rev
610+
}
611+
605612
# Print a sequence of numbers or letters in increasing order. This is
606613
# similar to GNU seq(1), but the latter might not be available
607614
# everywhere (and does not do letters). It may be used like:

0 commit comments

Comments
 (0)