From fb1b0590af138e317803893d2cab9dc887f33c5b Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 15 Dec 2021 14:02:46 +0200 Subject: [PATCH] test: Fix "non-zero exit code" subtest in system_tests for Windows --- src/test/system_tests.cpp | 21 +++++++++++++-------- 1 file 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