diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-04-21 09:17:01 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-04-21 09:17:01 +0200 |
commit | 5a36f357e174d002722122d2408c57fb43da6e59 (patch) | |
tree | 4d31e5ac43a3013426d26f48e7a42850c2aa8aea /tests | |
parent | 083834dcc5b76fe6f1318eb2b91c5caf08cd0c5f (diff) |
Implement execution of Windows batch files
Diffstat (limited to 'tests')
-rw-r--r-- | tests/process/buildfile | 2 | ||||
-rw-r--r-- | tests/process/driver.cxx | 25 | ||||
-rw-r--r-- | tests/process/testscript | 17 |
3 files changed, 41 insertions, 3 deletions
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<process::handle_type> (-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 <<EOI >=test.bat + @echo off + setlocal + goto end + :error + endlocal + exit /b 1 + :end + endlocal + EOI +end; +$* |