add test_cmp function for test scripts

Many scripts compare actual and expected output using
"diff -u". This is nicer than "cmp" because the output shows
how the two differ. However, not all versions of diff
understand -u, leading to unnecessary test failure.

This adds a test_cmp function to the test scripts and
switches all "diff -u" invocations to use it. The function
uses the contents of "$GIT_TEST_CMP" to compare its
arguments; the default is "diff -u".

On systems with a less-capable diff, you can do:

  GIT_TEST_CMP=cmp make test

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2008-03-12 17:36:36 -04:00 committed by Junio C Hamano
parent b4ce54fc61
commit 82ebb0b6ec
40 changed files with 133 additions and 115 deletions

View file

@ -11,7 +11,7 @@ attr_check () {
git check-attr test -- "$path" >actual &&
echo "$path: test: $2" >expect &&
diff -u expect actual
test_cmp expect actual
}

View file

@ -26,7 +26,7 @@ test_expect_success 'diff -M' '
git diff-tree -M -r --name-status HEAD^ HEAD |
sed -e "s/R[0-9]*/RNUM/" >actual &&
echo "RNUM sample elpmas" >expect &&
diff -u expect actual
test_cmp expect actual
'

View file

@ -24,7 +24,7 @@ test_expect_success 'setup' '
test_expect_success 'reset should work' '
git read-tree -u --reset HEAD^ &&
git ls-files >actual &&
diff -u expect actual
test_cmp expect actual
'
test_done

View file

@ -62,7 +62,7 @@ test_expect_success 'cache tree has not been corrupted' '
sed -e "s/ 0 / /" >expect &&
git ls-tree -r $(git write-tree) |
sed -e "s/ blob / /" >current &&
diff -u expect current
test_cmp expect current
'

View file

@ -97,7 +97,7 @@ cat > expect << EOF
EOF
test_expect_success 'git-status honours core.excludesfile' \
'diff -u expect output'
'test_cmp expect output'
test_expect_success 'trailing slash in exclude allows directory match(1)' '

View file

@ -26,7 +26,7 @@ test_expect_success clone '
cd cloned &&
(git rev-parse HEAD; git ls-files -s) >../actual
) &&
diff -u expected actual
test_cmp expected actual
'
test_expect_success advance '
@ -46,7 +46,7 @@ test_expect_success fetch '
git pull &&
(git rev-parse HEAD; git ls-files -s) >../actual
) &&
diff -u expected actual
test_cmp expected actual
'
test_done

View file

@ -66,6 +66,6 @@ test_expect_success 'git -ls-files --with-tree should succeed from subdir' '
cd ..
test_expect_success \
'git -ls-files --with-tree should add entries from named tree.' \
'diff -u expected output'
'test_cmp expected output'
test_done

View file

@ -31,7 +31,7 @@ test_expect_success 'branch --contains=master' '
{
echo " master" && echo "* side"
} >expect &&
diff -u expect actual
test_cmp expect actual
'
@ -41,7 +41,7 @@ test_expect_success 'branch --contains master' '
{
echo " master" && echo "* side"
} >expect &&
diff -u expect actual
test_cmp expect actual
'
@ -51,7 +51,7 @@ test_expect_success 'branch --contains=side' '
{
echo "* side"
} >expect &&
diff -u expect actual
test_cmp expect actual
'

View file

@ -146,8 +146,8 @@ EOF
test_expect_success 'stop on conflicting pick' '
git tag new-branch1 &&
! git rebase -i master &&
diff -u expect .git/.dotest-merge/patch &&
diff -u expect2 file1 &&
test_cmp expect .git/.dotest-merge/patch &&
test_cmp expect2 file1 &&
test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) &&
test 0 = $(grep -c "^[^#]" < .git/.dotest-merge/git-rebase-todo)
'

View file

@ -41,8 +41,8 @@ test_expect_success rebase '
git rebase master side &&
git cat-file commit HEAD | sed -e "1,/^\$/d" >F1 &&
diff -u F0 F1 &&
diff -u F F0
test_cmp F0 F1 &&
test_cmp F F0
'
test_done

