summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeLib
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2023-06-01 15:52:40 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2023-06-05 15:27:45 (GMT)
commit154fe00ca56710d6fced4ab5c51f7edb162ea991 (patch)
treed08d2ce6d426343d2599d0124e94325a955300ea /Tests/CMakeLib
parent17a43ee192116f82b9dae494333f5e14b4553f87 (diff)
downloadCMake-154fe00ca56710d6fced4ab5c51f7edb162ea991.zip
CMake-154fe00ca56710d6fced4ab5c51f7edb162ea991.tar.gz
CMake-154fe00ca56710d6fced4ab5c51f7edb162ea991.tar.bz2
cmUVProcessChain: Add Status::GetException() method
Diffstat (limited to 'Tests/CMakeLib')
-rw-r--r--Tests/CMakeLib/testUVProcessChain.cxx70
-rw-r--r--Tests/CMakeLib/testUVProcessChainHelper.cxx9
2 files changed, 65 insertions, 14 deletions
diff --git a/Tests/CMakeLib/testUVProcessChain.cxx b/Tests/CMakeLib/testUVProcessChain.cxx
index ce6cd6d..7027689 100644
--- a/Tests/CMakeLib/testUVProcessChain.cxx
+++ b/Tests/CMakeLib/testUVProcessChain.cxx
@@ -4,6 +4,8 @@
#include <iostream>
#include <sstream>
#include <string>
+#include <type_traits>
+#include <utility>
#include <vector>
#include <cm/memory>
@@ -22,30 +24,62 @@ struct ExpectedStatus
bool MatchExitStatus;
bool MatchTermSignal;
cmUVProcessChain::Status Status;
+ cmUVProcessChain::ExceptionCode ExceptionCode;
+ std::string ExceptionString;
};
static const std::vector<ExpectedStatus> status1 = {
- { false, false, false, { 0, 0 } },
- { false, false, false, { 0, 0 } },
- { false, false, false, { 0, 0 } },
+ { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" },
+ { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" },
+ { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" },
};
static const std::vector<ExpectedStatus> status2 = {
- { true, true, true, { 0, 0 } },
- { false, false, false, { 0, 0 } },
- { false, false, false, { 0, 0 } },
+ { true, true, true, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" },
+ { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" },
+ { false, false, false, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" },
};
static const std::vector<ExpectedStatus> status3 = {
- { true, true, true, { 0, 0 } },
- { true, true, true, { 1, 0 } },
+ { true, true, true, { 0, 0 }, cmUVProcessChain::ExceptionCode::None, "" },
+ { true, true, true, { 1, 0 }, cmUVProcessChain::ExceptionCode::None, "" },
#ifdef _WIN32
- { true, true, true, { 2, 0 } },
+ { true,
+ true,
+ true,
+ { STATUS_ACCESS_VIOLATION, 0 },
+ cmUVProcessChain::ExceptionCode::Fault,
+ "Access violation" },
#else
- { true, false, true, { 0, SIGABRT } },
+ { true,
+ false,
+ true,
+ { 0, SIGABRT },
+ cmUVProcessChain::ExceptionCode::Other,
+ "Subprocess aborted" },
#endif
};
+static const char* ExceptionCodeToString(cmUVProcessChain::ExceptionCode code)
+{
+ switch (code) {
+ case cmUVProcessChain::ExceptionCode::None:
+ return "None";
+ case cmUVProcessChain::ExceptionCode::Fault:
+ return "Fault";
+ case cmUVProcessChain::ExceptionCode::Illegal:
+ return "Illegal";
+ case cmUVProcessChain::ExceptionCode::Interrupt:
+ return "Interrupt";
+ case cmUVProcessChain::ExceptionCode::Numerical:
+ return "Numerical";
+ case cmUVProcessChain::ExceptionCode::Other:
+ return "Other";
+ default:
+ return "";
+ }
+}
+
bool operator==(const cmUVProcessChain::Status* actual,
const ExpectedStatus& expected)
{
@@ -62,6 +96,11 @@ bool operator==(const cmUVProcessChain::Status* actual,
expected.Status.TermSignal != actual->TermSignal) {
return false;
}
+ if (expected.Finished &&
+ std::make_pair(expected.ExceptionCode, expected.ExceptionString) !=
+ actual->GetException()) {
+ return false;
+ }
return true;
}
@@ -116,6 +155,11 @@ static void printResults(
<< printExpected(e.MatchExitStatus, e.Status.ExitStatus)
<< ", TermSignal: "
<< printExpected(e.MatchTermSignal, e.Status.TermSignal)
+ << ", ExceptionCode: "
+ << printExpected(e.Finished,
+ ExceptionCodeToString(e.ExceptionCode))
+ << ", ExceptionString: \""
+ << printExpected(e.Finished, e.ExceptionString) << '"'
<< std::endl;
} else {
std::cout << " null" << std::endl;
@@ -124,8 +168,12 @@ static void printResults(
std::cout << "Actual:" << std::endl;
for (auto const& a : actual) {
if (a) {
+ auto exception = a->GetException();
std::cout << " ExitStatus: " << a->ExitStatus
- << ", TermSignal: " << a->TermSignal << std::endl;
+ << ", TermSignal: " << a->TermSignal << ", ExceptionCode: "
+ << ExceptionCodeToString(exception.first)
+ << ", ExceptionString: \"" << exception.second << '"'
+ << std::endl;
} else {
std::cout << " null" << std::endl;
}
diff --git a/Tests/CMakeLib/testUVProcessChainHelper.cxx b/Tests/CMakeLib/testUVProcessChainHelper.cxx
index 82dafd2..99743e7 100644
--- a/Tests/CMakeLib/testUVProcessChainHelper.cxx
+++ b/Tests/CMakeLib/testUVProcessChainHelper.cxx
@@ -7,6 +7,10 @@
#include <string>
#include <thread>
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
#include "cmSystemTools.h"
static std::string getStdin()
@@ -61,10 +65,9 @@ int main(int argc, char** argv)
}
// On Windows, the exit code of abort() is different between debug and
- // release builds, and does not yield a term_signal in libuv in either
- // case. For the sake of simplicity, we just return another non-zero code.
+ // release builds. Instead, simulate an access violation.
#ifdef _WIN32
- return 2;
+ return STATUS_ACCESS_VIOLATION;
#else
std::abort();
#endif