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/CMakeLib/testUVProcessChain.cxx | |
parent | cf7b7600c669ea162e0c3960c3e4e3a5d04f3274 (diff) | |
download | CMake-67bb1ee50cde981dd36f2b9964013c330f7e92fe.zip CMake-67bb1ee50cde981dd36f2b9964013c330f7e92fe.tar.gz CMake-67bb1ee50cde981dd36f2b9964013c330f7e92fe.tar.bz2 |
cmUVProcessChain: Add working directory option
Diffstat (limited to 'Tests/CMakeLib/testUVProcessChain.cxx')
-rw-r--r-- | Tests/CMakeLib/testUVProcessChain.cxx | 62 |
1 files changed, 62 insertions, 0 deletions
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; } |