Skip to content

Commit

Permalink
t4014: check for empty files from git format-patch --stdout
Browse files Browse the repository at this point in the history
Most kinds of failure in 'git format-patch --stdout >output' will
result in an empty 'output'.  This slips past checks that only verify
absence of output, such as the '! grep ...' that are quite prevalent
in t4014.

Introduce a helper check_patch() that checks that at least From, Date
and Subject are present, thus making sure it looks vaguely like a
patch (or cover letter) email.  Then insert calls to it in all tests
that do have positive checks for content.

This makes two of the tests fail.  Mark them as such; they'll be
fixed in a moment.

Signed-off-by: Thomas Rast <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
trast authored and gitster committed Aug 29, 2011
1 parent e7af8e4 commit cc663d1
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions t/t4014-format-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,21 @@ test_expect_success 'configuration To: header' '
grep "^To: R. E. Cipient <[email protected]>\$" patch9
'

# check_patch <patch>: Verify that <patch> looks like a half-sane
# patch email to avoid a false positive with !grep
check_patch () {
grep -e "^From:" "$1" &&
grep -e "^Date:" "$1" &&
grep -e "^Subject:" "$1"
}

test_expect_success '--no-to overrides config.to' '
git config --replace-all format.to \
"R. E. Cipient <[email protected]>" &&
git format-patch --no-to --stdout master..side |
sed -e "/^\$/q" >patch10 &&
check_patch patch10 &&
! grep "^To: R. E. Cipient <[email protected]>\$" patch10
'

Expand All @@ -195,6 +204,7 @@ test_expect_success '--no-to and --to replaces config.to' '
git format-patch --no-to --to="Someone Else <[email protected]>" \
--stdout master..side |
sed -e "/^\$/q" >patch11 &&
check_patch patch11 &&
! grep "^To: Someone <[email protected]>\$" patch11 &&
grep "^To: Someone Else <[email protected]>\$" patch11
'
Expand All @@ -205,15 +215,17 @@ test_expect_success '--no-cc overrides config.cc' '
"C. E. Cipient <[email protected]>" &&
git format-patch --no-cc --stdout master..side |
sed -e "/^\$/q" >patch12 &&
check_patch patch12 &&
! grep "^Cc: C. E. Cipient <[email protected]>\$" patch12
'

test_expect_success '--no-add-headers overrides config.headers' '
test_expect_failure '--no-add-headers overrides config.headers' '
git config --replace-all format.headers \
"Header1: B. E. Cipient <[email protected]>" &&
git format-patch --no-add-headers --stdout master..side |
sed -e "/^\$/q" >patch13 &&
check_patch patch13 &&
! grep "^Header1: B. E. Cipient <[email protected]>\$" patch13
'

Expand Down Expand Up @@ -480,6 +492,7 @@ test_expect_success 'cover-letter inherits diff options' '
git mv file foo &&
git commit -m foo &&
git format-patch --cover-letter -1 &&
check_patch 0000-cover-letter.patch &&
! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
git format-patch --cover-letter -1 -M &&
grep "file => foo .* 0 *\$" 0000-cover-letter.patch
Expand Down Expand Up @@ -657,6 +670,7 @@ test_expect_success 'format-patch --no-signature ignores format.signature' '
git config format.signature "config sig" &&
git format-patch --stdout --signature="my sig" --no-signature \
-1 >output &&
check_patch output &&
! grep "config sig" output &&
! grep "my sig" output &&
! grep "^-- \$" output
Expand All @@ -673,17 +687,20 @@ test_expect_success 'format-patch --signature --cover-letter' '
test_expect_success 'format.signature="" supresses signatures' '
git config format.signature "" &&
git format-patch --stdout -1 >output &&
check_patch output &&
! grep "^-- \$" output
'

test_expect_success 'format-patch --no-signature supresses signatures' '
git config --unset-all format.signature &&
git format-patch --stdout --no-signature -1 >output &&
check_patch output &&
! grep "^-- \$" output
'

test_expect_success 'format-patch --signature="" supresses signatures' '
test_expect_failure 'format-patch --signature="" supresses signatures' '
git format-patch --signature="" -1 >output &&
check_patch output &&
! grep "^-- \$" output
'

Expand Down

0 comments on commit cc663d1

Please sign in to comment.