From owner-svn-src-all@FreeBSD.ORG Thu May 13 17:22:01 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0DC931065670; Thu, 13 May 2010 17:22:01 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (unknown [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EE7278FC19; Thu, 13 May 2010 17:22:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o4DHM0qq098662; Thu, 13 May 2010 17:22:00 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o4DHM0iP098653; Thu, 13 May 2010 17:22:00 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201005131722.o4DHM0iP098653@svn.freebsd.org> From: Jilles Tjoelker Date: Thu, 13 May 2010 17:22:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r208037 - in stable/8/tools/regression/bin/sh: expansion parameters parser X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 May 2010 17:22:01 -0000 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 <&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 <