Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 May 2010 17:22:00 +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: r208037 - in stable/8/tools/regression/bin/sh: expansion parameters parser
Message-ID:  <201005131722.o4DHM0iP098653@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Thu May 13 17:22:00 2010
New Revision: 208037
URL: http://svn.freebsd.org/changeset/base/208037

Log:
  MFC r206143,r206148,r206149,r206167,r206491,r206817,r207127,r207824
  Various testcases that work correctly with stable/8 sh.

Added:
  stable/8/tools/regression/bin/sh/expansion/arith4.0
     - copied unchanged from r206167, head/tools/regression/bin/sh/expansion/arith4.0
  stable/8/tools/regression/bin/sh/expansion/plus-minus3.0
     - copied unchanged from r206817, head/tools/regression/bin/sh/expansion/plus-minus3.0
  stable/8/tools/regression/bin/sh/expansion/tilde1.0
     - copied unchanged from r206149, head/tools/regression/bin/sh/expansion/tilde1.0
  stable/8/tools/regression/bin/sh/expansion/trim1.0
     - copied unchanged from r206143, head/tools/regression/bin/sh/expansion/trim1.0
  stable/8/tools/regression/bin/sh/expansion/trim3.0
     - copied unchanged from r207127, head/tools/regression/bin/sh/expansion/trim3.0
  stable/8/tools/regression/bin/sh/parameters/pwd1.0
     - copied unchanged from r206491, head/tools/regression/bin/sh/parameters/pwd1.0
  stable/8/tools/regression/bin/sh/parser/case1.0
     - copied unchanged from r207824, head/tools/regression/bin/sh/parser/case1.0
  stable/8/tools/regression/bin/sh/parser/case2.0
     - copied unchanged from r207824, head/tools/regression/bin/sh/parser/case2.0
  stable/8/tools/regression/bin/sh/parser/heredoc3.0
     - copied unchanged from r207824, head/tools/regression/bin/sh/parser/heredoc3.0
Modified:
Directory Properties:
  stable/8/tools/regression/bin/sh/   (props changed)

Copied: stable/8/tools/regression/bin/sh/expansion/arith4.0 (from r206167, head/tools/regression/bin/sh/expansion/arith4.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/arith4.0	Thu May 13 17:22:00 2010	(r208037, copy of r206167, head/tools/regression/bin/sh/expansion/arith4.0)
@@ -0,0 +1,20 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+	if [ $(($1)) != $2 ]; then
+		failures=$((failures+1))
+		echo "For $1, expected $2 actual $(($1))"
+	fi
+}
+
+check '20 / 2 / 2' 5
+check '20 - 2 - 2' 16
+unset a b c d
+check "a = b = c = d = 1" 1
+check "a == 1 && b == 1 && c == 1 && d == 1" 1
+check "a += b += c += d" 4
+check "a == 4 && b == 3 && c == 2 && d == 1" 1
+
+exit $((failures != 0))

Copied: stable/8/tools/regression/bin/sh/expansion/plus-minus3.0 (from r206817, head/tools/regression/bin/sh/expansion/plus-minus3.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/plus-minus3.0	Thu May 13 17:22:00 2010	(r208037, copy of r206817, head/tools/regression/bin/sh/expansion/plus-minus3.0)
@@ -0,0 +1,44 @@
+# $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
+}
+
+# We follow original ash behaviour for quoted ${var+-=?} expansions:
+# a double-quote in one switches back to unquoted state.
+# This allows expanding a variable as a single word if it is set
+# and substituting multiple words otherwise.
+# It is also close to the Bourne and Korn shells.
+# POSIX leaves this undefined, and various other shells treat
+# such double-quotes as introducing a second level of quoting
+# which does not do much except quoting close braces.
+
+testcase 'set -- "${p+"/et[c]/"}"'		'1|/etc/'
+testcase 'set -- "${p-"/et[c]/"}"'		'1|/et[c]/'
+testcase 'set -- "${p+"$p"}"'			'1|/etc/'
+testcase 'set -- "${p-"$p"}"'			'1|/et[c]/'
+testcase 'set -- "${p+"""/et[c]/"}"'		'1|/etc/'
+testcase 'set -- "${p-"""/et[c]/"}"'		'1|/et[c]/'
+testcase 'set -- "${p+"""$p"}"'			'1|/etc/'
+testcase 'set -- "${p-"""$p"}"'			'1|/et[c]/'
+testcase 'set -- "${p+"\@"}"'			'1|@'
+testcase 'set -- "${p+"'\''/et[c]/'\''"}"'	'1|/et[c]/'
+
+test "x$failures" = x