View file

@ -37,7 +37,7 @@ test_expect_success 'rebase -m' '
git rebase -m master >report &&
sed -n -e "/^Already applied: /p" \
-e "/^Committed: /p" report >actual &&
diff -u expect actual
test_cmp expect actual
'

View file

@ -24,7 +24,7 @@ EOF
test_expect_success 'diff works (initial)' '
(echo d; echo 1) | git add -i >output &&
sed -ne "/new file/,/content/p" <output >diff &&
diff -u expected diff
test_cmp expected diff
'
test_expect_success 'revert works (initial)' '
git add file &&
@ -57,7 +57,7 @@ EOF
test_expect_success 'diff works (commit)' '
(echo d; echo 1) | git add -i >output &&
sed -ne "/^index/,/content/p" <output >diff &&
diff -u expected diff
test_cmp expected diff
'
test_expect_success 'revert works (commit)' '
git add file &&

View file

@ -78,28 +78,28 @@ EOF
test_expect_success 'check fully quoted output from ls-files' '
git ls-files >current && diff -u expect.quoted current
git ls-files >current && test_cmp expect.quoted current
'
test_expect_success 'check fully quoted output from diff-files' '
git diff --name-only >current &&
diff -u expect.quoted current
test_cmp expect.quoted current
'
test_expect_success 'check fully quoted output from diff-index' '
git diff --name-only HEAD >current &&
diff -u expect.quoted current
test_cmp expect.quoted current
'
test_expect_success 'check fully quoted output from diff-tree' '
git diff --name-only HEAD^ HEAD >current &&
diff -u expect.quoted current
test_cmp expect.quoted current
'
@ -111,28 +111,28 @@ test_expect_success 'setting core.quotepath' '
test_expect_success 'check fully quoted output from ls-files' '
git ls-files >current && diff -u expect.raw current
git ls-files >current && test_cmp expect.raw current
'
test_expect_success 'check fully quoted output from diff-files' '
git diff --name-only >current &&
diff -u expect.raw current
test_cmp expect.raw current
'
test_expect_success 'check fully quoted output from diff-index' '
git diff --name-only HEAD >current &&
diff -u expect.raw current
test_cmp expect.raw current
'
test_expect_success 'check fully quoted output from diff-tree' '
git diff --name-only HEAD^ HEAD >current &&
diff -u expect.raw current
test_cmp expect.raw current
'

View file

@ -34,7 +34,7 @@ EOF
test_expect_success 'parents of stash' '
test $(git rev-parse stash^) = $(git rev-parse HEAD) &&
git diff stash^2..stash > output &&
diff -u output expect
test_cmp output expect
'
test_expect_success 'apply needs clean working directory' '

View file

@ -57,7 +57,7 @@ test_expect_success 'cross renames to be detected for regular files' '
echo "R100 foo bar"
echo "R100 bar foo"
} | sort >expect &&
diff -u expect actual
test_cmp expect actual
'
@ -68,7 +68,7 @@ test_expect_success 'cross renames to be detected for typechange' '
echo "R100 foo bar"
echo "R100 bar foo"
} | sort >expect &&
diff -u expect actual
test_cmp expect actual
'
@ -79,7 +79,7 @@ test_expect_success 'moves and renames' '
echo "R100 foo bar"
echo "T100 foo"
} | sort >expect &&
diff -u expect actual
test_cmp expect actual
'

View file

@ -150,7 +150,7 @@ test_expect_success 'diff -U0' '
do
git diff -U0 file-?$n
done | zc >actual &&
diff -u expect actual
test_cmp expect actual
'

View file

@ -37,7 +37,7 @@ test_expect_success 'hunk header truncation with an overly long line' '
echo " A $N$N$N$N$N$N$N$N$N2"
echo " L $N$N$N$N$N$N$N$N$N1"
) >expected &&
diff -u actual expected
test_cmp actual expected
'

