diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2021-12-15 14:02:46 +0200 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2021-12-15 14:09:31 +0200 |
commit | fb1b0590af138e317803893d2cab9dc887f33c5b (patch) | |
tree | cd914053a468b7da8093d441fa02ac8304649a3f /src/test/system_tests.cpp | |
parent | 0aad33db6410ed36fa0f4b96245cacbae7897d2e (diff) |
test: Fix "non-zero exit code" subtest in system_tests for Windows
Diffstat (limited to 'src/test/system_tests.cpp')
-rw-r--r-- | src/test/system_tests.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp index 3cb86de94d..677edb133f 100644 --- a/src/test/system_tests.cpp +++ b/src/test/system_tests.cpp @@ -37,13 +37,6 @@ bool checkMessage(const std::runtime_error& ex) return true; } -bool checkMessageStdErr(const std::runtime_error& ex) -{ - const std::string what(ex.what()); - BOOST_CHECK(what.find("RunCommandParseJSON error:") != std::string::npos); - return checkMessage(ex); -} - BOOST_AUTO_TEST_CASE(run_command) { { @@ -79,7 +72,19 @@ BOOST_AUTO_TEST_CASE(run_command) } { // Return non-zero exit code, with error message for stderr - BOOST_CHECK_EXCEPTION(RunCommandParseJSON("ls nosuchfile"), std::runtime_error, checkMessageStdErr); +#ifdef WIN32 + const std::string command{"cmd.exe /c dir nosuchfile"}; + const std::string expected{"File Not Found"}; +#else + const std::string command{"ls nosuchfile"}; + const std::string expected{"No such file or directory"}; +#endif + BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) { + const std::string what(e.what()); + BOOST_CHECK(what.find(strprintf("RunCommandParseJSON error: process(%s) returned", command)) != std::string::npos); + BOOST_CHECK(what.find(expected) != std::string::npos); + return true; + }); } { BOOST_REQUIRE_THROW(RunCommandParseJSON("echo \"{\""), std::runtime_error); // Unable to parse JSON |