Skip to content

Commit

Permalink
tests: move test_cmp_rev to test-lib-functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Martin von Zweigbergk authored and Junio C Hamano committed Dec 23, 2012
1 parent b3cf6f3 commit 5d77298
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 40 deletions.
18 changes: 5 additions & 13 deletions t/t1505-rev-parse-last.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,24 @@ test_expect_success 'setup' '
#
# and 'side' should be the last branch

test_rev_equivalent () {

git rev-parse "$1" > expect &&
git rev-parse "$2" > output &&
test_cmp expect output

}

test_expect_success '@{-1} works' '
test_rev_equivalent side @{-1}
test_cmp_rev side @{-1}
'

test_expect_success '@{-1}~2 works' '
test_rev_equivalent side~2 @{-1}~2
test_cmp_rev side~2 @{-1}~2
'

test_expect_success '@{-1}^2 works' '
test_rev_equivalent side^2 @{-1}^2
test_cmp_rev side^2 @{-1}^2
'

test_expect_success '@{-1}@{1} works' '
test_rev_equivalent side@{1} @{-1}@{1}
test_cmp_rev side@{1} @{-1}@{1}
'

test_expect_success '@{-2} works' '
test_rev_equivalent master @{-2}
test_cmp_rev master @{-2}
'

test_expect_success '@{-3} fails' '
Expand Down
6 changes: 0 additions & 6 deletions t/t3404-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ Initial setup:

. "$TEST_DIRECTORY"/lib-rebase.sh

test_cmp_rev () {
git rev-parse --verify "$1" >expect.rev &&
git rev-parse --verify "$2" >actual.rev &&
test_cmp expect.rev actual.rev
}

set_fake_editor

# WARNING: Modifications to the initial repository can change the SHA ID used
Expand Down
6 changes: 0 additions & 6 deletions t/t3507-cherry-pick-conflict.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ test_description='test cherry-pick and revert with conflicts

. ./test-lib.sh

test_cmp_rev () {
git rev-parse --verify "$1" >expect.rev &&
git rev-parse --verify "$2" >actual.rev &&
test_cmp expect.rev actual.rev
}

pristine_detach () {
git checkout -f "$1^0" &&
git read-tree -u --reset HEAD &&
Expand Down
8 changes: 2 additions & 6 deletions t/t3508-cherry-pick-many-commits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ test_description='test cherry-picking many commits'
. ./test-lib.sh

check_head_differs_from() {
head=$(git rev-parse --verify HEAD) &&
arg=$(git rev-parse --verify "$1") &&
test "$head" != "$arg"
! test_cmp_rev HEAD "$1"
}

check_head_equals() {
head=$(git rev-parse --verify HEAD) &&
arg=$(git rev-parse --verify "$1") &&
test "$head" = "$arg"
test_cmp_rev HEAD "$1"
}

test_expect_success setup '
Expand Down
6 changes: 0 additions & 6 deletions t/t3510-cherry-pick-sequence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ pristine_detach () {
git clean -d -f -f -q -x
}

test_cmp_rev () {
git rev-parse --verify "$1" >expect.rev &&
git rev-parse --verify "$2" >actual.rev &&
test_cmp expect.rev actual.rev
}

test_expect_success setup '
git config advice.detachedhead false &&
echo unrelated >unrelated &&
Expand Down
4 changes: 1 addition & 3 deletions t/t6030-bisect-porcelain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,7 @@ test_expect_success 'bisect fails if tree is broken on trial commit' '
check_same()
{
echo "Checking $1 is the same as $2" &&
git rev-parse "$1" > expected.same &&
git rev-parse "$2" > expected.actual &&
test_cmp expected.same expected.actual
test_cmp_rev "$1" "$2"
}

test_expect_success 'bisect: --no-checkout - start commit bad' '
Expand Down
7 changes: 7 additions & 0 deletions t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,13 @@ test_cmp() {
$GIT_TEST_CMP "$@"
}

# Tests that its two parameters refer to the same revision
test_cmp_rev () {
git rev-parse --verify "$1" >expect.rev &&
git rev-parse --verify "$2" >actual.rev &&
test_cmp expect.rev actual.rev
}

# Print a sequence of numbers or letters in increasing order. This is
# similar to GNU seq(1), but the latter might not be available
# everywhere (and does not do letters). It may be used like:
Expand Down

0 comments on commit 5d77298

Please sign in to comment.