View file

@ -37,17 +37,17 @@ test_expect_success setup '
test_expect_success 'git diff --raw HEAD' '
git diff --raw --abbrev=40 HEAD >actual &&
diff -u expect actual
test_cmp expect actual
'
test_expect_success 'git diff-index --raw HEAD' '
git diff-index --raw HEAD >actual.index &&
diff -u expect actual.index
test_cmp expect actual.index
'
test_expect_success 'git diff-files --raw' '
git diff-files --raw >actual.files &&
diff -u expect actual.files
test_cmp expect actual.files
'
test_done

View file

@ -9,7 +9,7 @@ dotest () {
test_expect_success "$name" "
git checkout-index -f -q -u file &&
git apply $* &&
diff -u expect file
test_cmp expect file
"
}

View file

@ -56,7 +56,7 @@ test_expect_success nofix '
git apply --whitespace=nowarn patch-1 &&
# The result should obviously match.
diff -u file-1 file
test_cmp file-1 file
'
test_expect_success 'withfix (forward)' '
@ -70,7 +70,7 @@ test_expect_success 'withfix (forward)' '
git apply --whitespace=fix patch-0 &&
git apply --whitespace=fix patch-1 &&
diff -u file-fixed file
test_cmp file-fixed file
'
test_expect_success 'withfix (backward)' '
@ -91,12 +91,12 @@ test_expect_success 'withfix (backward)' '
sed -e /h/d file-fixed >fixed-head &&
sed -e /h/d file >file-head &&
diff -u fixed-head file-head &&
test_cmp fixed-head file-head &&
sed -n -e /h/p file-fixed >fixed-tail &&
sed -n -e /h/p file >file-tail &&
! diff -u fixed-tail file-tail
! test_cmp fixed-tail file-tail
'

View file

@ -22,14 +22,14 @@ test_expect_success 'am regularly from stdin' '
git checkout initial &&
git am <patchfile &&
git diff master >actual &&
diff -u expect actual
test_cmp expect actual
'
test_expect_success 'am regularly from file' '
git checkout initial &&
git am patchfile &&
git diff master >actual &&
diff -u expect actual
test_cmp expect actual
'
test_expect_success 'am regularly from stdin in subdirectory' '
@ -41,7 +41,7 @@ test_expect_success 'am regularly from stdin in subdirectory' '
git am <../patchfile
) &&
git diff master>actual &&
diff -u expect actual
test_cmp expect actual
'
test_expect_success 'am regularly from file in subdirectory' '
@ -53,7 +53,7 @@ test_expect_success 'am regularly from file in subdirectory' '
git am ../patchfile
) &&
git diff master >actual &&
diff -u expect actual
test_cmp expect actual
'
test_expect_success 'am regularly from file in subdirectory with full path' '
@ -66,7 +66,7 @@ test_expect_success 'am regularly from file in subdirectory with full path' '
git am "$P/patchfile"
) &&
git diff master >actual &&
diff -u expect actual
test_cmp expect actual
'
test_done

View file

@ -45,6 +45,6 @@ A U Thor (5):
EOF
test_expect_success 'shortlog wrapping' 'diff -u expect out'
test_expect_success 'shortlog wrapping' 'test_cmp expect out'
test_done

View file

@ -24,7 +24,7 @@ setup_repository () {
tokens_match () {
echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect &&
echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual &&
diff -u expect actual
test_cmp expect actual
}
check_remote_track () {
@ -73,7 +73,7 @@ test_expect_success 'add another remote' '
sed -e "/^refs\/remotes\/origin\//d" \
-e "/^refs\/remotes\/second\//d" >actual &&
>expect &&
diff -u expect actual
test_cmp expect actual
)
'
@ -93,7 +93,7 @@ test_expect_success 'remove remote' '
git for-each-ref "--format=%(refname)" refs/remotes |
sed -e "/^refs\/remotes\/origin\//d" >actual &&
>expect &&
diff -u expect actual
test_cmp expect actual
)
'

