aboutsummaryrefslogtreecommitdiff
path: root/tests/test/script/runner/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test/script/runner/driver.cxx')
-rw-r--r--tests/test/script/runner/driver.cxx158
1 files changed, 97 insertions, 61 deletions
diff --git a/tests/test/script/runner/driver.cxx b/tests/test/script/runner/driver.cxx
index d5a74a4..b84f167 100644
--- a/tests/test/script/runner/driver.cxx
+++ b/tests/test/script/runner/driver.cxx
@@ -1,19 +1,29 @@
// file : tests/test/script/runner/driver.cxx -*- C++ -*-
// license : MIT; see accompanying LICENSE file
+#ifndef _WIN32
+# include <thread> // this_thread::sleep_for()
+# include <chrono>
+#else
+# include <libbutl/win32-utility.hxx>
+#endif
+
#include <limits> // numeric_limits
#include <string>
#include <cstdlib> // abort()
-#include <cassert>
#include <ostream> // endl, *bit
#include <istream> // istream::traits_type::eof()
#include <iostream>
#include <exception>
-#include <libbutl/path.mxx>
-#include <libbutl/optional.mxx>
-#include <libbutl/fdstream.mxx>
-#include <libbutl/filesystem.mxx>
+#include <libbutl/path.hxx>
+#include <libbutl/path-io.hxx>
+#include <libbutl/optional.hxx>
+#include <libbutl/fdstream.hxx>
+#include <libbutl/filesystem.hxx>
+
+#undef NDEBUG
+#include <cassert>
using namespace std;
using namespace butl;
@@ -36,10 +46,10 @@ main (int argc, char* argv[])
// Usage: driver [-i <int>] (-o <string>)* (-e <string>)* (-f <file>)*
// (-d <dir>)* (-v <name>)* [(-t (a|m|s|z)) | (-s <int>)]
//
- // Execute actions specified by -i, -o, -e, -f, -d, and -v options in the
- // order as they appear on the command line. After that terminate abnormally
- // if -t option is provided, otherwise exit normally with the status
- // specified by -s option (0 by default).
+ // Execute actions specified by -i, -o, -e, -f, -d, -w, -v, and -l options
+ // in the order as they appear on the command line. After that terminate
+ // abnormally if -t option is provided, otherwise exit normally with the
+ // status specified by -s option (0 by default).
//
// -i <fd>
// Forward stdin data to the standard stream denoted by the file
@@ -58,9 +68,15 @@ main (int argc, char* argv[])
// Create a directory with the path specified. Create parent directories
// if required.
//
+ // -w
+ // Print CWD to stdout.
+ //
// -v <name>
- // If the specified variable is set the print its value to stdout and the
- // string '<none>' otherwise.
+ // If the specified variable is set then print its value to stdout and
+ // the string '<none>' otherwise.
+ //
+ // -l <sec>
+ // Sleep the specified number of seconds.
//
// -t <method>
// Abnormally terminate itself using one of the following methods:
@@ -83,10 +99,7 @@ main (int argc, char* argv[])
for (int i (1); i < argc; ++i)
{
- string o (argv[i++]);
- assert (i < argc);
-
- string v (argv[i]);
+ string o (argv[i]);
auto toi = [] (const string& s) -> int
{
@@ -106,57 +119,80 @@ main (int argc, char* argv[])
return r;
};
- if (o == "-i")
+ if (o == "-w")
{
- assert (ifd == 3); // Make sure is not set yet.
-
- ifd = toi (v);
- assert (ifd >= 0 && ifd < 3);
+ cout << dir_path::current_directory () << endl;
+ }
+ else // Handle options other than flags.
+ {
+ ++i;
+ assert (i < argc);
+ string v (argv[i]);
- if (ifd == 0)
- cin.ignore (numeric_limits<streamsize>::max ());
- else if (cin.peek () != istream::traits_type::eof ())
+ if (o == "-i")
{
- ostream& o (ifd == 1 ? cout : cerr);
- o << cin.rdbuf ();
- o.flush ();
+ 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 if (cin.peek () != istream::traits_type::eof ())
+ {
+ ostream& o (ifd == 1 ? cout : cerr);
+ o << cin.rdbuf ();
+ o.flush ();
+ }
}
+ else if (o == "-o")
+ {
+ cout << v << endl;
+ }
+ else if (o == "-e")
+ {
+ cerr << v << endl;
+ }
+ else if (o == "-f")
+ {
+ ofdstream os (v);
+ os.close ();
+ }
+ else if (o == "-d")
+ {
+ try_mkdir_p (dir_path (v));
+ }
+ else if (o == "-v")
+ {
+ optional<string> var (getenv (v));
+ cout << (var ? *var : "<none>") << endl;
+ }
+ else if (o == "-l")
+ {
+ size_t t (toi (v));
+
+ // MinGW GCC 4.9 doesn't implement this_thread so use Win32 Sleep().
+ //
+#ifndef _WIN32
+ this_thread::sleep_for (chrono::seconds (t));
+#else
+ Sleep (static_cast<DWORD> (t * 1000));
+#endif
+ }
+ else if (o == "-t")
+ {
+ assert (aterm == '\0' && !status); // Make sure exit method is not set.
+ assert (v.size () == 1 && v.find_first_of ("amsz") != string::npos);
+ aterm = v[0];
+ }
+ else if (o == "-s")
+ {
+ assert (!status && aterm == '\0'); // Make sure exit method is not set.
+ status = toi (v);
+ }
+ else
+ assert (false);
}
- else if (o == "-o")
- {
- cout << v << endl;
- }
- else if (o == "-e")
- {
- cerr << v << endl;
- }
- else if (o == "-f")
- {
- ofdstream os (v);
- os.close ();
- }
- else if (o == "-d")
- {
- try_mkdir_p (dir_path (v));
- }
- else if (o == "-v")
- {
- optional<string> var (getenv (v));
- cout << (var ? *var : "<none>") << endl;
- }
- else if (o == "-t")
- {
- assert (aterm == '\0' && !status); // Make sure exit method is not set.
- assert (v.size () == 1 && v.find_first_of ("amsz") != string::npos);
- aterm = v[0];
- }
- else if (o == "-s")
- {
- assert (!status && aterm == '\0'); // Make sure exit method is not set.
- status = toi (v);
- }
- else
- assert (false);
}
switch (aterm)