Skip to content

Commit 9693cfa

Browse files
committed
Merge bitcoin/bitcoin#28989: test: Fix test by checking the actual exception instance
55e3dc3 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 55e3dc3 achow101: ACK 55e3dc3 furszy: Non-Windows code ACK 55e3dc3 pablomartin4btc: ACK 55e3dc3 Tree-SHA512: 32f49421bdcc94744c81e82dc10cfa02e3f8ed111974edf1c2a47bdaeb56d7baec1bede67301cc89464fba613029ecb131dedc6bc5948777ab52f0f12df8bfe9
2 parents dde7ac5 + 55e3dc3 commit 9693cfa

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/test/system_tests.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ BOOST_AUTO_TEST_CASE(run_command)
9090
});
9191
}
9292
{
93-
BOOST_REQUIRE_THROW(RunCommandParseJSON("echo \"{\""), std::runtime_error); // Unable to parse JSON
93+
// Unable to parse JSON
94+
#ifdef WIN32
95+
const std::string command{"cmd.exe /c echo {"};
96+
#else
97+
const std::string command{"echo {"};
98+
#endif
99+
BOOST_CHECK_EXCEPTION(RunCommandParseJSON(command), std::runtime_error, HasReason("Unable to parse JSON: {"));
94100
}
95101
// Test std::in, except for Windows
96102
#ifndef WIN32

0 commit comments

Comments
 (0)