Skip to content

Commit fb1b059

Browse files
committed
test: Fix "non-zero exit code" subtest in system_tests for Windows
1 parent 0aad33d commit fb1b059

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/test/system_tests.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ bool checkMessage(const std::runtime_error& ex)
3737
return true;
3838
}
3939

40-
bool checkMessageStdErr(const std::runtime_error& ex)
41-
{
42-
const std::string what(ex.what());
43-
BOOST_CHECK(what.find("RunCommandParseJSON error:") != std::string::npos);
44-
return checkMessage(ex);
45-
}
46-
4740
BOOST_AUTO_TEST_CASE(run_command)
4841
{
4942
{
@@ -79,7 +72,19 @@ BOOST_AUTO_TEST_CASE(run_command)
7972
}
8073
{
8174
// Return non-zero exit code, with error message for stderr
82-
BOOST_CHECK_EXCEPTION(RunCommandParseJSON("ls nosuchfile"), std::runtime_error, checkMessageStdErr);
75+
#ifdef WIN32
76+
const std::string command{"cmd.exe /c dir nosuchfile"};
77+
const std::string expected{"File Not Found"};
78+
#else
79+
const std::string command{"ls nosuchfile"};
80+
const std::string expected{"No such file or directory"};
81+
#endif
82+
BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) {
83+
const std::string what(e.what());
84+
BOOST_CHECK(what.find(strprintf("RunCommandParseJSON error: process(%s) returned", command)) != std::string::npos);
85+
BOOST_CHECK(what.find(expected) != std::string::npos);
86+
return true;
87+
});
8388
}
8489
{
8590
BOOST_REQUIRE_THROW(RunCommandParseJSON("echo \"{\""), std::runtime_error); // Unable to parse JSON

0 commit comments

Comments
 (0)