Skip to content

Commit 6e5fc2b

Browse files
committed
test: Reintroduce Windows support in system_tests/run_command test
1 parent 53ccb75 commit 6e5fc2b

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/test/system_tests.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,32 @@ BOOST_AUTO_TEST_CASE(run_command)
2525
BOOST_CHECK(result.isNull());
2626
}
2727
{
28+
#ifdef WIN32
29+
const UniValue result = RunCommandParseJSON("cmd.exe /c echo {\"success\": true}");
30+
#else
2831
const UniValue result = RunCommandParseJSON("echo {\"success\": true}");
32+
#endif
2933
BOOST_CHECK(result.isObject());
3034
const UniValue& success = result.find_value("success");
3135
BOOST_CHECK(!success.isNull());
3236
BOOST_CHECK_EQUAL(success.get_bool(), true);
3337
}
3438
{
3539
// An invalid command is handled by cpp-subprocess
40+
#ifdef WIN32
41+
const std::string expected{"CreateProcess failed: "};
42+
#else
3643
const std::string expected{"execve failed: "};
44+
#endif
3745
BOOST_CHECK_EXCEPTION(RunCommandParseJSON("invalid_command"), subprocess::CalledProcessError, HasReason(expected));
3846
}
3947
{
4048
// Return non-zero exit code, no output to stderr
49+
#ifdef WIN32
50+
const std::string command{"cmd.exe /c exit 1"};
51+
#else
4152
const std::string command{"false"};
53+
#endif
4254
BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) {
4355
const std::string what{e.what()};
4456
BOOST_CHECK(what.find(strprintf("RunCommandParseJSON error: process(%s) returned 1: \n", command)) != std::string::npos);
@@ -47,7 +59,11 @@ BOOST_AUTO_TEST_CASE(run_command)
4759
}
4860
{
4961
// Return non-zero exit code, with error message for stderr
62+
#ifdef WIN32
63+
const std::string command{"cmd.exe /c \"echo err 1>&2 && exit 1\""};
64+
#else
5065
const std::string command{"sh -c 'echo err 1>&2 && false'"};
66+
#endif
5167
const std::string expected{"err"};
5268
BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) {
5369
const std::string what(e.what());
@@ -58,17 +74,23 @@ BOOST_AUTO_TEST_CASE(run_command)
5874
}
5975
{
6076
// Unable to parse JSON
77+
#ifdef WIN32
78+
const std::string command{"cmd.exe /c echo {"};
79+
#else
6180
const std::string command{"echo {"};
81+
#endif
6282
BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, HasReason("Unable to parse JSON: {"));
6383
}
64-
// Test std::in
84+
#ifndef WIN32
6585
{
86+
// Test stdin
6687
const UniValue result = RunCommandParseJSON("cat", "{\"success\": true}");
6788
BOOST_CHECK(result.isObject());
6889
const UniValue& success = result.find_value("success");
6990
BOOST_CHECK(!success.isNull());
7091
BOOST_CHECK_EQUAL(success.get_bool(), true);
7192
}
93+
#endif
7294
}
7395
#endif // ENABLE_EXTERNAL_SIGNER
7496

0 commit comments

Comments
 (0)