View file

@ -249,7 +249,7 @@ test_expect_success 'bundle should record HEAD correctly' '
do
echo "$(git rev-parse --verify $h) $h"
done >expect &&
diff -u expect actual
test_cmp expect actual
'

View file

@ -24,28 +24,28 @@ test_expect_success setup '
test_expect_success 'ls-remote --tags .git' '
git ls-remote --tags .git >actual &&
diff -u expected.tag actual
test_cmp expected.tag actual
'
test_expect_success 'ls-remote .git' '
git ls-remote .git >actual &&
diff -u expected.all actual
test_cmp expected.all actual
'
test_expect_success 'ls-remote --tags self' '
git ls-remote --tags self >actual &&
diff -u expected.tag actual
test_cmp expected.tag actual
'
test_expect_success 'ls-remote self' '
git ls-remote self >actual &&
diff -u expected.all actual
test_cmp expected.all actual
'

View file

@ -45,7 +45,7 @@ test_expect_success 'further setup' '
test_expect_success 'path optimization 2' '
( echo "$side"; echo "$initial" ) >expected &&
git rev-list HEAD -- a >actual &&
diff -u expected actual
test_cmp expected actual
'
test_done

View file

@ -31,7 +31,7 @@ test_expect_failure 'one is ancestor of others and should not be shown' '
git rev-list one --not four >result &&
>expect &&
diff -u expect result
test_cmp expect result
'

View file

@ -45,7 +45,7 @@ test_expect_success resolve '
false
else
git ls-files -s >current
diff -u current expect
test_cmp current expect
fi
'
@ -60,7 +60,7 @@ test_expect_success recursive '
false
else
git ls-files -s >current
diff -u current expect
test_cmp current expect
fi
'

View file

@ -25,7 +25,7 @@ test_expect_success 'subtree available and works like recursive' '
git merge -s subtree side &&
for i in mundo $s world; do echo $i; done >expect &&
diff -u expect hello
test_cmp expect hello
'

View file

@ -18,7 +18,7 @@ test_expect_success 'git add (absolute)' '
git add "$D/a/b/c/d" &&
git ls-files >current &&
echo a/b/c/d >expect &&
diff -u expect current
test_cmp expect current
'
@ -32,7 +32,7 @@ test_expect_success 'git add (funny relative)' '
) &&
git ls-files >current &&
echo a/e/f >expect &&
diff -u expect current
test_cmp expect current
'
@ -43,7 +43,7 @@ test_expect_success 'git rm (absolute)' '
git rm -f --cached "$D/a/b/c/d" &&
git ls-files >current &&
echo a/e/f >expect &&
diff -u expect current
test_cmp expect current
'
@ -57,7 +57,7 @@ test_expect_success 'git rm (funny relative)' '
) &&
git ls-files >current &&
echo a/b/c/d >expect &&
diff -u expect current
test_cmp expect current
'
@ -67,7 +67,7 @@ test_expect_success 'git ls-files (absolute)' '
git add a &&
git ls-files "$D/a/e/../b" >current &&
echo a/b/c/d >expect &&
diff -u expect current
test_cmp expect current
'
@ -80,7 +80,7 @@ test_expect_success 'git ls-files (relative #1)' '
git ls-files "../b/c"
) >current &&
echo c/d >expect &&
diff -u expect current
test_cmp expect current
'
@ -93,7 +93,7 @@ test_expect_success 'git ls-files (relative #2)' '
git ls-files --full-name "../e/f"
) >current &&
echo a/e/f >expect &&
diff -u expect current
test_cmp expect current
'
@ -126,13 +126,13 @@ test_expect_success 'log using absolute path names' '
git log a/b/c/d >f1.txt &&
git log "$(pwd)/a/b/c/d" >f2.txt &&
diff -u f1.txt f2.txt
test_cmp f1.txt f2.txt
'
test_expect_success 'blame using absolute path names' '
git blame a/b/c/d >f1.txt &&
git blame "$(pwd)/a/b/c/d" >f2.txt &&
diff -u f1.txt f2.txt
test_cmp f1.txt f2.txt
'
test_expect_success 'setup deeper work tree' '

