diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2023-05-26 14:30:05 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2023-05-26 15:25:32 (GMT) |
commit | 67bb1ee50cde981dd36f2b9964013c330f7e92fe (patch) | |
tree | 1e6e4484530ff28ccfb0827f0925393c3d81dafd /Tests | |
parent | cf7b7600c669ea162e0c3960c3e4e3a5d04f3274 (diff) | |
download | CMake-67bb1ee50cde981dd36f2b9964013c330f7e92fe.zip CMake-67bb1ee50cde981dd36f2b9964013c330f7e92fe.tar.gz CMake-67bb1ee50cde981dd36f2b9964013c330f7e92fe.tar.bz2 |
cmUVProcessChain: Add working directory option
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/CMakeLib/testUVProcessChain.cxx | 62 | ||||
-rw-r--r-- | Tests/CMakeLib/testUVProcessChainHelper.cxx | 7 |
3 files changed, 70 insertions, 0 deletions
diff --git a/Tests/CMakeLib/CMakeLists.txt b/Tests/CMakeLib/CMakeLists.txt index 0fc3deb..944b328 100644 --- a/Tests/CMakeLib/CMakeLists.txt +++ b/Tests/CMakeLib/CMakeLists.txt @@ -37,6 +37,7 @@ if (CMake_TEST_FILESYSTEM_PATH OR NOT CMake_HAVE_CXX_FILESYSTEM) endif() add_executable(testUVProcessChainHelper testUVProcessChainHelper.cxx) +target_link_libraries(testUVProcessChainHelper CMakeLib) set(testRST_ARGS ${CMAKE_CURRENT_SOURCE_DIR}) set(testUVProcessChain_ARGS $<TARGET_FILE:testUVProcessChainHelper>) diff --git a/Tests/CMakeLib/testUVProcessChain.cxx b/Tests/CMakeLib/testUVProcessChain.cxx index c924083..05262bc 100644 --- a/Tests/CMakeLib/testUVProcessChain.cxx +++ b/Tests/CMakeLib/testUVProcessChain.cxx @@ -11,6 +11,7 @@ #include <cm3p/uv.h> #include "cmGetPipes.h" +#include "cmStringAlgorithms.h" #include "cmUVHandlePtr.h" #include "cmUVProcessChain.h" #include "cmUVStreambuf.h" @@ -314,6 +315,57 @@ bool testUVProcessChainNone(const char* helperCommand) return true; } +bool testUVProcessChainCwdUnchanged(const char* helperCommand) +{ + cmUVProcessChainBuilder builder; + builder.AddCommand({ helperCommand, "pwd" }) + .SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT) + .SetBuiltinStream(cmUVProcessChainBuilder::Stream_ERROR); + + auto chain = builder.Start(); + chain.Wait(); + if (chain.GetStatus().front()->ExitStatus != 0) { + std::cout << "Exit status was " << chain.GetStatus().front()->ExitStatus + << ", expecting 0" << std::endl; + return false; + } + + auto cwd = getInput(*chain.OutputStream()); + if (!cmHasLiteralSuffix(cwd, "/Tests/CMakeLib")) { + std::cout << "Working directory was \"" << cwd + << "\", expected to end in \"/Tests/CMakeLib\"" << std::endl; + return false; + } + + return true; +} + +bool testUVProcessChainCwdChanged(const char* helperCommand) +{ + cmUVProcessChainBuilder builder; + builder.AddCommand({ helperCommand, "pwd" }) + .SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT) + .SetBuiltinStream(cmUVProcessChainBuilder::Stream_ERROR) + .SetWorkingDirectory(".."); + + auto chain = builder.Start(); + chain.Wait(); + if (chain.GetStatus().front()->ExitStatus != 0) { + std::cout << "Exit status was " << chain.GetStatus().front()->ExitStatus + << ", expecting 0" << std::endl; + return false; + } + + auto cwd = getInput(*chain.OutputStream()); + if (!cmHasLiteralSuffix(cwd, "/Tests")) { + std::cout << "Working directory was \"" << cwd + << "\", expected to end in \"/Tests\"" << std::endl; + return false; + } + + return true; +} + int testUVProcessChain(int argc, char** const argv) { if (argc < 2) { @@ -336,5 +388,15 @@ int testUVProcessChain(int argc, char** const argv) return -1; } + if (!testUVProcessChainCwdUnchanged(argv[1])) { + std::cout << "While executing testUVProcessChainCwdUnchanged().\n"; + return -1; + } + + if (!testUVProcessChainCwdChanged(argv[1])) { + std::cout << "While executing testUVProcessChainCwdChanged().\n"; + return -1; + } + return 0; } diff --git a/Tests/CMakeLib/testUVProcessChainHelper.cxx b/Tests/CMakeLib/testUVProcessChainHelper.cxx index bc0ef8e..82dafd2 100644 --- a/Tests/CMakeLib/testUVProcessChainHelper.cxx +++ b/Tests/CMakeLib/testUVProcessChainHelper.cxx @@ -7,6 +7,8 @@ #include <string> #include <thread> +#include "cmSystemTools.h" + static std::string getStdin() { char buffer[1024]; @@ -67,6 +69,11 @@ int main(int argc, char** argv) std::abort(); #endif } + if (command == "pwd") { + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + std::cout << cwd << std::flush; + return 0; + } return -1; } |