aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-12-06 10:27:27 -0500
committerAndrew Chow <github@achow101.com>2023-12-06 10:33:29 -0500
commit9693cfa0a422030147cd4a57d3da92749d1b0e95 (patch)
tree1f5238231963b6bf5b802b7cb4b1605ef52b45da /src
parentdde7ac5c704688c8a9af29bd07e5ae8114824ce7 (diff)
parent55e3dc3e03510e97caba1547a82e3e022b0bbd42 (diff)
downloadbitcoin-9693cfa0a422030147cd4a57d3da92749d1b0e95.tar.xz
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
Diffstat (limited to 'src')
-rw-r--r--src/test/system_tests.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp
index 740f461548..6a96b60db0 100644
--- a/src/test/system_tests.cpp
+++ b/src/test/system_tests.cpp
@@ -90,7 +90,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