summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-05-30 13:41:26 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-05-30 13:41:35 (GMT)
commit150f0f19bc4832c27cf70bdbc56a87867ef60b84 (patch)
treec9271da6886a0563f33f4ced653bd08908b1b793 /Tests
parentf0e0eb63858489ecc33bed1d7e2539d75e932e8f (diff)
parent67bb1ee50cde981dd36f2b9964013c330f7e92fe (diff)
downloadCMake-150f0f19bc4832c27cf70bdbc56a87867ef60b84.zip
CMake-150f0f19bc4832c27cf70bdbc56a87867ef60b84.tar.gz
CMake-150f0f19bc4832c27cf70bdbc56a87867ef60b84.tar.bz2
Merge topic 'cmuvprocesschain-working-directory'
67bb1ee50c cmUVProcessChain: Add working directory option Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8512
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeLib/CMakeLists.txt1
-rw-r--r--Tests/CMakeLib/testUVProcessChain.cxx62
-rw-r--r--Tests/CMakeLib/testUVProcessChainHelper.cxx7
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;
}