Skip to content

Commit

Permalink
add test_cmp function for test scripts
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peff authored and gitster committed Mar 13, 2008
1 parent b4ce54f commit 82ebb0b
Show file tree
Hide file tree
Showing 40 changed files with 133 additions and 115 deletions.
2 changes: 1 addition & 1 deletion t/t0003-attributes.sh
Expand Up @@ -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

}

Expand Down
2 changes: 1 addition & 1 deletion t/t0022-crlf-rename.sh
Expand Up @@ -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
'

Expand Down
2 changes: 1 addition & 1 deletion t/t1005-read-tree-reset.sh
Expand Up @@ -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
2 changes: 1 addition & 1 deletion t/t2200-add-update.sh
Expand Up @@ -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
'

Expand Down
2 changes: 1 addition & 1 deletion t/t3001-ls-files-others-exclude.sh
Expand Up @@ -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)' '
Expand Down
4 changes: 2 additions & 2 deletions t/t3050-subprojects-fetch.sh
Expand Up @@ -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 '
Expand All @@ -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
2 changes: 1 addition & 1 deletion t/t3060-ls-files-with-tree.sh
Expand Up @@ -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
6 changes: 3 additions & 3 deletions t/t3201-branch-contains.sh
Expand Up @@ -31,7 +31,7 @@ test_expect_success 'branch --contains=master' '
{
echo " master" && echo "* side"
} >expect &&
diff -u expect actual
test_cmp expect actual
'

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

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

Expand Down
4 changes: 2 additions & 2 deletions t/t3404-rebase-interactive.sh
Expand Up @@ -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)
'
Expand Down
4 changes: 2 additions & 2 deletions t/t3405-rebase-malformed.sh
Expand Up @@ -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
2 changes: 1 addition & 1 deletion t/t3406-rebase-message.sh
Expand Up @@ -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
'

Expand Down
4 changes: 2 additions & 2 deletions t/t3701-add-interactive.sh
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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 &&
Expand Down
16 changes: 8 additions & 8 deletions t/t3902-quoted.sh
Expand Up @@ -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
'

Expand All @@ -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
'

Expand Down
2 changes: 1 addition & 1 deletion t/t3903-stash.sh
Expand Up @@ -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' '
Expand Down
6 changes: 3 additions & 3 deletions t/t4023-diff-rename-typechange.sh
Expand Up @@ -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
'

Expand All @@ -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
'

Expand All @@ -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
'

Expand Down
2 changes: 1 addition & 1 deletion t/t4024-diff-optimize-common.sh
Expand Up @@ -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
'

Expand Down
2 changes: 1 addition & 1 deletion t/t4025-hunk-header.sh
Expand Up @@ -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
'

Expand Down
6 changes: 3 additions & 3 deletions t/t4027-diff-submodule.sh
Expand Up @@ -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
2 changes: 1 addition & 1 deletion t/t4105-apply-fuzz.sh
Expand Up @@ -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
"
}

Expand Down
8 changes: 4 additions & 4 deletions t/t4125-apply-ws-fuzz.sh
Expand Up @@ -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)' '
Expand All @@ -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)' '
Expand All @@ -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
'

Expand Down
10 changes: 5 additions & 5 deletions t/t4150-am-subdir.sh
Expand Up @@ -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' '
Expand All @@ -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' '
Expand All @@ -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' '
Expand All @@ -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
2 changes: 1 addition & 1 deletion t/t4201-shortlog.sh
Expand Up @@ -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

0 comments on commit 82ebb0b

Please sign in to comment.