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 <martinvonz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin von Zweigbergk committed Dec 21, 2012 at 11:10 UTC 5d77298d084f01a854c8aecc1709acf53d956ef8
7 files changed +15 -40
t/t1505-rev-parse-last.sh
+5 -13
@@ -32,32 +32,24 @@ test_expect_success 'setup' '
32 #
33 # and 'side' should be the last branch
34
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 -
35 test_expect_success '@{-1} works' '
44 - test_rev_equivalent side @{-1}
36 + test_cmp_rev side @{-1}
37 '
38
39 test_expect_success '@{-1}~2 works' '
48 - test_rev_equivalent side~2 @{-1}~2
40 + test_cmp_rev side~2 @{-1}~2
41 '
42
43 test_expect_success '@{-1}^2 works' '
52 - test_rev_equivalent side^2 @{-1}^2
44 + test_cmp_rev side^2 @{-1}^2
45 '
46
47 test_expect_success '@{-1}@{1} works' '
56 - test_rev_equivalent side@{1} @{-1}@{1}
48 + test_cmp_rev side@{1} @{-1}@{1}
49 '
50
51 test_expect_success '@{-2} works' '
60 - test_rev_equivalent master @{-2}
52 + test_cmp_rev master @{-2}
53 '
54
55 test_expect_success '@{-3} fails' '
t/t3404-rebase-interactive.sh
-6
@@ -29,12 +29,6 @@ Initial setup:
29
30 . "$TEST_DIRECTORY"/lib-rebase.sh
31
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 -
32 set_fake_editor
33
34 # WARNING: Modifications to the initial repository can change the SHA ID used
t/t3507-cherry-pick-conflict.sh
-6
@@ -11,12 +11,6 @@ test_description='test cherry-pick and revert with conflicts
11
12 . ./test-lib.sh
13
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 -
14 pristine_detach () {
15 git checkout -f "$1^0" &&
16 git read-tree -u --reset HEAD &&
t/t3508-cherry-pick-many-commits.sh
+2 -6
@@ -5,15 +5,11 @@ test_description='test cherry-picking many commits'
5 . ./test-lib.sh
6
7 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"
9 }
10
11 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"
13 }
14
15 test_expect_success setup '
t/t3510-cherry-pick-sequence.sh
-6
@@ -24,12 +24,6 @@ pristine_detach () {
24 git clean -d -f -f -q -x
25 }
26
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 -
27 test_expect_success setup '
28 git config advice.detachedhead false &&
29 echo unrelated >unrelated &&
t/t6030-bisect-porcelain.sh
+1 -3
@@ -676,9 +676,7 @@ test_expect_success 'bisect fails if tree is broken on trial commit' '
676 check_same()
677 {
678 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"
680 }
681
682 test_expect_success 'bisect: --no-checkout - start commit bad' '
t/test-lib-functions.sh
+7
@@ -602,6 +602,13 @@ test_cmp() {
602 $GIT_TEST_CMP "$@"
603 }
604
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 +
612 # Print a sequence of numbers or letters in increasing order. This is
613 # similar to GNU seq(1), but the latter might not be available
614 # everywhere (and does not do letters). It may be used like: