Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Mar 2010 19:34:57 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r205800 - in stable/8/tools/regression/bin/sh: builtins errors expansion parser
Message-ID:  <201003281934.o2SJYvSq022890@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sun Mar 28 19:34:57 2010
New Revision: 205800
URL: http://svn.freebsd.org/changeset/base/205800

Log:
  MFC r196607,r198453,r204016,r204017,r204836,r204842,r205105,r205153
  Various testcases that work correctly with stable/8 sh.
  
  Note: this creates some gaps in the numbering due to lower-numbered tests
  for new functionality which is not or not yet MFC'ed.

Added:
  stable/8/tools/regression/bin/sh/builtins/eval3.0
     - copied unchanged from r196607, head/tools/regression/bin/sh/builtins/eval3.0
  stable/8/tools/regression/bin/sh/errors/redirection-error5.0
     - copied unchanged from r205153, head/tools/regression/bin/sh/errors/redirection-error5.0
  stable/8/tools/regression/bin/sh/expansion/arith3.0
     - copied unchanged from r204017, head/tools/regression/bin/sh/expansion/arith3.0
  stable/8/tools/regression/bin/sh/expansion/assign1.0
     - copied unchanged from r204842, head/tools/regression/bin/sh/expansion/assign1.0
  stable/8/tools/regression/bin/sh/expansion/cmdsubst2.0
     - copied unchanged from r205105, head/tools/regression/bin/sh/expansion/cmdsubst2.0
  stable/8/tools/regression/bin/sh/expansion/plus-minus1.0
     - copied unchanged from r204842, head/tools/regression/bin/sh/expansion/plus-minus1.0
  stable/8/tools/regression/bin/sh/expansion/question1.0
     - copied unchanged from r198453, head/tools/regression/bin/sh/expansion/question1.0
  stable/8/tools/regression/bin/sh/expansion/set-u1.0
     - copied unchanged from r198453, head/tools/regression/bin/sh/expansion/set-u1.0
  stable/8/tools/regression/bin/sh/parser/heredoc1.0
     - copied unchanged from r204836, head/tools/regression/bin/sh/parser/heredoc1.0
Modified:
  stable/8/tools/regression/bin/sh/expansion/arith2.0
Directory Properties:
  stable/8/tools/regression/bin/sh/   (props changed)