View file

@ -83,13 +83,13 @@ test_expect_success "checkout with unrelated dirty tree without -m" '
fill 0 1 2 3 4 5 6 7 8 >same &&
cp same kept
git checkout side >messages &&
diff -u same kept
test_cmp same kept
(cat > messages.expect <<EOF
M same
EOF
) &&
touch messages.expect &&
diff -u messages.expect messages
test_cmp messages.expect messages
'
test_expect_success "checkout -m with dirty tree" '
@ -106,19 +106,19 @@ test_expect_success "checkout -m with dirty tree" '
M one
EOF
) &&
diff -u expect.messages messages &&
test_cmp expect.messages messages &&
fill "M one" "A three" "D two" >expect.master &&
git diff --name-status master >current.master &&
diff -u expect.master current.master &&
test_cmp expect.master current.master &&
fill "M one" >expect.side &&
git diff --name-status side >current.side &&
diff -u expect.side current.side &&
test_cmp expect.side current.side &&
: >expect.index &&
git diff --cached >current.index &&
diff -u expect.index current.index
test_cmp expect.index current.index
'
test_expect_success "checkout -m with dirty tree, renamed" '
@ -136,7 +136,7 @@ test_expect_success "checkout -m with dirty tree, renamed" '
git checkout -m renamer &&
fill 1 3 4 5 7 8 >expect &&
diff -u expect uno &&
test_cmp expect uno &&
! test -f one &&
git diff --cached >current &&
! test -s current
@ -161,7 +161,7 @@ test_expect_success 'checkout -m with merge conflict' '
git diff master:one :3:uno |
sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current &&
fill d2 aT d7 aS >expect &&
diff -u current expect &&
test_cmp current expect &&
git diff --cached two >current &&
! test -s current
'
@ -178,7 +178,7 @@ If you want to create a new branch from this checkout, you may do so
HEAD is now at 7329388... Initial A one, A two
EOF
) &&
diff -u messages.expect messages &&
test_cmp messages.expect messages &&
H=$(git rev-parse --verify HEAD) &&
M=$(git show-ref -s --verify refs/heads/master) &&
test "z$H" = "z$M" &&

View file

@ -203,7 +203,7 @@ test_expect_success 'sign off (1)' '
git var GIT_COMMITTER_IDENT |
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
) >expected &&
diff -u expected actual
test_cmp expected actual
'
@ -223,7 +223,7 @@ $existing" &&
git var GIT_COMMITTER_IDENT |
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
) >expected &&
diff -u expected actual
test_cmp expected actual
'
@ -240,7 +240,7 @@ test_expect_success 'multiple -m' '
echo
echo three
) >expected &&
diff -u expected actual
test_cmp expected actual
'
@ -301,12 +301,12 @@ test_expect_success 'same tree (merge and amend merge)' '
git merge -s ours side -m "empty ok" &&
git diff HEAD^ HEAD >actual &&
: >expected &&
diff -u expected actual &&
test_cmp expected actual &&
git commit --amend -m "empty really ok" &&
git diff HEAD^ HEAD >actual &&
: >expected &&
diff -u expected actual
test_cmp expected actual
'
@ -323,7 +323,7 @@ test_expect_success 'amend using the message from another commit' '
git commit --allow-empty --amend -C "$old" &&
git show --pretty="format:%ad %s" "$old" >expected &&
git show --pretty="format:%ad %s" HEAD >actual &&
diff -u expected actual
test_cmp expected actual
'
@ -341,7 +341,7 @@ test_expect_success 'amend using the message from a commit named with tag' '
git commit --allow-empty --amend -C tagged-old &&
git show --pretty="format:%ad %s" "$old" >expected &&
git show --pretty="format:%ad %s" HEAD >actual &&
diff -u expected actual
test_cmp expected actual
'

View file

