On 24/06/18 23:49, Pádraig Brady wrote:
> I see a false failure in the new tests/misc/env-S-script.sh
> which is due to overflowing the shebang length limit
> depending on where one runs the test from.
> The limit on Linux is only 127 it seems :/
> https://www.in-ulm.de/~mascheck/various/shebang/#length
> 
> I'll come up with a way to skip the test if some sentinel
> value isn't passed through.

So rather than relying on shebangs that have various limitations,
the attached uses a wrapper script like:

cat <<\EOF > shebang
#!/bin/sh
# Execute a script as per 3 argument shebang
# but without length limits (127 on Linux for example).
script="$1"; shift
shebang=$(sed -n 's/^#!//p;q' < "$script")
interp=$(printf '%s' "$shebang" | cut -d' ' -f1)
rest=$(printf '%s' "$shebang" | cut -s -d' ' -f2-)
test "$rest" && exec "$interp" "$rest" "$script" "$@"
exec "$interp" "$script" "$@"
EOF
chmod a+x shebang


Which you then use like:

./shebang ./env1 ...


However I'm not convinced we're testing anything more
than what's in env-S.pl here?
I.E. we're not actually relying on shebang processing
as it's too inconsistent.

So I'm inclined to just remove the test?

cheers,
Pádraig
From b900ffef0929889b48f12da86385730fa0554051 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Tue, 26 Jun 2018 00:39:48 -0700
Subject: [PATCH] tests: fix false failure with limited shebang lines

* tests/misc/env-S-script.sh: Provide a wrapper to
emulate shebang processing, but without length limits,
which are 127 on Linux for example.
---
 tests/misc/env-S-script.sh | 39 +++++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/tests/misc/env-S-script.sh b/tests/misc/env-S-script.sh
index d164be5..e09996c 100755
--- a/tests/misc/env-S-script.sh
+++ b/tests/misc/env-S-script.sh
@@ -20,28 +20,31 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ env
 print_ver_ printf
+require_perl_
 
 # a shortcut to avoid long lines
 dir="$abs_top_builddir/src"
 
+cat <<\EOF > shebang || framework_failure_
+#!/bin/sh
+# Execute a script as per 3 argument shebang
+# but without length limits (127 on Linux for example).
+script="$1"; shift
+shebang=$(sed -n 's/^#!//p;q' < "$script")
+interp=$(printf '%s' "$shebang" | cut -d' ' -f1)
+rest=$(printf '%s' "$shebang" | cut -s -d' ' -f2-)
+test "$rest" && exec "$interp" "$rest" "$script" "$@"
+exec "$interp" "$script" "$@"
+EOF
+chmod a+x shebang || framework_failure_
+
 # A simple shebang program to call our new "env"
 printf "#!$dir/env sh\necho hello\n" > env_test || framework_failure_
 chmod a+x env_test || framework_failure_
 
 # Verify we can run the shebang which is not the case if
 # there are spaces in $abs_top_builddir.
-./env_test || skip_ "Error running env_test script"
-
-
-# This script (without -S) should not work if the OS does not
-# support multiple arguments on the shebang line.
-# Ignoring the absolute paths, the script is:
-#     #!env printf x%sx\n A B
-printf "#!$dir/env $dir/printf "'x%%sx\\n A B\n' > env_bad ||
-  framework_failure_
-chmod a+x env_bad || framework_failure_
-returns_ 127 ./env_bad ||
-  warn_ 'Note: OS natively accepts multiple arguments on shebang line'
+./shebang ./env_test || skip_ "Error running env_test script"
 
 # env should execute 'printf' with 7 parameters:
 # 'x%sx\n', 'A', 'B' from the "-S" argument,
@@ -58,7 +61,7 @@ xCx
 xDx
 xE Fx
 EOF
-./env1 C D "E F" > out1 || fail=1
+./shebang ./env1 C D "E F" > out1 || fail=1
 compare exp1 out1 || fail=1
 
 
@@ -73,7 +76,7 @@ cat<<\EOF>exp2 || framework_failure_
 xA Bx
 x./env2x
 EOF
-./env2 > out2 || fail=1
+./shebang ./env2 > out2 || fail=1
 compare exp2 out2 || fail=1
 
 
@@ -88,7 +91,7 @@ xYx
 x./env3x
 xWx
 EOF
-./env3 W > out3 || fail=1
+./shebang ./env3 W > out3 || fail=1
 compare exp3 out3 || fail=1
 
 
@@ -104,7 +107,7 @@ xA#Bx
 x./env4x
 xZx
 EOF
-./env4 Z > out4 || fail=1
+./shebang ./env4 Z > out4 || fail=1
 compare exp4 out4 || fail=1
 
 
@@ -119,7 +122,7 @@ chmod a+x env5 || framework_failure_
 cat<<\EOF>exp5 || framework_failure_
 hello
 EOF
-./env5 > out5 || fail=1
+./shebang ./env5 > out5 || fail=1
 compare exp5 out5 || fail=1
 
 
@@ -134,7 +137,7 @@ compare exp5 out5 || fail=1
 chmod a+x env6 || framework_failure_
 # Note: the perl script does not output a newline.
 printf "env6" > exp6 || framework_failure_
-./env6 > out6 || fail=1
+./shebang ./env6 > out6 || fail=1
 compare exp6 out6 || fail=1
 
 
-- 
2.9.3

Reply via email to