diff options
Diffstat (limited to 'tests/process-run')
-rw-r--r-- | tests/process-run/buildfile | 7 | ||||
-rw-r--r-- | tests/process-run/driver.cxx | 91 | ||||
-rw-r--r-- | tests/process-run/testscript | 14 |
3 files changed, 112 insertions, 0 deletions
diff --git a/tests/process-run/buildfile b/tests/process-run/buildfile new file mode 100644 index 0000000..5c55af9 --- /dev/null +++ b/tests/process-run/buildfile @@ -0,0 +1,7 @@ +# file : tests/process-run/buildfile +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +exe{driver}: cxx{driver} ../../butl/lib{butl} test{testscript} + +include ../../butl/ diff --git a/tests/process-run/driver.cxx b/tests/process-run/driver.cxx new file mode 100644 index 0000000..15d5f61 --- /dev/null +++ b/tests/process-run/driver.cxx @@ -0,0 +1,91 @@ +// file : tests/process-run/driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <iostream> + +#include <butl/path> +#include <butl/process> +#include <butl/fdstream> + +using namespace std; +using namespace butl; + +template <typename I, + typename O, + typename E, + typename P, + typename... A> +process_exit +run (I&& in, + O&& out, + E&& err, + const P& p, + A&&... args) +{ + return process_run (forward<I> (in), + forward<O> (out), + forward<E> (err), + dir_path (), + p, + forward<A> (args)...); +} + +int +main (int argc, const char* argv[]) +{ + if (argc < 2) // No argument test. + return 0; + + string a (argv[1]); + + if (a == "-c") + { + // -i read from stdin + // -o write argument to stdout + // -e write argument to stderr + // -x exit with argument + // + for (int i (2); i != argc; ++i) + { + a = argv[i]; + + if (a == "-i") cin >> a; + else if (a == "-o") cout << argv[++i] << endl; + else if (a == "-e") cerr << argv[++i] << endl; + else if (a == "-x") return atoi (argv[++i]); + } + + return 0; + } + else + assert (a == "-p"); + + const string p (argv[0]); + + assert (run (0, 1, 2, p)); + assert (run (0, 1, 2, p, "-c")); + + process_run ([] (const char* c[], size_t n) + { + process::print (cout, c, n); + cout << endl; + }, + 0, 1, 2, + dir_path (), + p, + "-c"); + + // Stream conversion and redirection. + // + assert (run (fdnull (), 1, 2, p, "-c", "-i")); + assert (run (fdnull (), 2, 2, p, "-c", "-o", "abc")); + assert (run (fdnull (), 1, 1, p, "-c", "-e", "abc")); + + // Argument conversion. + // + assert (run (0, 1, 2, p, "-c", "-o", "abc")); + assert (run (0, 1, 2, p, "-c", "-o", string ("abc"))); + assert (run (0, 1, 2, p, "-c", "-o", path ("abc"))); + assert (run (0, 1, 2, p, "-c", "-o", 123)); +} diff --git a/tests/process-run/testscript b/tests/process-run/testscript new file mode 100644 index 0000000..49abac4 --- /dev/null +++ b/tests/process-run/testscript @@ -0,0 +1,14 @@ +# file : tests/process-run/testscript +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +$* -p >>"EOO" 2>>EOE +$0 -c +abc +abc +abc +abc +123 +EOO +abc +EOE |