From 89424b41ef62430a49012c5c57b1979f29029505 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Nov 2016 08:50:12 +0200 Subject: Implement concurrent_runner --- tests/buildfile | 2 +- tests/test/buildfile | 7 ++++ tests/test/script/buildfile | 7 ++++ tests/test/script/driver.cxx | 76 ++++++++++++++++++++++++++++++++++++++++++++ tests/test/script/testscript | 42 ++++++++++++++++++++++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 tests/test/buildfile create mode 100644 tests/test/script/buildfile create mode 100644 tests/test/script/driver.cxx create mode 100644 tests/test/script/testscript (limited to 'tests') diff --git a/tests/buildfile b/tests/buildfile index 6367b5c..b6799d5 100644 --- a/tests/buildfile +++ b/tests/buildfile @@ -2,6 +2,6 @@ # copyright : Copyright (c) 2014-2016 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -d = +d = test/ ./: $d include $d diff --git a/tests/test/buildfile b/tests/test/buildfile new file mode 100644 index 0000000..0a98d5e --- /dev/null +++ b/tests/test/buildfile @@ -0,0 +1,7 @@ +# file : tests/test/buildfile +# copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +d = script/ +./: $d +include $d diff --git a/tests/test/script/buildfile b/tests/test/script/buildfile new file mode 100644 index 0000000..bf69e27 --- /dev/null +++ b/tests/test/script/buildfile @@ -0,0 +1,7 @@ +# file : tests/test/script/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/driver.cxx b/tests/test/script/driver.cxx new file mode 100644 index 0000000..b81172e --- /dev/null +++ b/tests/test/script/driver.cxx @@ -0,0 +1,76 @@ +// file : tests/test/script/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include // numeric_limits +#include +#include +#include // endl, *bit +#include +#include + +using namespace std; + +int +main (int argc, char* argv[]) +{ + // Usage: driver [-i ] [-s ] (-o )* (-e )* + // + 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::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/testscript b/tests/test/script/testscript new file mode 100644 index 0000000..b1cf0a5 --- /dev/null +++ b/tests/test/script/testscript @@ -0,0 +1,42 @@ +$* +$* -i 0 foo +$* -o foo >! +$* -e foo 2>! + +$* -o foo -o bar >>EOO +foo +bar +EOO + +$* -i 1 <>EOO +foo +bar +EOI +foo +bar +EOO + +$* -i 2 <>EOE +foo +bar +EOI +foo +bar +EOE + +$* -i 2 -s 1 <>EOE != 0 +foo +bar +EOI +foo +bar +EOE + +$* -i 2 -o baz -s 10 <baz 2>>EOE == 10 +foo +bar +EOI +foo +bar +EOE -- cgit v1.1