@ -85,7 +85,7 @@ test_expect_success 'verbose' '
git add negative &&
git status -v | sed -ne "/^diff --git /p" >actual &&
echo "diff --git a/negative b/negative" >expect &&
diff -u expect actual
test_cmp expect actual
'
@ -95,7 +95,7 @@ test_expect_success 'cleanup commit messages (verbatim,-t)' '
{ echo;echo "# text";echo; } >expect &&
git commit --cleanup=verbatim -t expect -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual &&
diff -u expect actual
test_cmp expect actual
'
@ -104,7 +104,7 @@ test_expect_success 'cleanup commit messages (verbatim,-F)' '
echo >>negative &&
git commit --cleanup=verbatim -F expect -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
diff -u expect actual
test_cmp expect actual
'
@ -113,7 +113,7 @@ test_expect_success 'cleanup commit messages (verbatim,-m)' '
echo >>negative &&
git commit --cleanup=verbatim -m "$(cat expect)" -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
diff -u expect actual
test_cmp expect actual
'
@ -124,7 +124,7 @@ test_expect_success 'cleanup commit messages (whitespace,-F)' '
echo "# text" >expect &&
git commit --cleanup=whitespace -F text -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
diff -u expect actual
test_cmp expect actual
'
@ -135,7 +135,7 @@ test_expect_success 'cleanup commit messages (strip,-F)' '
echo sample >expect &&
git commit --cleanup=strip -F text -a &&
git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
diff -u expect actual
test_cmp expect actual
'
@ -150,7 +150,7 @@ test_expect_success 'cleanup commit messages (strip,-F,-e)' '
{ echo;echo sample;echo; } >text &&
git commit -e -F text -a &&
head -n 4 .git/COMMIT_EDITMSG >actual &&
diff -u expect actual
test_cmp expect actual
'

View file

@ -146,7 +146,7 @@ cat <<EOF >expect
EOF
test_expect_success 'status of partial commit excluding new file in index' '
git status dir1/modified >output &&
diff -u expect output
test_cmp expect output
'
test_done

View file

@ -108,7 +108,7 @@ create_merge_msgs() {
}
verify_diff() {
if ! diff -u "$1" "$2"
if ! test_cmp "$1" "$2"
then
echo "$3"
false

View file

@ -112,7 +112,7 @@ test_expect_success 'blame wholesale copy' '
echo mouse-Second
echo mouse-Third
} >expected &&
diff -u expected current
test_cmp expected current
'
@ -125,7 +125,7 @@ test_expect_success 'blame wholesale copy and more' '
echo cow-Fifth
echo mouse-Third
} >expected &&
diff -u expected current
test_cmp expected current
'

View file

@ -81,7 +81,7 @@ test_expect_success 'Show all headers' '
-e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
-e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
>actual-show-all-headers &&
diff -u expected-show-all-headers actual-show-all-headers
test_cmp expected-show-all-headers actual-show-all-headers
'
z8=zzzzzzzz

View file

