aboutsummaryrefslogtreecommitdiff
path: root/tests/test/script/runner
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-10-24 15:38:22 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:35 +0200
commit83c28bc98a3cb439c3dbb3824f4ede4eb14798a3 (patch)
tree1d2ac9c673278c1d854b0843719e05f58b07b503 /tests/test/script/runner
parent5bfa47e072eb0592a4df15dbf68ce3ea76383905 (diff)
Rename tests/test/script/ to tests/test/script/runner/
Diffstat (limited to 'tests/test/script/runner')
-rw-r--r--tests/test/script/runner/buildfile7
-rw-r--r--tests/test/script/runner/driver.cxx76
-rw-r--r--tests/test/script/runner/testscript72
3 files changed, 155 insertions, 0 deletions
diff --git a/tests/test/script/runner/buildfile b/tests/test/script/runner/buildfile
new file mode 100644
index 0000000..c91f940
--- /dev/null
+++ b/tests/test/script/runner/buildfile
@@ -0,0 +1,7 @@
+# file : tests/test/script/runner/buildfile
+# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+
+exe{driver}: cxx{driver} test{testscript}
+
+include ../../../../../build2/
diff --git a/tests/test/script/runner/driver.cxx b/tests/test/script/runner/driver.cxx
new file mode 100644
index 0000000..940a68c
--- /dev/null
+++ b/tests/test/script/runner/driver.cxx
@@ -0,0 +1,76 @@
+// file : tests/test/script/runner/driver.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <limits> // numeric_limits
+#include <string>
+#include <cassert>
+#include <ostream> // endl, *bit
+#include <iostream>
+#include <exception>
+
+using namespace std;
+
+int
+main (int argc, char* argv[])
+{
+ // Usage: driver [-i <int>] [-s <int>] (-o <string>)* (-e <string>)*
+ //
+ int status (256);
+ int ifd (3);
+
+ cout.exceptions (ostream::failbit | ostream::badbit);
+ cerr.exceptions (ostream::failbit | ostream::badbit);
+
+ for (int i (1); i < argc; ++i)
+ {
+ string o (argv[i++]);
+ assert (i < argc);
+
+ string v (argv[i]);
+
+ auto toi = [] (const string& s) -> int
+ {
+ try
+ {
+ return stoi (s);
+ }
+ catch (const exception&)
+ {
+ assert (false);
+ }
+ };
+
+ if (o == "-i")
+ {
+ assert (ifd == 3); // Make sure is not set yet.
+
+ ifd = toi (v);
+ assert (ifd >= 0 && ifd < 3);
+
+ if (ifd == 0)
+ cin.ignore (numeric_limits<streamsize>::max ());
+ else
+ (ifd == 1 ? cout : cerr) << cin.rdbuf ();
+ }
+ else if (o == "-o")
+ {
+ cout << v << endl;
+ }
+ else if (o == "-e")
+ {
+ cerr << v << endl;
+ }
+ else if (o == "-s")
+ {
+ assert (status == 256); // Make sure is not set yet.
+
+ status = toi (v);
+ assert (status >= 0 && status < 256);
+ }
+ else
+ assert (false);
+ }
+
+ return status == 256 ? 0 : status;
+}
diff --git a/tests/test/script/runner/testscript b/tests/test/script/runner/testscript
new file mode 100644
index 0000000..4d5d3b3
--- /dev/null
+++ b/tests/test/script/runner/testscript
@@ -0,0 +1,72 @@
+$*
+$* -i 0 <foo
+$* -o foo >foo
+$* -o foo >-
+$* -e foo 2>-
+
+$* -o foo -o bar >>EOO
+foo
+bar
+EOO
+
+$* -i 1 <<EOI >>EOO
+foo
+bar
+EOI
+foo
+bar
+EOO
+
+$* -i 2 <<EOI 2>>EOE
+foo
+bar
+EOI
+foo
+bar
+EOE
+
+$* -i 2 -s 1 <<EOI 2>>EOE != 0
+foo
+bar
+EOI
+foo
+bar
+EOE
+
+$* -i 2 -o baz -s 10 <<EOI 1>baz 2>>EOE == 10
+foo
+bar
+EOI
+foo
+bar
+EOE
+
+# No-newline tests.
+#
+# @@ TMP Need does not compare test.
+#
+$* -i 1 <:"foo" >:"foo" # no-newline-str
+#\
+$* -i 1 <:"foo" >!"foo" # no-newline-str-fail1
+$* -i 1 <"foo" >:!"foo" # no-newline-str-fail2
+#\
+
+$* -i 1 <<:EOI >>:EOO # no-newline-doc
+foo
+EOI
+foo
+EOO
+
+#\
+$* -i 1 <<:EOI >>!EOO # no-newline-doc-fail1
+foo
+EOI
+foo
+EOO
+
+$* -i 1 <<EOI >>:!EOO # no-newline-doc-fail2
+foo
+EOI
+foo
+EOO
+#\