svn commit: r207824 - head/tools/regression/bin/sh/parser

Jilles Tjoelker jilles at FreeBSD.org
Sun May 9 17:10:51 UTC 2010


Author: jilles
Date: Sun May  9 17:10:50 2010
New Revision: 207824
URL: http://svn.freebsd.org/changeset/base/207824

Log:
  sh: Add some parser tests.
  
  case1.0 tests POSIX requirements and one more for keywords in case
  statements. The others test very special cases of command substitution.
  
  These also work on stable/8.

Added:
  head/tools/regression/bin/sh/parser/case1.0   (contents, props changed)
  head/tools/regression/bin/sh/parser/case2.0   (contents, props changed)
  head/tools/regression/bin/sh/parser/heredoc3.0   (contents, props changed)

Added: head/tools/regression/bin/sh/parser/case1.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/parser/case1.0	Sun May  9 17:10:50 2010	(r207824)
@@ -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

Added: head/tools/regression/bin/sh/parser/case2.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/parser/case2.0	Sun May  9 17:10:50 2010	(r207824)
@@ -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

Added: head/tools/regression/bin/sh/parser/heredoc3.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/parser/heredoc3.0	Sun May  9 17:10:50 2010	(r207824)
@@ -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


More information about the svn-src-all mailing list