Skip to content

Commit cc663d1

Browse files
trastgitster
authored andcommitted
t4014: check for empty files from git format-patch --stdout
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]>
1 parent e7af8e4 commit cc663d1

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

t/t4014-format-patch.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,21 @@ test_expect_success 'configuration To: header' '
179179
grep "^To: R. E. Cipient <[email protected]>\$" patch9
180180
'
181181

182+
# check_patch <patch>: Verify that <patch> looks like a half-sane
183+
# patch email to avoid a false positive with !grep
184+
check_patch () {
185+
grep -e "^From:" "$1" &&
186+
grep -e "^Date:" "$1" &&
187+
grep -e "^Subject:" "$1"
188+
}
189+
182190
test_expect_success '--no-to overrides config.to' '
183191
184192
git config --replace-all format.to \
185193
"R. E. Cipient <[email protected]>" &&
186194
git format-patch --no-to --stdout master..side |
187195
sed -e "/^\$/q" >patch10 &&
196+
check_patch patch10 &&
188197
! grep "^To: R. E. Cipient <[email protected]>\$" patch10
189198
'
190199

@@ -195,6 +204,7 @@ test_expect_success '--no-to and --to replaces config.to' '
195204
git format-patch --no-to --to="Someone Else <[email protected]>" \
196205
--stdout master..side |
197206
sed -e "/^\$/q" >patch11 &&
207+
check_patch patch11 &&
198208
! grep "^To: Someone <[email protected]>\$" patch11 &&
199209
grep "^To: Someone Else <[email protected]>\$" patch11
200210
'
@@ -205,15 +215,17 @@ test_expect_success '--no-cc overrides config.cc' '
205215
"C. E. Cipient <[email protected]>" &&
206216
git format-patch --no-cc --stdout master..side |
207217
sed -e "/^\$/q" >patch12 &&
218+
check_patch patch12 &&
208219
! grep "^Cc: C. E. Cipient <[email protected]>\$" patch12
209220
'
210221

211-
test_expect_success '--no-add-headers overrides config.headers' '
222+
test_expect_failure '--no-add-headers overrides config.headers' '
212223
213224
git config --replace-all format.headers \
214225
"Header1: B. E. Cipient <[email protected]>" &&
215226
git format-patch --no-add-headers --stdout master..side |
216227
sed -e "/^\$/q" >patch13 &&
228+
check_patch patch13 &&
217229
! grep "^Header1: B. E. Cipient <[email protected]>\$" patch13
218230
'
219231

@@ -480,6 +492,7 @@ test_expect_success 'cover-letter inherits diff options' '
480492
git mv file foo &&
481493
git commit -m foo &&
482494
git format-patch --cover-letter -1 &&
495+
check_patch 0000-cover-letter.patch &&
483496
! grep "file => foo .* 0 *\$" 0000-cover-letter.patch &&
484497
git format-patch --cover-letter -1 -M &&
485498
grep "file => foo .* 0 *\$" 0000-cover-letter.patch
@@ -657,6 +670,7 @@ test_expect_success 'format-patch --no-signature ignores format.signature' '
657670
git config format.signature "config sig" &&
658671
git format-patch --stdout --signature="my sig" --no-signature \
659672
-1 >output &&
673+
check_patch output &&
660674
! grep "config sig" output &&
661675
! grep "my sig" output &&
662676
! grep "^-- \$" output
@@ -673,17 +687,20 @@ test_expect_success 'format-patch --signature --cover-letter' '
673687
test_expect_success 'format.signature="" supresses signatures' '
674688
git config format.signature "" &&
675689
git format-patch --stdout -1 >output &&
690+
check_patch output &&
676691
! grep "^-- \$" output
677692
'
678693

679694
test_expect_success 'format-patch --no-signature supresses signatures' '
680695
git config --unset-all format.signature &&
681696
git format-patch --stdout --no-signature -1 >output &&
697+
check_patch output &&
682698
! grep "^-- \$" output
683699
'
684700

685-
test_expect_success 'format-patch --signature="" supresses signatures' '
701+
test_expect_failure 'format-patch --signature="" supresses signatures' '
686702
git format-patch --signature="" -1 >output &&
703+
check_patch output &&
687704
! grep "^-- \$" output
688705
'
689706

0 commit comments

Comments
 (0)