@ -55,74 +55,74 @@ printf 'r1 \nr2 \nr4 \n' > expected-range-r1-r2-r4
test_expect_success 'test ascending revision range' "
git reset --hard trunk &&
git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r1-r2-r4 -
git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 -
"
printf 'r4 \nr2 \nr1 \n' > expected-range-r4-r2-r1
test_expect_success 'test descending revision range' "
git reset --hard trunk &&
git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4-r2-r1 -
git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4-r2-r1 -
"
printf 'r1 \nr2 \n' > expected-range-r1-r2
test_expect_success 'test ascending revision range with unreachable revision' "
git reset --hard trunk &&
git svn log -r 1:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r1-r2 -
git svn log -r 1:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2 -
"
printf 'r2 \nr1 \n' > expected-range-r2-r1
test_expect_success 'test descending revision range with unreachable revision' "
git reset --hard trunk &&
git svn log -r 3:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2-r1 -
git svn log -r 3:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2-r1 -
"
printf 'r2 \n' > expected-range-r2
test_expect_success 'test ascending revision range with unreachable upper boundary revision and 1 commit' "
git reset --hard trunk &&
git svn log -r 2:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2 -
git svn log -r 2:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 -
"
test_expect_success 'test descending revision range with unreachable upper boundary revision and 1 commit' "
git reset --hard trunk &&
git svn log -r 3:2 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2 -
git svn log -r 3:2 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 -
"
printf 'r4 \n' > expected-range-r4
test_expect_success 'test ascending revision range with unreachable lower boundary revision and 1 commit' "
git reset --hard trunk &&
git svn log -r 3:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 -
git svn log -r 3:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 -
"
test_expect_success 'test descending revision range with unreachable lower boundary revision and 1 commit' "
git reset --hard trunk &&
git svn log -r 4:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 -
git svn log -r 4:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 -
"
printf -- '------------------------------------------------------------------------\n' > expected-separator
test_expect_success 'test ascending revision range with unreachable boundary revisions and no commits' "
git reset --hard trunk &&
git svn log -r 5:6 | diff -u expected-separator -
git svn log -r 5:6 | test_cmp expected-separator -
"
test_expect_success 'test descending revision range with unreachable boundary revisions and no commits' "
git reset --hard trunk &&
git svn log -r 6:5 | diff -u expected-separator -
git svn log -r 6:5 | test_cmp expected-separator -
"
test_expect_success 'test ascending revision range with unreachable boundary revisions and 1 commit' "
git reset --hard trunk &&
git svn log -r 3:5 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 -
git svn log -r 3:5 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 -
"
test_expect_success 'test descending revision range with unreachable boundary revisions and 1 commit' "
git reset --hard trunk &&
git svn log -r 5:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 -
git svn log -r 5:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 -
"
test_done

View file

@ -37,7 +37,7 @@ check_entries () {
else
printf '%s\n' "$2" | tr '|' '\012' >expected
fi
diff -u expected actual
test_cmp expected actual
}
test_expect_success \
@ -257,8 +257,8 @@ test_expect_success '-w option should work with relative GIT_DIR' '
(cd "$GIT_DIR" &&
GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
diff -u "$CVSWORK/W/file1.txt" ../W/file1.txt &&
diff -u "$CVSWORK/W/file2.txt" ../W/file2.txt
test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
)
'
@ -279,9 +279,9 @@ test_expect_success 'check files before directories' '
git cvsexportcommit -w "$CVSWORK" -c $id &&
check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
diff -u "$CVSWORK/DS" DS &&
diff -u "$CVSWORK/E/DS" E/DS &&
diff -u "$CVSWORK/release-notes" release-notes
test_cmp "$CVSWORK/DS" DS &&
test_cmp "$CVSWORK/E/DS" E/DS &&
test_cmp "$CVSWORK/release-notes" release-notes
'
@ -293,7 +293,7 @@ test_expect_success 'commit a file with leading spaces in the name' '
id=$(git rev-parse HEAD) &&
git cvsexportcommit -w "$CVSWORK" -c $id &&
check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" &&
diff -u "$CVSWORK/ space" " space"
test_cmp "$CVSWORK/ space" " space"
'

View file

@ -42,6 +42,7 @@ export GIT_MERGE_VERBOSITY
export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
export EDITOR VISUAL
GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
# Protect ourselves from common misconfiguration to export
# CDPATH into the environment
@ -302,6 +303,23 @@ test_must_fail () {
test $? -gt 0 -a $? -le 128
}
# test_cmp is a helper function to compare actual and expected output.
# You can use it like:
#
# test_expect_success 'foo works' '
# echo expected >expected &&
# foo >actual &&
# test_cmp expected actual
# '
#
# This could be written as either "cmp" or "diff -u", but:
# - cmp's output is not nearly as easy to read as diff -u
# - not all diff versions understand "-u"
test_cmp() {
$GIT_TEST_CMP "$@"
}
# Most tests can use the created repository, but some may need to create more.
# Usage: test_create_repo <directory>
test_create_repo () {