From 5a36f357e174d002722122d2408c57fb43da6e59 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 21 Apr 2017 09:17:01 +0200 Subject: Implement execution of Windows batch files --- tests/process/buildfile | 2 +- tests/process/driver.cxx | 25 +++++++++++++++++++++++-- tests/process/testscript | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 tests/process/testscript (limited to 'tests') diff --git a/tests/process/buildfile b/tests/process/buildfile index ae765c4..72cbec2 100644 --- a/tests/process/buildfile +++ b/tests/process/buildfile @@ -2,6 +2,6 @@ # copyright : Copyright (c) 2014-2017 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -exe{driver}: cxx{driver} ../../butl/lib{butl} +exe{driver}: cxx{driver} ../../butl/lib{butl} test{testscript} include ../../butl/ diff --git a/tests/process/driver.cxx b/tests/process/driver.cxx index fc9ffe9..ae5015c 100644 --- a/tests/process/driver.cxx +++ b/tests/process/driver.cxx @@ -143,10 +143,11 @@ exec (const path& p, } catch (const process_error& e) { + //cerr << args[0] << ": " << e << endl; + if (e.child) exit (1); - //cerr << args[0] << ": " << e << endl; return false; } } @@ -176,6 +177,7 @@ main (int argc, const char* argv[]) for (; i != argc; ++i) { string v (argv[i]); + if (v == "-c") child = true; else if (v == "-b") @@ -254,6 +256,8 @@ main (int argc, const char* argv[]) return 0; } + dir_path owd (dir_path::current_directory ()); + // Test processes created as "already terminated". // { @@ -309,7 +313,7 @@ main (int argc, const char* argv[]) assert (exec (dir_path (".") / fp.leaf ())); - // Fail for unexistent file path. + // Fail for non-existent file path. // assert (!exec (dir_path (".") / path ("dr"))); @@ -343,4 +347,21 @@ main (int argc, const char* argv[]) pr.handle = reinterpret_cast (-1); assert (!pr.wait (true) && !pr.wait (false)); #endif + + // Test execution of Windows batch files. The test file is in the original + // working directory. + // +#ifdef _WIN32 + { + assert (exec (owd / "test.bat")); + assert (exec (owd / "test")); + + paths = owd.string () + path::traits::path_separator + paths; + assert (_putenv (("PATH=" + paths).c_str ()) == 0); + + assert (exec (path ("test.bat"))); + assert (exec (path ("test"))); + assert (!exec (path ("testX.bat"))); + } +#endif } diff --git a/tests/process/testscript b/tests/process/testscript new file mode 100644 index 0000000..c734a05 --- /dev/null +++ b/tests/process/testscript @@ -0,0 +1,17 @@ +# file : tests/process/testscript +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +if ($cxx.target.class == 'windows') + cat <=test.bat + @echo off + setlocal + goto end + :error + endlocal + exit /b 1 + :end + endlocal + EOI +end; +$* -- cgit v1.1