aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-02-16 13:42:23 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-03-01 19:26:07 +0300
commita64b2ae2099346471ead988d5f2d383d55a9bf89 (patch)
tree04e1a43a484461ef88e6a804c1aa3751a58cdd95 /tests
parent9b4e51f72d640262161e38981a8b9255a7b47f6c (diff)
Add set builtin
Diffstat (limited to 'tests')
-rw-r--r--tests/test/script/runner/buildfile2
-rw-r--r--tests/test/script/runner/set.test275
2 files changed, 276 insertions, 1 deletions
diff --git a/tests/test/script/runner/buildfile b/tests/test/script/runner/buildfile
index df37c6d..c3df228 100644
--- a/tests/test/script/runner/buildfile
+++ b/tests/test/script/runner/buildfile
@@ -2,7 +2,7 @@
# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-./: test{cleanup expr if pipe redirect regex status} exe{driver} $b
+./: test{cleanup expr if pipe redirect regex set status} exe{driver} $b
test{*}: target = exe{driver}
diff --git a/tests/test/script/runner/set.test b/tests/test/script/runner/set.test
new file mode 100644
index 0000000..7c24669
--- /dev/null
+++ b/tests/test/script/runner/set.test
@@ -0,0 +1,275 @@
+# file : tests/test/script/runner/set.test
+# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+.include ../common.test
+
+: special
+:
+{
+ : pipelining
+ :
+ $c <'set foo | cat >bar' && $b 2>>EOE != 0
+ testscript:1:1: error: set builtin must be the last command in a pipe
+ EOE
+
+ : redirecting
+ :
+ {
+ : stdout
+ :
+ $c <'set foo >bar' && $b 2>>EOE != 0
+ testscript:1:1: error: set builtin stdout must not be redirected
+ EOE
+
+ : stderr
+ :
+ $c <'set foo 2>bar' && $b 2>>EOE != 0
+ testscript:1:1: error: set builtin stderr must not be redirected
+ EOE
+ }
+
+ : status
+ :
+ $c <'set foo == 1' && $b 2>>EOE != 0
+ testscript:1:1: error: set builtin exit status must not be other than zero
+ EOE
+}
+
+: arguments
+:
+{
+ : none
+ :
+ $c <'set -e' && $b 2>>EOE != 0
+ testscript:1:1: error: missing variable name
+ EOE
+
+ : unexpected
+ :
+ $c <'set foo bar baz' && $b 2>>EOE != 0
+ testscript:1:1: error: unexpected argument
+ EOE
+
+ : empty-attrs
+ :
+ $c <"set '' baz" && $b 2>>EOE != 0
+ testscript:1:1: error: empty variable attributes
+ EOE
+
+ : empty-var
+ :
+ $c <"set ''" && $b 2>>EOE != 0
+ testscript:1:1: error: empty variable name
+ EOE
+}
+
+: whitespace-separated-list
+:
+{
+ : non-exact
+ :
+ $c <<EOI && $b
+ set -w baz <' foo bar ';
+ echo $baz >'foo bar'
+ EOI
+
+ : exact
+ :
+ {
+ : trailing-ws
+ :
+ $c <<EOI && $b
+ set -e -w baz <' foo bar ';
+ echo $baz >'foo bar '
+ EOI
+
+ : no-trailing-ws
+ :
+ : Note that we need to strip the default trailing newline as well with the
+ : ':' modifier.
+ :
+ $c <<EOI && $b
+ set -e -w baz <:' foo bar';
+ echo $baz >'foo bar'
+ EOI
+ }
+}
+
+: newline-separated-list
+:
+{
+ : non-exact
+ :
+ $c <<EOI && $b
+ set -n baz <<EOF;
+
+ foo
+
+ bar
+
+ EOF
+ echo $baz >' foo bar '
+ EOI
+
+ : exact
+ :
+ {
+ : trailing-newline
+ :
+ $c <<EOI && $b
+ set -e -n baz <<EOF;
+
+ foo
+
+ bar
+
+ EOF
+ echo $baz >' foo bar '
+ EOI
+
+ : no-trailing-newline
+ :
+ $c <<EOI && $b
+ set -e -n baz <<:EOF;
+
+ foo
+
+ bar
+ EOF
+ echo $baz >' foo bar'
+ EOI
+ }
+}
+
+: string
+:
+{
+ : non-exact
+ :
+ $c <<EOI && $b
+ set baz <<EOF;
+
+ foo
+
+ bar
+
+ EOF
+ echo $baz >>EOO
+
+ foo
+
+ bar
+
+ EOO
+ EOI
+
+ : roundtrip
+ :
+ echo 'foo' | set bar;
+ echo "$bar" >'foo'
+
+ : exact
+ :
+ : Note that echo adds the trailing newline, so EOF and EOO here-documents
+ : differ by this newline.
+ :
+ {
+ : trailing-newline
+ :
+ $c <<EOI && $b
+ set -e baz <<EOF;
+
+ foo
+
+ bar
+ EOF
+ echo "$baz" >>EOO
+
+ foo
+
+ bar
+
+ EOO
+ EOI
+
+ : no-trailing-newline
+ :
+ $c <<EOI && $b
+ set -e baz <<:EOF;
+
+ foo
+
+ bar
+ EOF
+ echo "$baz" >>EOO
+
+ foo
+
+ bar
+ EOO
+ EOI
+ }
+}
+
+: attributes
+:
+{
+ : dir_path
+ :
+ $c <<EOI && $b
+ set [dir_path] bar <'foo';
+ echo $bar >/'foo/'
+ EOI
+
+ : null
+ :
+ $c <<EOI && $b
+ set [null] foo <-;
+ echo $foo >''
+ EOI
+
+ : none
+ :
+ $c <<EOI && $b 2>>EOE != 0
+ set -w baz <'foo bar';
+ echo "$baz"
+ EOI
+ testscript:2:8: error: concatenating variable expansion contains multiple values
+ EOE
+
+ # @@ Move the following tests to build2 parser unit tests when created.
+ #
+ : empty-brackets
+ :
+ $c <<EOI && $b 2>>EOE != 0
+ set -w '[]' baz <'foo bar';
+ echo "$baz"
+ EOI
+ testscript:2:8: error: concatenating variable expansion contains multiple values
+ EOE
+
+ : no-left-bracket
+ :
+ $c <<EOI && $b 2>>EOE != 0
+ set -w x baz
+ EOI
+ testscript:1:1: (x):1:1: error: expected '[' instead of 'x'
+ EOE
+
+ : unknown
+ :
+ $c <<EOI && $b 2>>EOE != 0
+ set -w [x] baz
+ EOI
+ testscript:1:1: ([x]):1:1: error: unknown value attribute x
+ EOE
+
+ : junk
+ :
+ $c <<EOI && $b 2>>EOE != 0
+ set -w '[string] x' baz
+ EOI
+ testscript:1:1: ([string] x):1:10: error: trailing junk after ']'
+ EOE
+}