From: Jonathan Nieder <jrnieder@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Guido Günther" <agx@sigxcpu.org>,
"Giuseppe Iuculano" <iuculano@debian.org>
Subject: [PATCH 2/3] tests: Test how well "git apply" copes with weird filenames
Date: Fri, 23 Jul 2010 20:11:14 -0500 [thread overview]
Message-ID: <20100724011114.GC13670@burratino> (raw)
In-Reply-To: <20100724010618.GA13670@burratino>
The tests assume a reasonably well-behaved “diff -u” and “pr”
to produce the (possibly whitespace-damaged) patches. On platforms
without those commands, skip the tests.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/t4135-apply-weird-filenames.sh | 119 ++++++++++++++++++++++++++++++++++++++
1 files changed, 119 insertions(+), 0 deletions(-)
create mode 100755 t/t4135-apply-weird-filenames.sh
diff --git a/t/t4135-apply-weird-filenames.sh b/t/t4135-apply-weird-filenames.sh
new file mode 100755
index 0000000..2dcb040
--- /dev/null
+++ b/t/t4135-apply-weird-filenames.sh
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+test_description='git apply with weird postimage filenames'
+
+. ./test-lib.sh
+
+test_expect_success 'setup: empty commit' '
+ test_tick &&
+ git commit --allow-empty -m preimage &&
+ git tag preimage
+'
+
+test_expect_success 'setup: clean-up functions' '
+ reset_preimage() {
+ git checkout -f preimage^0 &&
+ git read-tree -u --reset HEAD &&
+ git update-index --refresh
+ } &&
+
+ reset_subdirs() {
+ rm -fr a b &&
+ mkdir a b
+ }
+'
+
+test_expect_success 'setup: test prerequisites' '
+ echo one >1 &&
+ echo one >2 &&
+ if diff -u 1 2
+ then
+ test_set_prereq UNIDIFF
+ fi &&
+
+ if diff -pruN 1 2
+ then
+ test_set_prereq FULLDIFF
+ fi &&
+
+ echo "tab -> ." >expected &&
+ echo "tab -> ." >with-tab &&
+
+ pr -tT -e8 with-tab >actual &&
+ if test_cmp expected actual
+ then
+ test_set_prereq PR
+ fi
+'
+
+try_filename() {
+ desc=$1
+ postimage=$2
+ exp1=${3:-success}
+ exp2=${4:-success}
+ exp3=${5:-success}
+
+ test_expect_$exp1 "$desc, git-style file creation patch" "
+ reset_preimage &&
+ echo postimage >'$postimage' &&
+ git add -N '$postimage' &&
+ git diff HEAD >'git-$desc.diff' &&
+
+ git rm -f --cached '$postimage' &&
+ mv '$postimage' postimage.saved &&
+ git apply -v 'git-$desc.diff' &&
+
+ test_cmp postimage.saved '$postimage'
+ "
+
+ test_expect_$exp2 UNIDIFF "$desc, traditional patch" "
+ reset_preimage &&
+ echo preimage >'$postimage.orig' &&
+ echo postimage >'$postimage' &&
+ ! diff -u '$postimage.orig' '$postimage' >'diff-$desc.diff' &&
+
+ mv '$postimage' postimage.saved &&
+ mv '$postimage.orig' '$postimage' &&
+ git apply -v 'diff-$desc.diff' &&
+
+ test_cmp postimage.saved '$postimage'
+ "
+
+ test_expect_$exp3 FULLDIFF "$desc, traditional file creation patch" "
+ reset_preimage &&
+ reset_subdirs &&
+ echo postimage >b/'$postimage' &&
+ ! diff -pruN a b >'add-$desc.diff' &&
+
+ rm -f '$postimage' &&
+ mv b/'$postimage' postimage.saved &&
+ git apply -v 'add-$desc.diff' &&
+
+ test_cmp postimage.saved '$postimage'
+ "
+}
+
+try_filename 'plain' 'postimage.txt'
+try_filename 'with spaces' 'post image.txt' success failure failure
+try_filename 'with tab' 'post image.txt' success failure failure
+try_filename 'with backslash' 'post\image.txt'
+try_filename 'with quote' '"postimage".txt' success failure success
+
+if test_have_prereq FULLDIFF && test_have_prereq PR
+then
+ test_set_prereq FULLDIFFPR
+fi
+test_expect_success FULLDIFFPR 'whitespace-damaged traditional patch' '
+ reset_preimage &&
+ reset_subdirs &&
+ echo postimage >b/postimage.txt &&
+ ! diff -pruN a b >diff-plain.txt &&
+ pr -tT -e8 diff-plain.txt >damaged.diff &&
+
+ mv postimage.txt postimage.saved &&
+ git apply -v damaged.diff &&
+
+ test_cmp postimage.saved postimage.txt
+'
+
+test_done
--
1.7.2.rc3
next prev parent reply other threads:[~2010-07-24 1:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-24 1:06 [PATCH 0/3] apply: handle traditional patches with spaces in filename Jonathan Nieder
2010-07-24 1:09 ` [PATCH 1/3] apply: Split quoted filename handling into new function Jonathan Nieder
2010-07-24 1:11 ` Jonathan Nieder [this message]
2010-07-24 8:03 ` [PATCH 2/3] tests: Test how well "git apply" copes with weird filenames Andreas Schwab
2010-07-24 8:48 ` Jonathan Nieder
2010-07-24 1:20 ` [PATCH 3/3] apply: Handle traditional patches with space in filename Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100724011114.GC13670@burratino \
--to=jrnieder@gmail.com \
--cc=agx@sigxcpu.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=iuculano@debian.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).