aboutsummaryrefslogtreecommitdiff
path: root/tests/test/script/runner
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test/script/runner')
-rw-r--r--tests/test/script/runner/buildfile5
-rw-r--r--tests/test/script/runner/cleanup.test122
-rw-r--r--tests/test/script/runner/mkdir.test50
-rw-r--r--tests/test/script/runner/redirect.test107
-rw-r--r--tests/test/script/runner/status.test45
-rw-r--r--tests/test/script/runner/touch.test44
6 files changed, 306 insertions, 67 deletions
diff --git a/tests/test/script/runner/buildfile b/tests/test/script/runner/buildfile
index e5f2761..b9c0e69 100644
--- a/tests/test/script/runner/buildfile
+++ b/tests/test/script/runner/buildfile
@@ -4,6 +4,9 @@
import libs = libbutl%lib{butl}
-exe{driver}: cxx{driver} $libs test{cleanup redirect status}
+exe{driver}: cxx{driver} $libs test{cleanup mkdir redirect status touch}
+
+if ($cxx.target.class == "windows") # @@ TMP
+ test{*}: ext = ".exe"
include ../../../../../build2/
diff --git a/tests/test/script/runner/cleanup.test b/tests/test/script/runner/cleanup.test
index bb65c27..4cd8650 100644
--- a/tests/test/script/runner/cleanup.test
+++ b/tests/test/script/runner/cleanup.test
@@ -2,7 +2,7 @@
# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-+mkdir build &build/ # @@ Should not be necessary once builtin.
++mkdir build
+cat <<EOI >>>build/boostrap.build
project = test
amalgamation =
@@ -13,6 +13,7 @@ EOI
b = $build.driver -q --no-column --buildfile - <"./: test{testscript}" \
&?test/*** test
c = cat >>>testscript
+test = \'$test\'
# Valid cleanups.
#
@@ -33,6 +34,28 @@ $b
$c <"$* &!a";
$b
+: file-implicit
+:
+: Test that a file created out of the script working directory is not
+: implicitly registered for cleanup. If it were, the test would fail due to
+: 'rm' failure.
+:
+$c <"touch ../../a";
+$b;
+rm a
+
+: file-append
+:
+: Test that file append redirect doesn't not register cleanup. If it did, that
+: cleanup would fail as the file would be already deleted by 'rm'.
+:
+$c <<EOI;
+touch a &!a;
+$* -o foo >>>&a;
+rm a
+EOI
+$b
+
: dir-always
:
$c <"$* -d a &a/";
@@ -43,6 +66,16 @@ $b
$c <"$* &?a/";
$b
+: dir-implicit
+:
+: Test that a directory created out of the script working directory is not
+: implicitly registered for cleanup. If it were, the test would fail due to
+: 'rm' failure.
+:
+$c <"mkdir ../../a";
+$b;
+rm -r a
+
: wildcard-always
:
$c <"$* -d a/b -f a/b/c &a/***";
@@ -54,7 +87,8 @@ $c <"$* &?a/***";
$b
: order
-: Test that cleanup is performed in registration reversed order
+:
+: Test that cleanup is performed in registration reversed order.
:
$c <"$* -d a/b &a/ &a/b/";
$b
@@ -62,7 +96,8 @@ $b
# Invalid cleanups.
#
: file-not-exists
-: Test cleanup of non-existing file
+:
+: Test cleanup of non-existing file.
:
$c <"$* &a";
$b 2>>EOE != 0
@@ -70,23 +105,34 @@ testscript:1: error: registered for cleanup file test/1/a does not exist
EOE
: file-out-wd
-: Test cleanup of file out of working directory
+:
+: Test explicit cleanup of a file out of the script working directory.
+:
+$c <"$* &../../a";
+$b 2>>EOE != 0
+testscript:1: error: file cleanup ../../a is out of working directory test/
+EOE
+
+: file-in-wd
+:
+: Test cleanup explicit registration of a file being outside the scope working
+: directory but inside the script working directory.
:
$c <"$* &../a";
$b 2>>EOE != 0
-testscript:1: error: registered for cleanup file test/a is out of working directory test/1/
+testscript:1: error: registered for cleanup file test/a does not exist
EOE
: not-file
-: Test cleanup of directory as a file
+:
+: Test cleanup of a directory as a file.
:
$c <"$* -d a &a";
-$b 2>>EOE != 0
-error: unable to remove file test/1/a: Is a directory
-EOE
+$b 2>- != 0 # @@ REGEX
: dir-not-exists
-: Test cleanup of non-existing directory
+:
+: Test cleanup of non-existing directory.
:
$c <"$* &a/";
$b 2>>EOE != 0
@@ -94,15 +140,27 @@ testscript:1: error: registered for cleanup directory test/1/a/ does not exist
EOE
: dir-out-wd
-: Test cleanup of directory out of working directory
+:
+: Test cleanup of a directory out of the script working directory.
+:
+$c <"$* &../../a/";
+$b 2>>EOE != 0
+testscript:1: error: directory cleanup ../../a/ is out of working directory test/
+EOE
+
+: dir-in-wd
+:
+: Test cleanup explicit registration of a directory being outside the scope
+: working directory but inside the script working directory.
:
$c <"$* &../a/";
$b 2>>EOE != 0
-testscript:1: error: registered for cleanup directory test/a/ is out of working directory test/1/
+testscript:1: error: registered for cleanup directory test/a/ does not exist
EOE
: dir-not-empty
-: Test cleanup of non-empty directory
+:
+: Test cleanup of a non-empty directory.
:
$c <"$* -d a -f a/b &a/";
$b 2>>EOE != 0
@@ -110,15 +168,15 @@ testscript:1: error: registered for cleanup directory test/1/a/ is not empty
EOE
: not-dir
-: Test cleanup of file as a directory
+:
+: Test cleanup of a file as a directory.
:
$c <"$* -f a &a/";
-$b 2>>EOE != 0
-error: unable to remove directory test/1/a/: Not a directory
-EOE
+$b 2>- != 0 # @@ REGEX
: wildcard-not-exists
-: Test cleanup of wildcard not matching any directory
+:
+: Test cleanup of a wildcard not matching any directory.
:
$c <"$* &a/***";
$b 2>>EOE != 0
@@ -126,23 +184,34 @@ testscript:1: error: registered for cleanup wildcard test/1/a/*** doesn't match
EOE
: wildcard-out-wd
-: Test cleanup of wildcard out of working directory
+:
+: Test cleanup of a wildcard out of the script working directory.
+:
+$c <"$* &../../a/***";
+$b 2>>EOE != 0
+testscript:1: error: wildcard cleanup ../../a/*** is out of working directory test/
+EOE
+
+: wildcard-in-wd
+:
+: Test cleanup registration of a wildcard matching the directory that being
+: outside the scope working directory is inside the script working directory.
:
$c <"$* &../a/***";
$b 2>>EOE != 0
-testscript:1: error: registered for cleanup wildcard test/a/*** is out of working directory test/1/
+testscript:1: error: registered for cleanup wildcard test/a/*** doesn't match a directory
EOE
: wildcard-not-dir
-: Test cleanup of file as a wildcard
+:
+: Test cleanup of a file as a wildcard.
:
$c <"$* -f a &a/***";
-$b 2>>EOE != 0
-error: unable to remove directory test/1/a/: Not a directory
-EOE
+$b 2>- != 0 # @@ REGEX
: implicit-overwrite
-: Test implicit cleanup being overwritten with an explicit one
+:
+: Test an implicit cleanup being overwritten with the explicit one,
:
$c <"$* -o foo >>>a &!a";
$b 2>>EOE != 0
@@ -150,7 +219,8 @@ testscript:1: error: registered for cleanup directory test/1/ is not empty
EOE
: explicit-overwrite
-: Test explicit cleanup not being overwritten with an implicit one
+:
+: Test an explicit cleanup not being overwritten with the implicit one.
:
$c <<EOO;
$* &!a;
diff --git a/tests/test/script/runner/mkdir.test b/tests/test/script/runner/mkdir.test
new file mode 100644
index 0000000..6b7b5c9
--- /dev/null
+++ b/tests/test/script/runner/mkdir.test
@@ -0,0 +1,50 @@
+# file : tests/test/script/runner/mkdir.test
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+: dirs
+:
+mkdir a b;
+touch a/a b/b
+
+: parent
+:
+mkdir -p a/b;
+touch a/a a/b/b
+
+: exists
+:
+mkdir -p a a a/b a/b
+
+: double-dash
+:
+: Make sure '-p' directory is created.
+:
+mkdir -p -- -p;
+touch -p/a
+
+: no-args
+:
+: Test passing no arguments.
+:
+mkdir 2>"mkdir: missing directory" == 1
+
+: empty-path
+:
+: Test creation of empty directory path.
+:
+mkdir '' 2>"mkdir: invalid path ''" == 1
+
+: already-exists
+:
+: Test creation of an existing directory. Note that error message is
+: platform-dependent so is not checked.
+:
+mkdir a 2>- a == 1 # @@ REGEX
+
+: not-exists
+:
+: Test creation of a directory with non-existent parent. Note that error
+: message is platform-dependent so is not checked.
+:
+mkdir a/b 2>- == 1 # @@ REGEX
diff --git a/tests/test/script/runner/redirect.test b/tests/test/script/runner/redirect.test
index a49cd3c..68cc9aa 100644
--- a/tests/test/script/runner/redirect.test
+++ b/tests/test/script/runner/redirect.test
@@ -2,31 +2,39 @@
# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-$* -o foo >- # out-null
-$* -e foo 2>- # err-null
-$* -i 0 <foo # in-str
-$* -o foo >foo # out-str
-$* -e foo 2>foo # err-str
-$* -i 1 <foo >foo # inout-str
-$* -i 2 <foo 2>foo # inerr-str
-$* -i 1 -e bar <foo 1>foo 2>bar # inout-err-str
-
-$* -i 0 <<EOO # in-doc
+$* -o foo >- : out-null
+$* -e foo 2>- : err-null
+$* -i 0 <foo : in-str
+$* -o foo >foo : out-str
+$* -e foo 2>foo : err-str
+$* -i 1 <foo >foo : inout-str
+$* -i 2 <foo 2>foo : inerr-str
+$* -i 1 -e bar <foo 1>foo 2>bar : inout-err-str
+
+: in-doc
+:
+$* -i 0 <<EOO
foo
bar
EOO
-$* -o foo -o bar >>EOO # out-doc
+: out-doc
+:
+$* -o foo -o bar >>EOO
foo
bar
EOO
-$* -e foo -e bar 2>>EOO # err-doc
+: err-doc
+:
+$* -e foo -e bar 2>>EOO
foo
bar
EOO
-$* -i 1 <<EOI >>EOO # inout-doc
+: inout-doc
+:
+$* -i 1 <<EOI >>EOO
foo
bar
EOI
@@ -34,7 +42,9 @@ foo
bar
EOO
-$* -i 2 <<EOI 2>>EOE # inerr-doc
+: inerr-doc
+:
+$* -i 2 <<EOI 2>>EOE
foo
bar
EOI
@@ -42,22 +52,15 @@ foo
bar
EOE
-$* -i 1 -e bar -e baz -s 2 <<EOI 1>>EOO 2>>EOE == 2 # inout-err-doc-status
-foo
-bar
+: empty-str-doc
+:
+$* -i 1 -e "" <<EOI >>EOO 2>""
EOI
-foo
-bar
EOO
-bar
-baz
-EOE
-$* -i 1 -e "" <<EOI >>EOO 2>"" # empty-str-doc
-EOI
-EOO
-
-$* -i 1 <<EOI >>EOO # nl-containing-doc
+: nl-containing-doc
+:
+$* -i 1 <<EOI >>EOO
EOI
@@ -67,13 +70,18 @@ EOO
#
# @@ TMP Need does not compare test.
#
-$* -i 1 <:"foo" >:"foo" # no-newline-str
+: no-newline-str
+:
+$* -i 1 <:"foo" >:"foo"
+
#\
$* -i 1 <:"foo" >!"foo" # no-newline-str-fail1
$* -i 1 <"foo" >:!"foo" # no-newline-str-fail2
#\
-$* -i 1 <<:EOI >>:EOO # no-newline-doc
+: no-newline-doc
+:
+$* -i 1 <<:EOI >>:EOO
foo
EOI
foo
@@ -93,29 +101,39 @@ foo
EOO
#\
-$* -i 1 <<:EOI >>:EOO 2>:"" # no-newline-empty-str-doc
+: no-newline-empty-str-doc
+:
+$* -i 1 <<:EOI >>:EOO 2>:""
EOI
EOO
-$* -i 1 <<:EOI >>:EOO # no-newline-nl-cont-doc
+: no-newline-nl-cont-doc
+:
+$* -i 1 <<:EOI >>:EOO
EOI
EOO
-$* -o foo >>>out; # file
+: file
+:
+$* -o foo >>>out;
$* -e bar 2>>>&out;
$* -i 1 <<<out >>EOO
foo
bar
EOO
-$* -o foo -e bar 2>>EOE 1>&2 # merge-str
+: merge-str
+:
+$* -o foo -e bar 2>>EOE 1>&2
foo
bar
EOE
-$* -i 1 <<EOI -e baz >>EOO 2>&1 # merge-doc
+: merge-doc
+:
+$* -i 1 <<EOI -e baz >>EOO 2>&1
foo
bar
EOI
@@ -124,7 +142,9 @@ bar
baz
EOO
-$* -o foo -e bar 2>&1 >>>out; # merge-file
+: merge-file
+:
+$* -o foo -e bar 2>&1 >>>out;
$* -e baz -o biz 1>&2 2>>>&out;
$* -i 1 <<<out >>EOO
foo
@@ -132,3 +152,20 @@ bar
baz
biz
EOO
+
+# Builtins redirects.
+#
+# @@ That will probably become redundant when builtins and process obtain file
+# descriptors uniformly.
+#
+: builtins
+:
+{
+ echo "abc" >- : out-null
+ echo "abc" 1>&2 2>- : err-null
+ echo <foo 1>- : in-str
+ echo "foo" >foo : out-str
+ echo "foo" 2>foo 1>&2 : err-str
+ cat <foo >foo : inout-str # @@ cat is not a builtin yet.
+ cat <foo 2>foo 1>&2 : inerr-str
+}
diff --git a/tests/test/script/runner/status.test b/tests/test/script/runner/status.test
index 0ef1ee9..f1ad5bf 100644
--- a/tests/test/script/runner/status.test
+++ b/tests/test/script/runner/status.test
@@ -2,8 +2,43 @@
# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-$* # status-def @@ status- is already in file name
-$* == 0 # status-eq-0
-$* -s 1 != 0 # status-ne-0
-$* -s 1 == 1 # status-eq-1
-$* != 1 # status-ne-1
++mkdir build
++cat <<EOI >>>build/boostrap.build
+project = test
+amalgamation =
+
+using test
+EOI
+
+b = $build.driver -q --no-column --buildfile - <"./: test{testscript}" \
+ &?test/*** test
+c = cat >>>testscript
+test = \'$test\'
+
+# Successfull tests.
+#
+: eq-true
+:
+$c <"$* == 0";
+$b
+
+: ne-true
+:
+$c <"$* -s 1 != 0";
+$b
+
+# Faulty tests.
+#
+: eq-false
+:
+$c <"$* -s 1 == 0";
+$b 2>>EOE != 0
+testscript:1: error: ../../../driver$ext exit status 1 != 0
+EOE
+
+: ne-false
+:
+$c <"$* -s 1 != 1";
+$b 2>>EOE != 0
+testscript:1: error: ../../../driver$ext exit status 1 == 1
+EOE
diff --git a/tests/test/script/runner/touch.test b/tests/test/script/runner/touch.test
new file mode 100644
index 0000000..e9d9f68
--- /dev/null
+++ b/tests/test/script/runner/touch.test
@@ -0,0 +1,44 @@
+# file : tests/test/script/runner/touch.test
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+: file
+:
+touch a
+
+: file-create
+:
+: Test that file is created. If it didn't then 'rm' would fail.
+:
+touch a &!a;
+rm a
+
+: file-update
+:
+: Test that existing file touch doesn't register cleanup. If it did then it
+: would be left dangling after 'rm' call and so test would fail.
+:
+$* -f a;
+touch a;
+rm a
+
+: no-args
+:
+: Test passing no arguments.
+:
+touch 2>"touch: missing file" == 1
+
+: empty-path
+:
+: Test touching an empty path.
+:
+touch '' 2>"touch: invalid path ''" == 1
+
+: dir-update
+:
+: Test touching an existing directory.
+:
+a = [path] $~;
+a += "a";
+mkdir a;
+touch 2>"touch: '$a' exists and is not a file" a == 1