]> Savannah Git Hosting - gnulib/maint-tools.git/commitdiff
test-program: Add more feature tests to sh-features.
authorBruno Haible <bruno@clisp.org>
Mon, 1 Jul 2024 21:51:27 +0000 (23:51 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 1 Jul 2024 21:51:27 +0000 (23:51 +0200)
test-programs/sh-features

index f6dcdeb079cad212a02b62a4de6ed76a09e9fb06..ff7d4b6fa29c58da4fbec47a5e78a63f9673670c 100644 (file)
@@ -2,11 +2,68 @@
 # Usage: SHELL sh-features 2>/dev/null
 # You find the known results at the end of this script.
 
-echo '1 - $(...) syntax for command substitution'
-echo '2 - printf builtin supports octal escapes correctly'
-echo '3 - local variables with non-surprising semantics'
-echo '4 - sane tracing (set -x)'
-echo '5 - locally bound shell options'
+echo '1 - accepted by configure (generated by autoconf 2.72)'
+echo '2 - $(...) syntax for command substitution'
+echo '3 - ${var#...} syntax for removing a prefix'
+echo '4 - ${var%...} syntax for removing a suffix'
+echo '5 - printf builtin supports octal escapes correctly'
+echo '6 - local variables with non-surprising semantics'
+echo '7 - sane tracing (set -x)'
+echo '8 - locally bound shell options'
+echo '9 - append operator'
+echo '10 - associative arrays'
+
+as_bourne_compatible="if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
+then :
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '\${1+\"\$@\"}'='\"\$@\"'
+  setopt NO_GLOB_SUBST
+else case e in #(
+  e) case \`(set -o) 2>/dev/null\` in #(
+  *posix*) :
+    set -o posix ;; #(
+  *) :
+     ;;
+esac ;;
+esac
+fi
+"
+as_required="as_fn_return () { (exit \$1); }
+as_fn_success () { as_fn_return 0; }
+as_fn_failure () { as_fn_return 1; }
+as_fn_ret_success () { return 0; }
+as_fn_ret_failure () { return 1; }
+exitcode=0
+as_fn_success || { exitcode=1; echo as_fn_success failed.; }
+as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
+as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
+as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
+if ( set x; as_fn_ret_success y && test x = \"\$1\" )
+then :
+
+else case e in #(
+  e) exitcode=1; echo positional parameters were not saved. ;;
+esac
+fi
+test x\$exitcode = x0 || exit 1
+blah=\$(echo \$(echo blah))
+test x\"\$blah\" = xblah || exit 1
+test -x / || exit 1"
+as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
+  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
+  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
+  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
+test \$(( 1 + 1 )) = 2 || exit 1"
+if (eval "$as_required") 2>/dev/null
+then :
+  as_have_required=yes
+else case e in #(
+  e) as_have_required=no ;;
+esac
+fi
 
 if (eval 'test $(echo y) = y'); then
   posix_command_subst=yes
@@ -14,6 +71,18 @@ else
   posix_command_subst=no
 fi
 
+if ( foo=bar; eval 'test "${foo#b}" = ar' ) >/dev/null 2>&1; then
+  remove_prefix_works=yes
+else
+  remove_prefix_works=no
+fi
+
+if ( foo=bar; eval 'test "${foo%r}" = ba' ) >/dev/null 2>&1; then
+  remove_suffix_works=yes
+else
+  remove_suffix_works=no
+fi
+
 if { LC_ALL=en_US.UTF-8 printf "\\351" 2>/dev/null \
      | LC_ALL=C tr "\\351" x | LC_ALL=C grep "^x$" > /dev/null; } \
    && { printf "\\351" 2>/dev/null \
@@ -62,40 +131,57 @@ else
   locally_bound_options=no
 fi
 
-echo "1 2 3 4 5"
-echo "$posix_command_subst $printf_works $local_works $tracing_works $locally_bound_options" \
+if ( foo=bar; foo+=baz && test "$foo" = barbaz ) >/dev/null 2>&1; then
+  append_operator=yes
+else
+  append_operator=no
+fi
+
+if (declare -A x && { x[f/2]='foo'; x[f/3]='bar'; eval test '${x[f/2]}' = foo; }) 2>/dev/null; then
+  associative_arrays=yes
+else
+  associative_arrays=no
+fi
+
+echo "1 2 3 4 5 6 7 8 9 10"
+echo "$as_have_required $posix_command_subst $remove_prefix_works $remove_suffix_works $printf_works $local_works $tracing_works $locally_bound_options $append_operator $associative_arrays" \
   | sed -e 's/yes/Y/g' -e 's/no/-/g'
 
 exit 0
 
 ====================== Results ======================
-1 - $(...) syntax for command substitution
-2 - printf builtin supports octal escapes correctly
-3 - local variables with non-surprising semantics
-4 - sane tracing (set -x)
-5 - locally bound shell options
-
-                    1 2 3 4 5
-bash 1.14.7         Y Y Y Y -
-bash 2.05b          Y Y Y Y -
-bash 3.2.57         Y Y Y Y -
-bash 4.4.18         Y Y Y Y Y
-bash 5.2.21         Y Y Y Y Y
-dash 0.5.11         Y Y Y Y Y
-zsh 5.8.11          Y Y Y Y Y
-busybox sh          Y Y Y Y Y
-macOS 10.5 sh       Y Y Y Y -
-macOS 12 sh         Y Y Y Y -
-FreeBSD 5.2.1 sh    Y Y - Y Y
-FreeBSD 14.0 sh     Y Y Y Y Y
-NetBSD 10.0 sh      Y Y - Y Y
-OpenBSD 7.5 sh      Y Y Y - Y
-AIX 7.1 sh          Y ? Y - Y
-Solaris 10 sh       - Y - - -
-Solaris 11 sh       Y Y - - -
-
-
-Details for 5:
+1 - accepted by configure (generated by autoconf 2.72)
+2 - $(...) syntax for command substitution
+3 - ${var#...} syntax for removing a prefix
+4 - ${var%...} syntax for removing a suffix
+5 - printf builtin supports octal escapes correctly
+6 - local variables with non-surprising semantics
+7 - sane tracing (set -x)
+8 - locally bound shell options
+9 - append operator
+10 - associative arrays
+
+                    1 2 3 4 5 6 7 8 9 10
+bash 1.14.7         Y Y Y Y Y Y Y - - -
+bash 2.05b          Y Y Y Y Y Y Y - - -
+bash 3.2.57         Y Y Y Y Y Y Y - Y -
+bash 4.4.18         Y Y Y Y Y Y Y Y Y Y
+bash 5.2.21         Y Y Y Y Y Y Y Y Y Y
+dash 0.5.11         Y Y Y Y Y Y Y Y - -
+zsh 5.8.11          Y Y Y Y Y Y Y Y Y Y
+busybox sh          Y Y Y Y Y Y Y Y - -
+macOS 10.5 sh       Y Y Y Y Y Y Y - Y -
+macOS 12 sh         Y Y Y Y Y Y Y - Y -
+FreeBSD 5.2.1 sh    Y Y Y Y Y - Y Y - -
+FreeBSD 14.0 sh     Y Y Y Y Y Y Y Y - -
+NetBSD 10.0 sh      Y Y Y Y Y - Y Y - -
+OpenBSD 7.5 sh      Y Y Y Y Y Y - Y - -
+AIX 7.1 sh          Y Y Y Y ? Y - Y - -
+Solaris 10 sh       - - - - Y - - - - -
+Solaris 11 sh       Y Y Y Y Y - - - Y -
+
+
+Details for 8:
 
 bash 1.14.7, bash 2.05b, bash 3.2.57, macOS 10.5 sh, macOS 12 sh
 is_tracing_1=++ :