From 4fdf71be1ca3a817851a14f91b75e7d30f885a48 Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Fri, 14 May 2010 09:31:37 +0000 Subject: tests: use "test_cmp", not "diff", when verifying the result In tests, call test_cmp rather than raw diff where possible (i.e. if the output does not go to a pipe), to allow the use of, say, 'cmp' when the default 'diff -u' is not compatible with a vendor diff. When that is not possible, use $DIFF, as set in GIT-BUILD-OPTIONS. Signed-off-by: Gary V. Vaughan Signed-off-by: Junio C Hamano --- t/Makefile | 4 ++++ t/t0000-basic.sh | 2 +- t/t3200-branch.sh | 4 ++-- t/t3210-pack-refs.sh | 8 ++++---- t/t3903-stash.sh | 2 +- t/t4002-diff-basic.sh | 2 +- t/t4124-apply-ws-rule.sh | 10 +++++----- t/t4127-apply-same-fn.sh | 6 +++--- t/t5300-pack-object.sh | 6 +++--- t/t5510-fetch.sh | 2 +- t/t5520-pull.sh | 2 +- t/t5700-clone-reference.sh | 8 ++++---- t/t6000lib.sh | 2 +- t/t6001-rev-list-graft.sh | 2 +- t/t6022-merge-rename.sh | 4 ++-- t/t7002-grep.sh | 16 ++++++++-------- t/t7005-editor.sh | 6 +++--- t/t9200-git-cvsexportcommit.sh | 26 +++++++++++++------------- t/t9400-git-cvsserver-server.sh | 2 +- 19 files changed, 59 insertions(+), 55 deletions(-) (limited to 't') diff --git a/t/Makefile b/t/Makefile index 25c559bb4..93a64750e 100644 --- a/t/Makefile +++ b/t/Makefile @@ -6,10 +6,14 @@ -include ../config.mak #GIT_TEST_OPTS=--verbose --debug +GIT_TEST_CMP ?= $(DIFF) SHELL_PATH ?= $(SHELL) TAR ?= $(TAR) RM ?= rm -f +# Make sure test-lib.sh uses make's value of GIT_TEST_CMP +export GIT_TEST_CMP + # Shell quote; SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index f4ca4fc85..5dd18c05a 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -280,7 +280,7 @@ $expectfilter >expected <<\EOF EOF test_expect_success \ 'validate git diff-files output for a know cache/work tree state.' \ - 'git diff-files >current && diff >/dev/null -b current expected' + 'git diff-files >current && test_cmp current expected >/dev/null' test_expect_success \ 'git update-index --refresh should succeed.' \ diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index e0b760513..8818d0de6 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -43,7 +43,7 @@ test_expect_success \ git branch -l d/e/f && test -f .git/refs/heads/d/e/f && test -f .git/logs/refs/heads/d/e/f && - diff expect .git/logs/refs/heads/d/e/f' + test_cmp expect .git/logs/refs/heads/d/e/f' test_expect_success \ 'git branch -d d/e/f should delete a branch and a log' \ @@ -222,7 +222,7 @@ test_expect_success \ git checkout -b g/h/i -l master && test -f .git/refs/heads/g/h/i && test -f .git/logs/refs/heads/g/h/i && - diff expect .git/logs/refs/heads/g/h/i' + test_cmp expect .git/logs/refs/heads/g/h/i' test_expect_success 'avoid ambiguous track' ' git config branch.autosetupmerge true && diff --git a/t/t3210-pack-refs.sh b/t/t3210-pack-refs.sh index 413019aca..525174013 100755 --- a/t/t3210-pack-refs.sh +++ b/t/t3210-pack-refs.sh @@ -28,7 +28,7 @@ test_expect_success \ SHA1=`cat .git/refs/heads/a` && echo "$SHA1 refs/heads/a" >expect && git show-ref a >result && - diff expect result' + test_cmp expect result' test_expect_success \ 'see if a branch still exists when packed' \ @@ -37,7 +37,7 @@ test_expect_success \ rm -f .git/refs/heads/b && echo "$SHA1 refs/heads/b" >expect && git show-ref b >result && - diff expect result' + test_cmp expect result' test_expect_success 'git branch c/d should barf if branch c exists' ' git branch c && @@ -52,7 +52,7 @@ test_expect_success \ git pack-refs --all --prune && echo "$SHA1 refs/heads/e" >expect && git show-ref e >result && - diff expect result' + test_cmp expect result' test_expect_success 'see if git pack-refs --prune remove ref files' ' git branch f && @@ -109,7 +109,7 @@ test_expect_success 'pack, prune and repack' ' git show-ref >all-of-them && git pack-refs && git show-ref >again && - diff all-of-them again + test_cmp all-of-them again ' test_done diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 476e5ec03..7e47030a1 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -81,7 +81,7 @@ test_expect_success 'drop top stash' ' git stash && git stash drop && git stash list > stashlist2 && - diff stashlist1 stashlist2 && + test_cmp stashlist1 stashlist2 && git stash apply && test 3 = $(cat file) && test 1 = $(git show :file) && diff --git a/t/t4002-diff-basic.sh b/t/t4002-diff-basic.sh index 18695ce82..73441a516 100755 --- a/t/t4002-diff-basic.sh +++ b/t/t4002-diff-basic.sh @@ -135,7 +135,7 @@ cmp_diff_files_output () { # filesystem. sed <"$2" >.test-tmp \ -e '/^:000000 /d;s/'$x40'\( [MCRNDU][0-9]*\) /'$z40'\1 /' && - diff "$1" .test-tmp + test_cmp "$1" .test-tmp } test_expect_success \ diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh index fb9ad247b..bef3bcb1b 100755 --- a/t/t4124-apply-ws-rule.sh +++ b/t/t4124-apply-ws-rule.sh @@ -44,7 +44,7 @@ test_fix () { apply_patch --whitespace=fix || return 1 # find touched lines - diff file target | sed -n -e "s/^> //p" >fixed + $DIFF file target | sed -n -e "s/^> //p" >fixed # the changed lines are all expeced to change fixed_cnt=$(wc -l .gitattributes && apply_patch --whitespace=error-all && - diff file target + test_cmp file target ' diff --git a/t/t4127-apply-same-fn.sh b/t/t4127-apply-same-fn.sh index 3a8202ea9..77200c0b2 100755 --- a/t/t4127-apply-same-fn.sh +++ b/t/t4127-apply-same-fn.sh @@ -27,7 +27,7 @@ test_expect_success 'apply same filename with independent changes' ' cp same_fn same_fn2 && git reset --hard && git apply patch0 && - diff same_fn same_fn2 + test_cmp same_fn same_fn2 ' test_expect_success 'apply same filename with overlapping changes' ' @@ -40,7 +40,7 @@ test_expect_success 'apply same filename with overlapping changes' ' cp same_fn same_fn2 && git reset --hard && git apply patch0 && - diff same_fn same_fn2 + test_cmp same_fn same_fn2 ' test_expect_success 'apply same new filename after rename' ' @@ -54,7 +54,7 @@ test_expect_success 'apply same new filename after rename' ' cp new_fn new_fn2 && git reset --hard && git apply --index patch1 && - diff new_fn new_fn2 + test_cmp new_fn new_fn2 ' test_expect_success 'apply same old filename after rename -- should fail.' ' diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 7649b810b..bbb9c1251 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -147,7 +147,7 @@ test_expect_success \ git cat-file $t $object || return 1 done current && - diff expect current' + test_cmp expect current' test_expect_success \ 'use packed deltified (REF_DELTA) objects' \ @@ -162,7 +162,7 @@ test_expect_success \ git cat-file $t $object || return 1 done current && - diff expect current' + test_cmp expect current' test_expect_success \ 'use packed deltified (OFS_DELTA) objects' \ @@ -177,7 +177,7 @@ test_expect_success \ git cat-file $t $object || return 1 done current && - diff expect current' + test_cmp expect current' unset GIT_OBJECT_DIRECTORY diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 721821ec9..4eb10f602 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -71,7 +71,7 @@ test_expect_success "fetch test for-merge" ' echo "$one_in_two " } >expected && cut -f -2 .git/FETCH_HEAD >actual && - diff expected actual' + test_cmp expected actual' test_expect_success 'fetch tags when there is no tags' ' diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index dd2ee842e..319e389ed 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -26,7 +26,7 @@ cd "$D" test_expect_success 'checking the results' ' test -f file && test -f cloned/file && - diff file cloned/file + test_cmp file cloned/file ' test_expect_success 'pulling into void using master:master' ' diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh index 1c1091606..895f5595a 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -48,7 +48,7 @@ test_expect_success 'that reference gets used' \ 'cd C && echo "0 objects, 0 kilobytes" > expected && git count-objects > current && -diff expected current' +test_cmp expected current' cd "$base_dir" @@ -75,7 +75,7 @@ cd "$base_dir" test_expect_success 'that reference gets used' \ 'cd D && echo "0 objects, 0 kilobytes" > expected && git count-objects > current && -diff expected current' +test_cmp expected current' cd "$base_dir" @@ -100,7 +100,7 @@ test_expect_success 'that alternate to origin gets used' \ 'cd C && echo "2 objects" > expected && git count-objects | cut -d, -f1 > current && -diff expected current' +test_cmp expected current' cd "$base_dir" @@ -116,7 +116,7 @@ test_expect_success 'check objects expected to exist locally' \ 'cd D && echo "5 objects" > expected && git count-objects | cut -d, -f1 > current && -diff expected current' +test_cmp expected current' cd "$base_dir" diff --git a/t/t6000lib.sh b/t/t6000lib.sh index 985d517a1..ea25dd89e 100644 --- a/t/t6000lib.sh +++ b/t/t6000lib.sh @@ -91,7 +91,7 @@ check_output() shift 1 if eval "$*" | entag > $_name.actual then - diff $_name.expected $_name.actual + test_cmp $_name.expected $_name.actual else return 1; fi diff --git a/t/t6001-rev-list-graft.sh b/t/t6001-rev-list-graft.sh index b2131cdac..fc57e7d3f 100755 --- a/t/t6001-rev-list-graft.sh +++ b/t/t6001-rev-list-graft.sh @@ -84,7 +84,7 @@ check () { git rev-list --parents --pretty=raw $arg | sed -n -e 's/^commit //p' >test.actual fi - diff test.expect test.actual + test_cmp test.expect test.actual } for type in basic parents parents-raw diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh index e3f7ae812..b66544b76 100755 --- a/t/t6022-merge-rename.sh +++ b/t/t6022-merge-rename.sh @@ -280,7 +280,7 @@ test_expect_success 'updated working tree file should prevent the merge' ' echo "BAD: should have complained" return 1 } - diff M M.saved || { + test_cmp M M.saved || { echo "BAD: should have left M intact" return 1 } @@ -301,7 +301,7 @@ test_expect_success 'updated working tree file should prevent the merge' ' echo "BAD: should have complained" return 1 } - diff M M.saved || { + test_cmp M M.saved || { echo "BAD: should have left M intact" return 1 } diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index e249c3ed4..8a6322765 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -60,7 +60,7 @@ do echo ${HC}file:5:foo_mmap bar mmap baz } >expected && git grep -n -w -e mmap $H >actual && - diff expected actual + test_cmp expected actual ' test_expect_success "grep -w $L (w)" ' @@ -74,7 +74,7 @@ do echo ${HC}x:1:x x xx x } >expected && git grep -n -w -e "x xx* x" $H >actual && - diff expected actual + test_cmp expected actual ' test_expect_success "grep -w $L (y-1)" ' @@ -82,7 +82,7 @@ do echo ${HC}y:1:y yy } >expected && git grep -n -w -e "^y" $H >actual && - diff expected actual + test_cmp expected actual ' test_expect_success "grep -w $L (y-2)" ' @@ -93,7 +93,7 @@ do cat actual false else - diff expected actual + test_cmp expected actual fi ' @@ -105,14 +105,14 @@ do cat actual false else - diff expected actual + test_cmp expected actual fi ' test_expect_success "grep $L (t-1)" ' echo "${HC}t/t:1:test" >expected && git grep -n -e test $H >actual && - diff expected actual + test_cmp expected actual ' test_expect_success "grep $L (t-2)" ' @@ -121,7 +121,7 @@ do cd t && git grep -n -e test $H ) >actual && - diff expected actual + test_cmp expected actual ' test_expect_success "grep $L (t-3)" ' @@ -130,7 +130,7 @@ do cd t && git grep --full-name -n -e test $H ) >actual && - diff expected actual + test_cmp expected actual ' test_expect_success "grep -c $L (no /dev/null)" ' diff --git a/t/t7005-editor.sh b/t/t7005-editor.sh index 5257f4d26..25b6d2e67 100755 --- a/t/t7005-editor.sh +++ b/t/t7005-editor.sh @@ -38,7 +38,7 @@ test_expect_success setup ' test_commit "$msg" && echo "$msg" >expect && git show -s --format=%s > actual && - diff actual expect + test_cmp actual expect ' @@ -85,7 +85,7 @@ do git --exec-path=. commit --amend && git show -s --pretty=oneline | sed -e "s/^[0-9a-f]* //" >actual && - diff actual expect + test_cmp actual expect ' done @@ -107,7 +107,7 @@ do git --exec-path=. commit --amend && git show -s --pretty=oneline | sed -e "s/^[0-9a-f]* //" >actual && - diff actual expect + test_cmp actual expect ' done diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh index fc3795dc9..61bcb8fc8 100755 --- a/t/t9200-git-cvsexportcommit.sh +++ b/t/t9200-git-cvsexportcommit.sh @@ -63,10 +63,10 @@ test_expect_success \ check_entries B "newfile2.txt/1.1/" && check_entries C "newfile3.png/1.1/-kb" && check_entries D "newfile4.png/1.1/-kb" && - diff A/newfile1.txt ../A/newfile1.txt && - diff B/newfile2.txt ../B/newfile2.txt && - diff C/newfile3.png ../C/newfile3.png && - diff D/newfile4.png ../D/newfile4.png + test_cmp A/newfile1.txt ../A/newfile1.txt && + test_cmp B/newfile2.txt ../B/newfile2.txt && + test_cmp C/newfile3.png ../C/newfile3.png && + test_cmp D/newfile4.png ../D/newfile4.png )' test_expect_success \ @@ -89,10 +89,10 @@ test_expect_success \ check_entries D "newfile4.png/1.2/-kb" && check_entries E "newfile5.txt/1.1/" && check_entries F "newfile6.png/1.1/-kb" && - diff A/newfile1.txt ../A/newfile1.txt && - diff D/newfile4.png ../D/newfile4.png && - diff E/newfile5.txt ../E/newfile5.txt && - diff F/newfile6.png ../F/newfile6.png + test_cmp A/newfile1.txt ../A/newfile1.txt && + test_cmp D/newfile4.png ../D/newfile4.png && + test_cmp E/newfile5.txt ../E/newfile5.txt && + test_cmp F/newfile6.png ../F/newfile6.png )' # Should fail (but only on the git cvsexportcommit stage) @@ -137,9 +137,9 @@ test_expect_success \ check_entries D "" && check_entries E "newfile5.txt/1.1/" && check_entries F "newfile6.png/1.1/-kb" && - diff A/newfile1.txt ../A/newfile1.txt && - diff E/newfile5.txt ../E/newfile5.txt && - diff F/newfile6.png ../F/newfile6.png + test_cmp A/newfile1.txt ../A/newfile1.txt && + test_cmp E/newfile5.txt ../E/newfile5.txt && + test_cmp F/newfile6.png ../F/newfile6.png )' test_expect_success \ @@ -155,8 +155,8 @@ test_expect_success \ check_entries D "" && check_entries E "newfile5.txt/1.1/" && check_entries F "newfile6.png/1.1/-kb" && - diff E/newfile5.txt ../E/newfile5.txt && - diff F/newfile6.png ../F/newfile6.png + test_cmp E/newfile5.txt ../E/newfile5.txt && + test_cmp F/newfile6.png ../F/newfile6.png )' test_expect_success \ diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index daef2d6c2..e4ee0782b 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -435,7 +435,7 @@ test_expect_success 'cvs update (-p)' ' rm -f failures && for i in merge no-lf empty really-empty; do GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out - diff $i.out ../$i >>failures 2>&1 + test_cmp $i.out ../$i >>failures 2>&1 done && test -z "$(cat failures)" ' -- cgit v1.2.1 From 7b3bdbb335b6be938b4748e86a41357e51c97804 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 31 May 2010 17:35:20 -0700 Subject: fixup: do not unconditionally disable "diff -u" Signed-off-by: Junio C Hamano --- t/Makefile | 4 ---- t/test-lib.sh | 11 ++++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 't') diff --git a/t/Makefile b/t/Makefile index 93a64750e..25c559bb4 100644 --- a/t/Makefile +++ b/t/Makefile @@ -6,14 +6,10 @@ -include ../config.mak #GIT_TEST_OPTS=--verbose --debug -GIT_TEST_CMP ?= $(DIFF) SHELL_PATH ?= $(SHELL) TAR ?= $(TAR) RM ?= rm -f -# Make sure test-lib.sh uses make's value of GIT_TEST_CMP -export GIT_TEST_CMP - # Shell quote; SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) diff --git a/t/test-lib.sh b/t/test-lib.sh index c582964b0..a290011fa 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -63,7 +63,16 @@ export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR -GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} + +if test -z "$GIT_TEST_CMP" +then + if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT" + then + GIT_TEST_CMP="$DIFF -c" + else + GIT_TEST_CMP="$DIFF -u" + fi +fi # Protect ourselves from common misconfiguration to export # CDPATH into the environment -- cgit v1.2.1 From b2b0026eede10894d3317920a277b2a579cd86c5 Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Fri, 14 May 2010 09:31:38 +0000 Subject: test_cmp: do not use "diff -u" on platforms that lack one By default the testsuite calls 'diff -u' whenever a file comparison is called for. Unfortunately that throws a "diff: unknown option '-u'" error for most non-GNU diffs. This patch sets GIT_TEST_CMP to 'cmp' on all the architectures where that happens. The previous version of this patch forgot to export GIT_TEST_CMP from t/Makefile, which is why 'make test' continued to fail most tests on most architectures - test-lib.sh was falling back on its default of `diff -u' for GIT_TEST_CMP. This version of this patch shows a vast improvement in testsuite results where either GNU diff is in the path at configure time, or where Makefile knows that GIT_TEST_CMP=cmp is required. Signed-off-by: Gary V. Vaughan Signed-off-by: Junio C Hamano --- t/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 't') diff --git a/t/Makefile b/t/Makefile index 25c559bb4..172948586 100644 --- a/t/Makefile +++ b/t/Makefile @@ -3,6 +3,7 @@ # Copyright (c) 2005 Junio C Hamano # +-include ../config.mak.autogen -include ../config.mak #GIT_TEST_OPTS=--verbose --debug -- cgit v1.2.1 From 5e87eae97df69a48a575fd79131e85067f9dbf13 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 11 Jun 2010 09:40:25 -0700 Subject: test-lib: use DIFF definition from GIT-BUILD-OPTIONS Otherwise running individual tests from t/ directory may lack the definition of $DIFF, $GIT_TEST_CMP and friends. Noticed and initial patch provided by Thomas Rast, alternative solution suggested by Brandon Casey, which this patch implements. Signed-off-by: Junio C Hamano Acked-by: Thomas Rast --- t/test-lib.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 't') diff --git a/t/test-lib.sh b/t/test-lib.sh index a290011fa..eafe14660 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -64,16 +64,6 @@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR -if test -z "$GIT_TEST_CMP" -then - if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT" - then - GIT_TEST_CMP="$DIFF -c" - else - GIT_TEST_CMP="$DIFF -u" - fi -fi - # Protect ourselves from common misconfiguration to export # CDPATH into the environment unset CDPATH @@ -691,6 +681,16 @@ export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOB . ../GIT-BUILD-OPTIONS +if test -z "$GIT_TEST_CMP" +then + if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT" + then + GIT_TEST_CMP="$DIFF -c" + else + GIT_TEST_CMP="$DIFF -u" + fi +fi + GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git export GITPERLLIB test -d ../templates/blt || { -- cgit v1.2.1