From a64b2ae2099346471ead988d5f2d383d55a9bf89 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 16 Feb 2017 13:42:23 +0300 Subject: Add set builtin --- tests/test/script/runner/buildfile | 2 +- tests/test/script/runner/set.test | 275 +++++++++++++++++++++++++++++++++++++ 2 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 tests/test/script/runner/set.test (limited to 'tests/test/script/runner') 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 <'foo bar' + EOI + + : exact + : + { + : trailing-ws + : + $c <'foo bar ' + EOI + + : no-trailing-ws + : + : Note that we need to strip the default trailing newline as well with the + : ':' modifier. + : + $c <'foo bar' + EOI + } +} + +: newline-separated-list +: +{ + : non-exact + : + $c <' foo bar ' + EOI + + : exact + : + { + : trailing-newline + : + $c <' foo bar ' + EOI + + : no-trailing-newline + : + $c <' foo bar' + EOI + } +} + +: string +: +{ + : non-exact + : + $c <>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 <>EOO + + foo + + bar + + EOO + EOI + + : no-trailing-newline + : + $c <>EOO + + foo + + bar + EOO + EOI + } +} + +: attributes +: +{ + : dir_path + : + $c </'foo/' + EOI + + : null + : + $c <'' + EOI + + : none + : + $c <>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 <>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 <>EOE != 0 + set -w x baz + EOI + testscript:1:1: (x):1:1: error: expected '[' instead of 'x' + EOE + + : unknown + : + $c <>EOE != 0 + set -w [x] baz + EOI + testscript:1:1: ([x]):1:1: error: unknown value attribute x + EOE + + : junk + : + $c <>EOE != 0 + set -w '[string] x' baz + EOI + testscript:1:1: ([string] x):1:10: error: trailing junk after ']' + EOE +} -- cgit v1.1