aboutsummaryrefslogtreecommitdiff
path: root/tests/process/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-06-14 18:13:04 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2018-06-15 14:21:58 +0300
commit481f9ba1aee62fea092184f2243d210a8686781f (patch)
treea54fc536d835c5277038e145fabc1255c42ff8ac /tests/process/driver.cxx
parent5d424ea127333859a32addaf9e28eae07a4dc9f6 (diff)
Add portable environment variable manipulation functions
Diffstat (limited to 'tests/process/driver.cxx')
-rw-r--r--tests/process/driver.cxx35
1 files changed, 14 insertions, 21 deletions
diff --git a/tests/process/driver.cxx b/tests/process/driver.cxx
index 9bee6c5..6ca28a5 100644
--- a/tests/process/driver.cxx
+++ b/tests/process/driver.cxx
@@ -2,8 +2,6 @@
// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-#include <stdlib.h> // getenv(), setenv(), _putenv()
-
#include <cassert>
#ifndef __cpp_lib_modules
@@ -23,11 +21,13 @@ import std.core;
import std.io;
#endif
import butl.path;
+import butl.utility; // setenv(), getenv()
import butl.process;
import butl.optional;
import butl.fdstream;
#else
#include <libbutl/path.mxx>
+#include <libbutl/utility.mxx>
#include <libbutl/process.mxx>
#include <libbutl/optional.mxx>
#include <libbutl/fdstream.mxx>
@@ -68,13 +68,8 @@ exec (const path& p,
// sure that the child process will not see the variable that is requested
// to be unset, and will see the other one unaffected.
//
-#ifndef _WIN32
- assert (setenv ("DEF", "2", 1) == 0);
- assert (setenv ("XYZ", "3", 1) == 0);
-#else
- assert (_putenv ("DEF=2") == 0);
- assert (_putenv ("XYZ=3") == 0);
-#endif
+ setenv ("DEF", "2");
+ setenv ("XYZ", "3");
}
if (cwd != nullptr)
@@ -205,6 +200,9 @@ exec (const path& p,
int
main (int argc, const char* argv[])
{
+ using butl::getenv;
+ using butl::optional;
+
bool child (false);
bool bin (false);
dir_path wd; // Working directory.
@@ -276,10 +274,9 @@ main (int argc, const char* argv[])
// Check that the ABC variable is set, the DEF is unset and the XYZ is
// left unchanged.
//
- const char* v;
- if ((v = getenv ("ABC")) == nullptr || string ("1") != v ||
- getenv ("DEF") != nullptr ||
- (v = getenv ("XYZ")) == nullptr || string ("3") != v)
+ if (getenv ("ABC") != optional<string> ("1") ||
+ getenv ("DEF") ||
+ getenv ("XYZ") != optional<string> ("3"))
return 1;
}
@@ -383,14 +380,10 @@ main (int argc, const char* argv[])
//
string paths (fp.directory ().string ());
- if (char const* s = getenv ("PATH"))
- paths += string (1, path::traits::path_separator) + s;
+ if (optional<string> p = getenv ("PATH"))
+ paths += string (1, path::traits::path_separator) + *p;
-#ifndef _WIN32
- assert (setenv ("PATH", paths.c_str (), 1) == 0);
-#else
- assert (_putenv (("PATH=" + paths).c_str ()) == 0);
-#endif
+ setenv ("PATH", paths);
dir_path::current_directory (fp.directory () / dir_path (".."));
@@ -419,7 +412,7 @@ main (int argc, const char* argv[])
assert (exec (owd / "test"));
paths = owd.string () + path::traits::path_separator + paths;
- assert (_putenv (("PATH=" + paths).c_str ()) == 0);
+ setenv ("PATH", paths);
assert (exec (path ("test.bat")));
assert (exec (path ("test")));