svn commit: r206148 - head/tools/regression/bin/sh/expansion

Jilles Tjoelker jilles at FreeBSD.org
Sat Apr 3 21:32:22 UTC 2010


Author: jilles
Date: Sat Apr  3 21:32:22 2010
New Revision: 206148
URL: http://svn.freebsd.org/changeset/base/206148

Log:
  sh: Add some testcases for the working parts of tilde expansion.

Added:
  head/tools/regression/bin/sh/expansion/tilde1.0   (contents, props changed)

Added: head/tools/regression/bin/sh/expansion/tilde1.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/expansion/tilde1.0	Sat Apr  3 21:32:22 2010	(r206148)
@@ -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'
+oIFS=$IFS
+IFS=m
+testcase 'set -- ~'				'1|/tmp'
+testcase 'set -- ~/foo'				'1|/tmp/foo'
+testcase 'set -- $h'				'2|/t|p'
+IFS=$oIFS
+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


More information about the svn-src-all mailing list