Copied: stable/8/tools/regression/bin/sh/builtins/eval3.0 (from r196607, head/tools/regression/bin/sh/builtins/eval3.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/builtins/eval3.0	Sun Mar 28 19:34:57 2010	(r205800, copy of r196607, head/tools/regression/bin/sh/builtins/eval3.0)
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+eval 'false;' && exit 1
+eval 'true;' || exit 1
+eval 'false;
+' && exit 1
+eval 'true;
+' || exit 1
+exit 0

Copied: stable/8/tools/regression/bin/sh/errors/redirection-error5.0 (from r205153, head/tools/regression/bin/sh/errors/redirection-error5.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/errors/redirection-error5.0	Sun Mar 28 19:34:57 2010	(r205800, copy of r205153, head/tools/regression/bin/sh/errors/redirection-error5.0)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+# A redirection error on a subshell should not abort the shell.
+exec 2>/dev/null
+( echo bad ) </var/empty/x
+exit 0

Modified: stable/8/tools/regression/bin/sh/expansion/arith2.0
==============================================================================
--- stable/8/tools/regression/bin/sh/expansion/arith2.0	Sun Mar 28 18:46:01 2010	(r205799)
+++ stable/8/tools/regression/bin/sh/expansion/arith2.0	Sun Mar 28 19:34:57 2010	(r205800)
@@ -22,6 +22,7 @@ check "4611686018427387904" 461168601842
 check "0x4000000000000000" 4611686018427387904
 check "0400000000000000000000" 4611686018427387904
 check "0x4Ab0000000000000" 5381801554707742720
+check "010" 8
 
 # try out all operators
 v=42

Copied: stable/8/tools/regression/bin/sh/expansion/arith3.0 (from r204017, head/tools/regression/bin/sh/expansion/arith3.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/arith3.0	Sun Mar 28 19:34:57 2010	(r205800, copy of r204017, head/tools/regression/bin/sh/expansion/arith3.0)
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+	if [ $(($1)) != $2 ]; then
+		failures=$((failures+1))
+		echo "For $1, expected $2 actual $(($1))"
+	fi
+}
+
+check "1 << 1 + 1 | 1" 5
+
+exit $((failures != 0))

Copied: stable/8/tools/regression/bin/sh/expansion/assign1.0 (from r204842, head/tools/regression/bin/sh/expansion/assign1.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/assign1.0	Sun Mar 28 19:34:57 2010	(r205800, copy of r204842, head/tools/regression/bin/sh/expansion/assign1.0)
@@ -0,0 +1,37 @@
+# $FreeBSD$
+
+e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
+h='##'
+failures=''
+ok=''
+
+testcase() {
+	code="$1"
+	expected="$2"
+	oIFS="$IFS"
+	eval "$code"
+	IFS='|'
+	result="$#|$*"
+	IFS="$oIFS"
+	if [ "x$result" = "x$expected" ]; then
+		ok=x$ok
+	else
+		failures=x$failures
+		echo "For $code, expected $expected actual $result"
+	fi
+}
+
+testcase 'v=; set -- ${v=a b} $v'		'0|'
+testcase 'unset v; set -- ${v=a b} $v'		'4|a|b|a|b'
+testcase 'v=; set -- ${v:=a b} $v'		'4|a|b|a|b'
+testcase 'v=; set -- "${v:=a b}" "$v"'		'2|a b|a b'
+# expect sensible behaviour, although it disagrees with POSIX
+testcase 'v=; set -- ${v:=a\ b} $v'		'4|a|b|a|b'
+testcase 'v=; set -- ${v:=$p} $v'		'2|/etc/|/etc/'
+testcase 'v=; set -- "${v:=$p}" "$v"'		'2|/et[c]/|/et[c]/'
+testcase 'v=; set -- "${v:=a\ b}" "$v"'		'2|a\ b|a\ b'
+testcase 'v=; set -- ${v:="$p"} $v'		'2|/etc/|/etc/'
+# whether $p is quoted or not shouldn't really matter
+testcase 'v=; set -- "${v:="$p"}" "$v"'		'2|/et[c]/|/et[c]/'
+
+test "x$failures" = x

Copied: stable/8/tools/regression/bin/sh/expansion/cmdsubst2.0 (from r205105, head/tools/regression/bin/sh/expansion/cmdsubst2.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/cmdsubst2.0	Sun Mar 28 19:34:57 2010	(r205800, copy of r205105, head/tools/regression/bin/sh/expansion/cmdsubst2.0)
@@ -0,0 +1,43 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+	if ! eval "[ $* ]"; then
+		echo "Failed: $*"
+		: $((failures += 1))
+	fi
+}
+
+check '`echo /et[c]/` = "/etc/"'
+check '`printf /var/empty%s /et[c]/` = "/var/empty/etc/"'
+check '"`echo /et[c]/`" = "/etc/"'
+check '`echo "/et[c]/"` = "/etc/"'
+check '`printf /var/empty%s "/et[c]/"` = "/var/empty/et[c]/"'
+check '`printf /var/empty/%s \"/et[c]/\"` = "/var/empty/\"/et[c]/\""'
+check '"`echo \"/et[c]/\"`" = "/et[c]/"'
+check '"`echo "/et[c]/"`" = "/et[c]/"'
+check '`echo $$` = $$'
+check '"`echo $$`" = $$'
+check '`echo \$\$` = $$'
+check '"`echo \$\$`" = $$'
+
+# Command substitutions consisting of a single builtin may be treated
+# differently.
+check '`:; echo /et[c]/` = "/etc/"'
+check '`:; printf /var/empty%s /et[c]/` = "/var/empty/etc/"'
+check '"`:; echo /et[c]/`" = "/etc/"'
+check '`:; echo "/et[c]/"` = "/etc/"'
+check '`:; printf /var/empty%s "/et[c]/"` = "/var/empty/et[c]/"'
+check '`:; printf /var/empty/%s \"/et[c]/\"` = "/var/empty/\"/et[c]/\""'
+check '"`:; echo \"/et[c]/\"`" = "/et[c]/"'
+check '"`:; echo "/et[c]/"`" = "/et[c]/"'
+check '`:; echo $$` = $$'
+check '"`:; echo $$`" = $$'
+check '`:; echo \$\$` = $$'
+check '"`:; echo \$\$`" = $$'
+
+check '`set -f; echo /et[c]/` = "/etc/"'
+check '"`set -f; echo /et[c]/`" = "/et[c]/"'
+
+exit $((failures > 0))

Copied: stable/8/tools/regression/bin/sh/expansion/plus-minus1.0 (from r204842, head/tools/regression/bin/sh/expansion/plus-minus1.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/plus-minus1.0	Sun Mar 28 19:34:57 2010	(r205800, copy of r204842, head/tools/regression/bin/sh/expansion/plus-minus1.0)
@@ -0,0 +1,81 @@
+# $FreeBSD$
+
+e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
+h='##'
+failures=''
+ok=''
+
+testcase() {
+	code="$1"
+	expected="$2"
+	oIFS="$IFS"
+	eval "$code"
+	IFS='|'
+	result="$#|$*"
+	IFS="$oIFS"
+	if [ "x$result" = "x$expected" ]; then
+		ok=x$ok
+	else
+		failures=x$failures
+		echo "For $code, expected $expected actual $result"
+	fi
+}
+
+testcase 'set -- a b'				'2|a|b'
+testcase 'set --'				'0|'
+testcase 'set -- ${e}'				'0|'
+testcase 'set -- "${e}"'			'1|'
+
+testcase 'set -- $p'				'1|/etc/'
+testcase 'set -- "$p"'				'1|/et[c]/'
+testcase 'set -- ${s+$p}'			'1|/etc/'
+testcase 'set -- "${s+$p}"'			'1|/et[c]/'
+testcase 'set -- ${s+"$p"}'			'1|/et[c]/'
+# Dquotes in dquotes is undefined for Bourne shell operators
+#testcase 'set -- "${s+"$p"}"'			'1|/et[c]/'
+testcase 'set -- ${e:-$p}'			'1|/etc/'
+testcase 'set -- "${e:-$p}"'			'1|/et[c]/'
+testcase 'set -- ${e:-"$p"}'			'1|/et[c]/'
+# Dquotes in dquotes is undefined for Bourne shell operators
+#testcase 'set -- "${e:-"$p"}"'			'1|/et[c]/'
+testcase 'set -- ${e:+"$e"}'			'0|'
+testcase 'set -- ${e:+$w"$e"}'			'0|'
+testcase 'set -- ${w:+"$w"}'			'1|a b c'
+testcase 'set -- ${w:+$w"$w"}'			'3|a|b|ca b c'
+
+# These two are known broken in FreeBSD /bin/sh
+#testcase 'set -- ${s+a b}'			'2|a|b'
+#testcase 'set -- ${e:-a b}'			'2|a|b'
+testcase 'set -- "${s+a b}"'			'1|a b'
+testcase 'set -- "${e:-a b}"'			'1|a b'
+testcase 'set -- ${e:-\}}'			'1|}'
+# Currently broken in FreeBSD /bin/sh
+#testcase 'set -- "${e:-\}}"'			'1|}'
+testcase 'set -- ${e:+{}}'			'1|}'
+testcase 'set -- "${e:+{}}"'			'1|}'
+
+testcase 'set -- ${e+x}${e+x}'			'1|xx'
+testcase 'set -- "${e+x}"${e+x}'		'1|xx'
+testcase 'set -- ${e+x}"${e+x}"'		'1|xx'
+testcase 'set -- "${e+x}${e+x}"'		'1|xx'
+testcase 'set -- "${e+x}""${e+x}"'		'1|xx'
+
+testcase 'set -- ${e:-${e:-$p}}'		'1|/etc/'
+testcase 'set -- "${e:-${e:-$p}}"'		'1|/et[c]/'
+testcase 'set -- ${e:-"${e:-$p}"}'		'1|/et[c]/'
+testcase 'set -- ${e:-${e:-"$p"}}'		'1|/et[c]/'
+testcase 'set -- ${e:-${e:-${e:-$w}}}'		'3|a|b|c'
+testcase 'set -- ${e:-${e:-${e:-"$w"}}}'	'1|a b c'
+testcase 'set -- ${e:-${e:-"${e:-$w}"}}'	'1|a b c'
+testcase 'set -- ${e:-"${e:-${e:-$w}}"}'	'1|a b c'
+testcase 'set -- "${e:-${e:-${e:-$w}}}"'	'1|a b c'
+
+testcase 'shift $#; set -- ${1+"$@"}'		'0|'
+testcase 'set -- ""; set -- ${1+"$@"}'		'1|'
+testcase 'set -- "" a; set -- ${1+"$@"}'	'2||a'
+testcase 'set -- a ""; set -- ${1+"$@"}'	'2|a|'
+testcase 'set -- a b; set -- ${1+"$@"}'		'2|a|b'
+testcase 'set -- a\ b; set -- ${1+"$@"}'	'1|a b'
+testcase 'set -- " " ""; set -- ${1+"$@"}'	'2| |'
+
+test "x$failures" = x

Copied: stable/8/tools/regression/bin/sh/expansion/question1.0 (from r198453, head/tools/regression/bin/sh/expansion/question1.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/question1.0	Sun Mar 28 19:34:57 2010	(r205800, copy of r198453, head/tools/regression/bin/sh/expansion/question1.0)
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+x=a\ b
+[ "$x" = "${x?}" ] || exit 1
+set -- ${x?}
+{ [ "$#" = 2 ] && [ "$1" = a ] && [ "$2" = b ]; } || exit 1
+unset x
+(echo ${x?abcdefg}) 2>&1 | grep -q abcdefg || exit 1
+sh -c 'unset foo; echo ${foo?}' 2>/dev/null && exit 1
+sh -c 'foo=; echo ${foo:?}' 2>/dev/null && exit 1
+sh -c 'foo=; echo ${foo?}' >/dev/null || exit 1
+sh -c 'foo=1; echo ${foo:?}' >/dev/null || exit 1
+sh -c 'echo ${!?}' 2>/dev/null && exit 1
+sh -c ':& echo ${!?}' >/dev/null || exit 1
+sh -c 'echo ${#?}' >/dev/null || exit 1
+sh -c 'echo ${*?}' 2>/dev/null && exit 1
+sh -c 'echo ${*?}' sh x >/dev/null || exit 1
+sh -c 'echo ${1?}' 2>/dev/null && exit 1
+sh -c 'echo ${1?}' sh x >/dev/null || exit 1
+sh -c 'echo ${2?}' sh x 2>/dev/null && exit 1
+sh -c 'echo ${2?}' sh x y >/dev/null || exit 1
+exit 0

Copied: stable/8/tools/regression/bin/sh/expansion/set-u1.0 (from r198453, head/tools/regression/bin/sh/expansion/set-u1.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/set-u1.0	Sun Mar 28 19:34:57 2010	(r205800, copy of r198453, head/tools/regression/bin/sh/expansion/set-u1.0)
@@ -0,0 +1,29 @@
+# $FreeBSD$
+
+sh -uc 'unset foo; echo $foo' 2>/dev/null && exit 1
+sh -uc 'foo=; echo $foo' >/dev/null || exit 1
+sh -uc 'foo=1; echo $foo' >/dev/null || exit 1
+# -/+/= are unaffected by set -u
+sh -uc 'unset foo; echo ${foo-}' >/dev/null || exit 1
+sh -uc 'unset foo; echo ${foo+}' >/dev/null || exit 1
+sh -uc 'unset foo; echo ${foo=}' >/dev/null || exit 1
+# length/trimming are affected
+sh -uc 'unset foo; echo ${#foo}' 2>/dev/null && exit 1
+sh -uc 'foo=; echo ${#foo}' >/dev/null || exit 1
+sh -uc 'unset foo; echo ${foo#?}' 2>/dev/null && exit 1
+sh -uc 'foo=1; echo ${foo#?}' >/dev/null || exit 1
+sh -uc 'unset foo; echo ${foo##?}' 2>/dev/null && exit 1
+sh -uc 'foo=1; echo ${foo##?}' >/dev/null || exit 1
+sh -uc 'unset foo; echo ${foo%?}' 2>/dev/null && exit 1
+sh -uc 'foo=1; echo ${foo%?}' >/dev/null || exit 1
+sh -uc 'unset foo; echo ${foo%%?}' 2>/dev/null && exit 1
+sh -uc 'foo=1; echo ${foo%%?}' >/dev/null || exit 1
+
+sh -uc 'echo $!' 2>/dev/null && exit 1
+sh -uc ':& echo $!' >/dev/null || exit 1
+sh -uc 'echo $#' >/dev/null || exit 1
+sh -uc 'echo $1' 2>/dev/null && exit 1
+sh -uc 'echo $1' sh x >/dev/null || exit 1
+sh -uc 'echo $2' sh x 2>/dev/null && exit 1
+sh -uc 'echo $2' sh x y >/dev/null || exit 1
+exit 0

Copied: stable/8/tools/regression/bin/sh/parser/heredoc1.0 (from r204836, head/tools/regression/bin/sh/parser/heredoc1.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/parser/heredoc1.0	Sun Mar 28 19:34:57 2010	(r205800, copy of r204836, head/tools/regression/bin/sh/parser/heredoc1.0)
@@ -0,0 +1,85 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+	if ! eval "[ $* ]"; then
+		echo "Failed: $*"
+		: $((failures += 1))
+	fi
+}
+
+check '"$(cat <<EOF
+hi
+EOF
+)" = hi'
+
+check '"$(cat <<EOF
+${$+hi}
+EOF
+)" = hi'
+
+unset yy
+check '"$(cat <<EOF
+${yy-hi}
+EOF
+)" = hi'
+
+check '"$(cat <<EOF
+${$+hi
+there}
+EOF
+)" = "hi
+there"'
+
+check '"$(cat <<EOF
+$((1+1))
+EOF
+)" = 2'
+
+check '"$(cat <<EOF
+$(echo hi)
+EOF
+)" = hi'
+
+check '"$(cat <<EOF
+`echo hi`
+EOF
+)" = hi'
+
+check '"$(cat <<\EOF
+${$+hi}
+EOF
+)" = "\${\$+hi}"'
+
+check '"$(cat <<\EOF
+$(
+EOF
+)" = \$\('
+
+check '"$(cat <<\EOF
+`
+EOF
+)" = \`'
+
+check '"$(cat <<EOF
+"
+EOF
+)" = \"'
+
+check '"$(cat <<\EOF
+"
+EOF
+)" = \"'
+
+check '"$(cat <<esac
+'"'"'
+esac
+)" = "'"'"'"'
+
+check '"$(cat <<\)
+'"'"'
+)
+)" = "'"'"'"'
+
+exit $((failures != 0))



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003281934.o2SJYvSq022890>