From 75e0334866c6cf8ada1aae215ea1fe42c9277963 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Wed, 6 Dec 2023 10:27:27 -0500 Subject: [PATCH] Merge bitcoin/bitcoin#28989: test: Fix test by checking the actual exception instance 55e3dc3e03510e97caba1547a82e3e022b0bbd42 test: Fix test by checking the actual exception instance (Hennadii Stepanov) Pull request description: The `system_tests/run_command` test is broken because it passes even with the diff as follows: ```diff --- a/src/test/system_tests.cpp +++ b/src/test/system_tests.cpp @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(run_command) }); } { - BOOST_REQUIRE_THROW(RunCommandParseJSON("echo \"{\""), std::runtime_error); // Unable to parse JSON + BOOST_REQUIRE_THROW(RunCommandParseJSON("invalid_command \"{\""), std::runtime_error); // Unable to parse JSON } // Test std::in, except for Windows #ifndef WIN32 ``` The reason of such fragility is that the [`BOOST_REQUIRE_THROW`](https://www.boost.org/doc/libs/1_83_0/libs/test/doc/html/boost_test/utf_reference/testing_tool_ref/assertion_boost_level_throw.html) macro passes even if the command raises an exception in the underlying subprocess implementation, which might have a type derived from `std::runtime_error`. ACKs for top commit: maflcko: lgtm ACK 55e3dc3e03510e97caba1547a82e3e022b0bbd42 achow101: ACK 55e3dc3e03510e97caba1547a82e3e022b0bbd42 furszy: Non-Windows code ACK 55e3dc3e pablomartin4btc: ACK 55e3dc3e03510e97caba1547a82e3e022b0bbd42 Tree-SHA512: 32f49421bdcc94744c81e82dc10cfa02e3f8ed111974edf1c2a47bdaeb56d7baec1bede67301cc89464fba613029ecb131dedc6bc5948777ab52f0f12df8bfe9 --- src/test/system_tests.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp index 6be41070c5..3f84aa837a 100644 --- a/src/test/system_tests.cpp +++ b/src/test/system_tests.cpp @@ -77,7 +77,13 @@ BOOST_AUTO_TEST_CASE(run_command) }); } { - BOOST_REQUIRE_THROW(RunCommandParseJSON("echo \"{\""), std::runtime_error); // Unable to parse JSON + // Unable to parse JSON +#ifdef WIN32 + const std::string command{"cmd.exe /c echo {"}; +#else + const std::string command{"echo {"}; +#endif + BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, HasReason("Unable to parse JSON: {")); } // Test std::in, except for Windows #ifndef WIN32