From 840c519d7e7ae4651a7b5a0954f7aa53eebc29b6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 4 Feb 2012 01:29:01 -0500 Subject: [PATCH 1/2] 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 Signed-off-by: Junio C Hamano --- t/test-lib.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/t/test-lib.sh b/t/test-lib.sh index a65dfc7ea93..a089a188641 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: # From 3d9f5b674fb53cc931e0f676f1599050bd69f696 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 4 Feb 2012 01:30:18 -0500 Subject: [PATCH 2/2] t0300: use write_script helper t0300 creates some helper shell scripts, and marks them with "!/bin/sh". Even though the scripts are fairly simple, they can fail on broken shells (specifically, Solaris /bin/sh will persist a temporary assignment to IFS in a "read" command). Rather than work around the problem for Solaris /bin/sh, using write_script will make sure we point to a known-good shell that the user has given us. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t0300-credentials.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh index 885af8fb62a..8621ab036f9 100755 --- a/t/t0300-credentials.sh +++ b/t/t0300-credentials.sh @@ -14,22 +14,18 @@ test_expect_success 'setup helper scripts' ' done EOF - cat >git-credential-useless <<-\EOF && - #!/bin/sh + write_script git-credential-useless <<-\EOF && . ./dump exit 0 EOF - chmod +x git-credential-useless && - cat >git-credential-verbatim <<-\EOF && - #!/bin/sh + write_script git-credential-verbatim <<-\EOF && user=$1; shift pass=$1; shift . ./dump test -z "$user" || echo username=$user test -z "$pass" || echo password=$pass EOF - chmod +x git-credential-verbatim && PATH="$PWD:$PATH" '