Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

sh: Add tests for lines that look like heredoc delimiters but are not.

Obtained-from:  FreeBSD 221887
  • Loading branch information...
commit 2687e410aa76e380912c06270ee7ec72ede59c4f 1 parent 5824251
authored December 25, 2011
49  tools/regression/bin/sh/parser/heredoc10.0
... ...
@@ -0,0 +1,49 @@
  1
+# $FreeBSD: src/tools/regression/bin/sh/parser/heredoc10.0,v 1.1 2011/05/14 14:19:30 jilles Exp $
  2
+
  3
+# It may be argued that
  4
+#   x=$(cat <<EOF
  5
+#   foo
  6
+#   EOF)
  7
+# is a valid complete command that sets x to foo, because
  8
+#   cat <<EOF
  9
+#   foo
  10
+#   EOF
  11
+# is a valid script even without the final newline.
  12
+# However, if the here-document is not within a new-style command substitution
  13
+# or there are other constructs nested inside the command substitution that
  14
+# need terminators, the delimiter at the start of a line followed by a close
  15
+# parenthesis is clearly a literal part of the here-document.
  16
+
  17
+# This file contains tests that may not work with simplistic $(...) parsers.
  18
+# The open parentheses in comments help mksh, but not zsh.
  19
+
  20
+failures=0
  21
+
  22
+check() {
  23
+	if ! eval "[ $* ]"; then
  24
+		echo "Failed: $*"
  25
+		: $((failures += 1))
  26
+	fi
  27
+}
  28
+
  29
+check '"$(cat <<EOF # (
  30
+EOF )
  31
+EOF
  32
+)" = "EOF )"'
  33
+
  34
+check '"$({ cat <<EOF # (
  35
+EOF)
  36
+EOF
  37
+})" = "EOF)"'
  38
+
  39
+check '"$(if :; then cat <<EOF # (
  40
+EOF)
  41
+EOF
  42
+fi)" = "EOF)"'
  43
+
  44
+check '"$( (cat <<EOF # (
  45
+EOF)
  46
+EOF
  47
+))" = "EOF)"'
  48
+
  49
+exit $((failures != 0))
58  tools/regression/bin/sh/parser/heredoc9.0
... ...
@@ -0,0 +1,58 @@
  1
+# $FreeBSD: src/tools/regression/bin/sh/parser/heredoc9.0,v 1.1 2011/05/14 14:19:30 jilles Exp $
  2
+
  3
+# It may be argued that
  4
+#   x=$(cat <<EOF
  5
+#   foo
  6
+#   EOF)
  7
+# is a valid complete command that sets x to foo, because
  8
+#   cat <<EOF
  9
+#   foo
  10
+#   EOF
  11
+# is a valid script even without the final newline.
  12
+# However, if the here-document is not within a new-style command substitution
  13
+# or there are other constructs nested inside the command substitution that
  14
+# need terminators, the delimiter at the start of a line followed by a close
  15
+# parenthesis is clearly a literal part of the here-document.
  16
+
  17
+# This file contains tests that also work with simplistic $(...) parsers.
  18
+
  19
+failures=0
  20
+
  21
+check() {
  22
+	if ! eval "[ $* ]"; then
  23
+		echo "Failed: $*"
  24
+		: $((failures += 1))
  25
+	fi
  26
+}
  27
+
  28
+check '`${SH} -c "cat <<EOF
  29
+EOF)
  30
+EOF
  31
+"` = "EOF)"'
  32
+
  33
+check '`${SH} -c "(cat <<EOF
  34
+EOF)
  35
+EOF
  36
+)"` = "EOF)"'
  37
+
  38
+check '"`cat <<EOF
  39
+EOF x
  40
+EOF
  41
+`" = "EOF x"'
  42
+
  43
+check '"`cat <<EOF
  44
+EOF )
  45
+EOF
  46
+`" = "EOF )"'
  47
+
  48
+check '"`cat <<EOF
  49
+EOF)
  50
+EOF
  51
+`" = "EOF)"'
  52
+
  53
+check '"$(cat <<EOF
  54
+EOF x
  55
+EOF
  56
+)" = "EOF x"'
  57
+
  58
+exit $((failures != 0))

0 notes on commit 2687e41

Please sign in to comment.
Something went wrong with that request. Please try again.