summaryrefslogtreecommitdiff
path: root/t/test-lib.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-02-04 06:29:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-02-04 07:01:07 (GMT)
commit840c519d7e7ae4651a7b5a0954f7aa53eebc29b6 (patch)
treedac8be1023f6930cb6166d43d6fa5626a6314d41 /t/test-lib.sh
parent828ea97de486c1693d6e4f2c7347acb50235a85d (diff)
downloadgit-840c519d7e7ae4651a7b5a0954f7aa53eebc29b6.zip
git-840c519d7e7ae4651a7b5a0954f7aa53eebc29b6.tar.gz
git-840c519d7e7ae4651a7b5a0954f7aa53eebc29b6.tar.bz2
tests: add write_script helper function
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/test-lib.sh')
-rw-r--r--t/test-lib.sh9
1 files changed, 9 insertions, 0 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh
index a65dfc7..a089a18 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -381,11 +381,20 @@ test_config () {
git config "$@"
}
+
test_config_global () {
test_when_finished "test_unconfig --global '$1'" &&
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:
#