Copied: stable/8/tools/regression/bin/sh/expansion/tilde1.0 (from r206149, head/tools/regression/bin/sh/expansion/tilde1.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/tilde1.0	Thu May 13 17:22:00 2010	(r208037, copy of r206149, head/tools/regression/bin/sh/expansion/tilde1.0)
@@ -0,0 +1,56 @@
+# $FreeBSD$
+
+HOME=/tmp
+roothome=~root
+if [ "$roothome" = "~root" ]; then
+	echo "~root is not expanded!"
+	exit 2
+fi
+
+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 -- ~'				'1|/tmp'
+testcase 'set -- ~/foo'				'1|/tmp/foo'
+testcase 'set -- x~'				'1|x~'
+testcase 'set -- ~root'				"1|$roothome"
+h=~
+testcase 'set -- "$h"'				'1|/tmp'
+ooIFS=$IFS
+IFS=m
+testcase 'set -- ~'				'1|/tmp'
+testcase 'set -- ~/foo'				'1|/tmp/foo'
+testcase 'set -- $h'				'2|/t|p'
+IFS=$ooIFS
+t=\~
+testcase 'set -- $t'				'1|~'
+r=$(cat <<EOF
+~
+EOF
+)
+testcase 'set -- $r'				'1|~'
+r=$(cat <<EOF
+${t+~}
+EOF
+)
+testcase 'set -- $r'				'1|~'
+r=$(cat <<EOF
+${t+~/.}
+EOF
+)
+testcase 'set -- $r'				'1|~/.'
+
+test "x$failures" = x

Copied: stable/8/tools/regression/bin/sh/expansion/trim1.0 (from r206143, head/tools/regression/bin/sh/expansion/trim1.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/trim1.0	Thu May 13 17:22:00 2010	(r208037, copy of r206143, head/tools/regression/bin/sh/expansion/trim1.0)
@@ -0,0 +1,85 @@
+# $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 -- ${t%t}'			'1|texttex'
+testcase 'set -- "${t%t}"'			'1|texttex'
+testcase 'set -- ${t%e*}'			'1|textt'
+testcase 'set -- "${t%e*}"'			'1|textt'
+testcase 'set -- ${t%%e*}'			'1|t'
+testcase 'set -- "${t%%e*}"'			'1|t'
+testcase 'set -- ${t%%*}'			'0|'
+testcase 'set -- "${t%%*}"'			'1|'
+testcase 'set -- ${t#t}'			'1|exttext'
+testcase 'set -- "${t#t}"'			'1|exttext'
+testcase 'set -- ${t#*x}'			'1|ttext'
+testcase 'set -- "${t#*x}"'			'1|ttext'
+testcase 'set -- ${t##*x}'			'1|t'
+testcase 'set -- "${t##*x}"'			'1|t'
+testcase 'set -- ${t##*}'			'0|'
+testcase 'set -- "${t##*}"'			'1|'
+testcase 'set -- ${t%e$a}'			'1|textt'
+
+set -f
+testcase 'set -- ${s%[?]*}'			'1|ast*que'
+testcase 'set -- "${s%[?]*}"'			'1|ast*que'
+testcase 'set -- ${s%[*]*}'			'1|ast'
+testcase 'set -- "${s%[*]*}"'			'1|ast'
+set +f
+
+testcase 'set -- $b'				'1|{{(#)}}'
+testcase 'set -- ${b%\}}'			'1|{{(#)}'
+testcase 'set -- ${b#{}'			'1|{(#)}}'
+testcase 'set -- "${b#{}"'			'1|{(#)}}'
+# Parentheses are special in ksh, check that they can be escaped
+testcase 'set -- ${b%\)*}'			'1|{{(#'
+testcase 'set -- ${b#{}'			'1|{(#)}}'
+testcase 'set -- $h'				'1|##'
+testcase 'set -- ${h#\#}'			'1|#'
+testcase 'set -- ${h###}'			'1|#'
+testcase 'set -- "${h###}"'			'1|#'
+testcase 'set -- ${h%#}'			'1|#'
+testcase 'set -- "${h%#}"'			'1|#'
+
+set -f
+testcase 'set -- ${s%"${s#?}"}'			'1|a'
+testcase 'set -- ${s%"${s#????}"}'		'1|ast*'
+testcase 'set -- ${s%"${s#????????}"}'		'1|ast*que?'
+testcase 'set -- ${s#"${s%?}"}'			'1|n'
+testcase 'set -- ${s#"${s%????}"}'		'1|?non'
+testcase 'set -- ${s#"${s%????????}"}'		'1|*que?non'
+set +f
+testcase 'set -- "${s%"${s#?}"}"'		'1|a'
+testcase 'set -- "${s%"${s#????}"}"'		'1|ast*'
+testcase 'set -- "${s%"${s#????????}"}"'	'1|ast*que?'
+testcase 'set -- "${s#"${s%?}"}"'		'1|n'
+testcase 'set -- "${s#"${s%????}"}"'		'1|?non'
+testcase 'set -- "${s#"${s%????????}"}"'	'1|*que?non'
+testcase 'set -- ${p#${p}}'			'1|/etc/'
+testcase 'set -- "${p#${p}}"'			'1|/et[c]/'
+testcase 'set -- ${p#*[[]}'			'1|c]/'
+testcase 'set -- "${p#*[[]}"'			'1|c]/'
+testcase 'set -- ${p#*\[}'			'1|c]/'
+testcase 'set -- ${p#*"["}'			'1|c]/'
+testcase 'set -- "${p#*"["}"'			'1|c]/'
+
+test "x$failures" = x

Copied: stable/8/tools/regression/bin/sh/expansion/trim3.0 (from r207127, head/tools/regression/bin/sh/expansion/trim3.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/expansion/trim3.0	Thu May 13 17:22:00 2010	(r208037, copy of r207127, head/tools/regression/bin/sh/expansion/trim3.0)
@@ -0,0 +1,46 @@
+# $FreeBSD$
+
+e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}'
+h='##' c='\\\\'
+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
+}
+
+# This doesn't make much sense, but it fails in dash so I'm adding it here:
+testcase 'set -- "${w%${w#???}}"'		'1|a b'
+
+testcase 'set -- ${p#/et[}'			'1|c]/'
+testcase 'set -- "${p#/et[}"'			'1|c]/'
+testcase 'set -- "${p%${p#????}}"'		'1|/et['
+
+testcase 'set -- ${b%'\'}\''}'			'1|{{(#)}'
+
+testcase 'set -- ${c#\\}'			'1|\\\'
+testcase 'set -- ${c#\\\\}'			'1|\\'
+testcase 'set -- ${c#\\\\\\}'			'1|\'
+testcase 'set -- ${c#\\\\\\\\}'			'0|'
+testcase 'set -- "${c#\\}"'			'1|\\\'
+testcase 'set -- "${c#\\\\}"'			'1|\\'
+testcase 'set -- "${c#\\\\\\}"'			'1|\'
+testcase 'set -- "${c#\\\\\\\\}"'		'1|'
+testcase 'set -- "${c#"$c"}"'			'1|'
+testcase 'set -- ${c#"$c"}'			'0|'
+testcase 'set -- "${c%"$c"}"'			'1|'
+testcase 'set -- ${c%"$c"}'			'0|'
+
+test "x$failures" = x

Copied: stable/8/tools/regression/bin/sh/parameters/pwd1.0 (from r206491, head/tools/regression/bin/sh/parameters/pwd1.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/parameters/pwd1.0	Thu May 13 17:22:00 2010	(r208037, copy of r206491, head/tools/regression/bin/sh/parameters/pwd1.0)
@@ -0,0 +1,11 @@
+# $FreeBSD$
+# Check that bogus PWD values are not accepted from the environment.
+
+cd / || exit 3
+failures=0
+[ "$(PWD=foo sh -c 'pwd')" = / ] || : $((failures += 1))
+[ "$(PWD=/var/empty sh -c 'pwd')" = / ] || : $((failures += 1))
+[ "$(PWD=/var/empty/foo sh -c 'pwd')" = / ] || : $((failures += 1))
+[ "$(PWD=/bin/ls sh -c 'pwd')" = / ] || : $((failures += 1))
+
+exit $((failures != 0))

Copied: stable/8/tools/regression/bin/sh/parser/case1.0 (from r207824, head/tools/regression/bin/sh/parser/case1.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/parser/case1.0	Thu May 13 17:22:00 2010	(r208037, copy of r207824, head/tools/regression/bin/sh/parser/case1.0)
@@ -0,0 +1,14 @@
+# $FreeBSD$
+
+keywords='if then else elif fi while until for do done { } case esac ! in'
+
+# Keywords can be used unquoted in case statements, except the keyword
+# esac as the first pattern of a '|' alternation without a starting '('.
+# (POSIX doesn't seem to require (esac) to work.)
+for k in $keywords; do
+	eval "case $k in (foo|$k) ;; *) echo bad ;; esac"
+	eval "case $k in ($k) ;; *) echo bad ;; esac"
+	eval "case $k in foo|$k) ;; *) echo bad ;; esac"
+	[ "$k" = esac ] && continue
+	eval "case $k in $k) ;; *) echo bad ;; esac"
+done

Copied: stable/8/tools/regression/bin/sh/parser/case2.0 (from r207824, head/tools/regression/bin/sh/parser/case2.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/parser/case2.0	Thu May 13 17:22:00 2010	(r208037, copy of r207824, head/tools/regression/bin/sh/parser/case2.0)
@@ -0,0 +1,32 @@
+# $FreeBSD$
+
+# Pretty much only ash derivatives can parse all of this.
+
+f1() {
+	x=$(case x in
+		(x|esac) ;;
+		(*) echo bad >&2 ;;
+	esac)
+}
+f1
+f2() {
+	x=$(case x in
+		(x|esac) ;;
+		(*) echo bad >&2
+	esac)
+}
+f2
+f3() {
+	x=$(case x in
+		x|esac) ;;
+		*) echo bad >&2 ;;
+	esac)
+}
+f3
+f4() {
+	x=$(case x in
+		x|esac) ;;
+		*) echo bad >&2
+	esac)
+}
+f4

Copied: stable/8/tools/regression/bin/sh/parser/heredoc3.0 (from r207824, head/tools/regression/bin/sh/parser/heredoc3.0)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/parser/heredoc3.0	Thu May 13 17:22:00 2010	(r208037, copy of r207824, head/tools/regression/bin/sh/parser/heredoc3.0)
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+# This may be expected to work, but pretty much only ash derivatives allow it.
+
+test "$(cat <<EOF)" = "hi there"
+hi there
+EOF



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