From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Ben Walton <bwalton@artsci.utoronto.ca>, git@vger.kernel.org
Subject: [PATCH 1/2] tests: add write_script helper function
Date: Sat, 4 Feb 2012 01:29:01 -0500 [thread overview]
Message-ID: <20120204062901.GA21559@sigill.intra.peff.net> (raw)
In-Reply-To: <20120204062712.GA20076@sigill.intra.peff.net>
From: Junio C Hamano <gitster@pobox.com>
Many of the scripts in the test suite write small helper
shell scripts to disk. It's best if these shell scripts
start with "#!$SHELL_PATH" rather than "#!/bin/sh", because
/bin/sh on some platforms is too buggy to be used.
However, it can be cumbersome to expand $SHELL_PATH, because
the usual recipe for writing a script is:
cat >foo.sh <<-\EOF
#!/bin/sh
echo my arguments are "$@"
EOF
To expand $SHELL_PATH, you have to either interpolate the
here-doc (which would require quoting "\$@"), or split the
creation into two commands (interpolating the $SHELL_PATH
line, but not the rest of the script). Let's provide a
helper function that makes that less syntactically painful.
While we're at it, this helper can also take care of the
"chmod +x" that typically comes after the creation of such a
script, saving the caller a line.
Signed-off-by: Jeff King <peff@peff.net>
---
I suspect you already have this in your repo, but maybe the commit
message is useful.
t/test-lib.sh | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index b22bee7..254849e 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -400,6 +400,14 @@ test_config_global () {
git config --global "$@"
}
+write_script () {
+ {
+ echo "#!${2-"$SHELL_PATH"}" &&
+ cat
+ } >"$1" &&
+ chmod +x "$1"
+}
+
# Use test_set_prereq to tell that a particular prerequisite is available.
# The prerequisite can later be checked for in two ways:
#
--
1.7.9.rc1.28.gf4be5
next prev parent reply other threads:[~2012-02-04 6:29 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-02 19:32 [PATCH] t0300-credentials: Word around a solaris /bin/sh bug Ben Walton
2012-02-02 19:44 ` Frans Klaver
2012-02-02 19:48 ` Ben Walton
2012-02-02 20:02 ` Jeff King
2012-02-03 1:02 ` Junio C Hamano
2012-02-03 12:06 ` Jeff King
2012-02-03 13:45 ` Ben Walton
2012-02-03 20:32 ` Junio C Hamano
2012-02-03 21:26 ` Jeff King
2012-02-03 21:50 ` Junio C Hamano
2012-02-03 21:55 ` Jeff King
2012-02-03 22:00 ` Ben Walton
2012-02-03 22:45 ` Junio C Hamano
2012-02-03 23:27 ` Jeff King
2012-02-04 6:27 ` Jeff King
2012-02-04 6:29 ` Jeff King [this message]
2012-02-04 6:30 ` [PATCH 2/2] t0300: use write_script helper Jeff King
2012-02-04 6:58 ` Junio C Hamano
2012-02-04 7:00 ` Jeff King
2012-02-02 20:16 ` [PATCH] t0300-credentials: Word around a solaris /bin/sh bug Jonathan Nieder
2012-02-02 20:43 ` Matthieu Moy
2012-02-02 21:11 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120204062901.GA21559@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=bwalton@artsci.utoronto.ca \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
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 NNTP newsgroup(s).