aboutsummaryrefslogtreecommitdiff
path: root/tests/process/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-04-06 16:19:38 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2020-04-07 15:08:30 +0300
commitca0fa738650ab546b1422e0b2dbfdc89ba8eb5a3 (patch)
tree5e9fe6a4d8b419ab8fd94cc0614d76d2a7376028 /tests/process/driver.cxx
parent5fba51e990e7111c7dc125c1115ac7b5de4025be (diff)
Add ability to print process_env environment
Diffstat (limited to 'tests/process/driver.cxx')
-rw-r--r--tests/process/driver.cxx36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/process/driver.cxx b/tests/process/driver.cxx
index 7a0f38b..3be4154 100644
--- a/tests/process/driver.cxx
+++ b/tests/process/driver.cxx
@@ -7,6 +7,7 @@
#include <ios>
#include <string>
#include <vector>
+#include <sstream>
#include <iterator> // istreambuf_iterator, ostream_iterator
#include <algorithm> // copy()
#include <iostream>
@@ -28,6 +29,7 @@ import butl.fdstream;
#include <libbutl/path.mxx>
#include <libbutl/utility.mxx>
#include <libbutl/process.mxx>
+#include <libbutl/process-io.mxx>
#include <libbutl/optional.mxx>
#include <libbutl/fdstream.mxx>
#endif
@@ -474,4 +476,38 @@ main (int argc, const char* argv[])
assert (!exec (path ("testX.bat")));
}
#endif
+
+ // Test printing process_env to stream.
+ //
+ {
+ auto str = [] (const process_env& env)
+ {
+ ostringstream os;
+ os << env;
+ return os.str ();
+ };
+
+ process_path p;
+
+ assert (str (process_env (p)) == "");
+
+ {
+ dir_path d ("dir");
+ dir_path ds ("d ir");
+ assert (str (process_env (p, d)) == "PWD=dir");
+ assert (str (process_env (p, ds)) == "PWD=\"d ir\"");
+ }
+
+ {
+ dir_path ed; // Empty.
+ const char* vars[] = {nullptr};
+ assert (str (process_env (p, ed, vars)) == "");
+ }
+
+ {
+ const char* vars[] = {"A=B", "A=B C", "A B=C", "A", "A B", nullptr};
+ assert (str (process_env (p, vars)) ==
+ "A=B A=\"B C\" \"A B=C\" A= \"A B=\"");
+ }
+ }
}