From 507c009c1ee68a4c3ad100f765bf854307d5bf39 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 15 Dec 2021 10:38:34 +0200 Subject: test: Fix "echo" subtest in the system_tests for Windows --- src/test/system_tests.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp index e97eab2c00..32aee2bce5 100644 --- a/src/test/system_tests.cpp +++ b/src/test/system_tests.cpp @@ -58,10 +58,8 @@ BOOST_AUTO_TEST_CASE(run_command) } { #ifdef WIN32 - // Windows requires single quotes to prevent escaping double quotes from the JSON... - const UniValue result = RunCommandParseJSON("echo '{\"success\": true}'"); + const UniValue result = RunCommandParseJSON("cmd.exe /c echo {\"success\": true}"); #else - // ... but Linux and macOS echo a single quote if it's used const UniValue result = RunCommandParseJSON("echo \"{\"success\": true}\""); #endif BOOST_CHECK(result.isObject()); -- cgit v1.2.3 From 0aad33db6410ed36fa0f4b96245cacbae7897d2e Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 15 Dec 2021 13:59:08 +0200 Subject: test: Fix "false" subtest in system_tests for Windows --- src/test/system_tests.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp index 32aee2bce5..3cb86de94d 100644 --- a/src/test/system_tests.cpp +++ b/src/test/system_tests.cpp @@ -37,12 +37,6 @@ bool checkMessage(const std::runtime_error& ex) return true; } -bool checkMessageFalse(const std::runtime_error& ex) -{ - BOOST_CHECK_EQUAL(ex.what(), std::string("RunCommandParseJSON error: process(false) returned 1: \n")); - return true; -} - bool checkMessageStdErr(const std::runtime_error& ex) { const std::string what(ex.what()); @@ -73,7 +67,15 @@ BOOST_AUTO_TEST_CASE(run_command) } { // Return non-zero exit code, no output to stderr - BOOST_CHECK_EXCEPTION(RunCommandParseJSON("false"), std::runtime_error, checkMessageFalse); +#ifdef WIN32 + const std::string command{"cmd.exe /c call"}; +#else + const std::string command{"false"}; +#endif + BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, [&](const std::runtime_error& e) { + BOOST_CHECK(std::string(e.what()).find(strprintf("RunCommandParseJSON error: process(%s) returned 1: \n", command)) != std::string::npos); + return true; + }); } { // Return non-zero exit code, with error message for stderr -- cgit v1.2.3 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: 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(-) (limited to 'src') 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 -- cgit v1.2.3 From edd0313ae7c94420642081c9172e349080bb9335 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 15 Dec 2021 13:21:33 +0200 Subject: test: Improve "invalid_command" subtest in system_tests for Windows No need to explain code with comments. --- src/test/system_tests.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp index 677edb133f..bdb4b4ed7f 100644 --- a/src/test/system_tests.cpp +++ b/src/test/system_tests.cpp @@ -28,15 +28,6 @@ BOOST_AUTO_TEST_CASE(dummy) #ifdef ENABLE_EXTERNAL_SIGNER -bool checkMessage(const std::runtime_error& ex) -{ - // On Linux & Mac: "No such file or directory" - // On Windows: "The system cannot find the file specified." - const std::string what(ex.what()); - BOOST_CHECK(what.find("file") != std::string::npos); - return true; -} - BOOST_AUTO_TEST_CASE(run_command) { { @@ -56,7 +47,17 @@ BOOST_AUTO_TEST_CASE(run_command) } { // An invalid command is handled by Boost - BOOST_CHECK_EXCEPTION(RunCommandParseJSON("invalid_command"), boost::process::process_error, checkMessage); // Command failed +#ifdef WIN32 + const std::string expected{"The system cannot find the file specified."}; +#else + const std::string expected{"No such file or directory"}; +#endif + BOOST_CHECK_EXCEPTION(RunCommandParseJSON("invalid_command"), boost::process::process_error, [&](const boost::process::process_error& e) { + const std::string what(e.what()); + BOOST_CHECK(what.find("RunCommandParseJSON error:") == std::string::npos); + BOOST_CHECK(what.find(expected) != std::string::npos); + return true; + }); } { // Return non-zero exit code, no output to stderr -- cgit v1.2.3