Skip to content

Commit e653eef

Browse files
committed
Merge #16277: [Tests] Suppress output in test_bitcoin for expected errors
7a0c224 Suppress output in test_bitcoin for expected errors (Gert-Jaap Glasbergen) Pull request description: Closes #15944 This adds two methods to noui, that allows temporarily suppressing (and then resuming) the output from `noui`. For situations where errors are expected, it's confusing for the test binary to output an error and then conclude with `No errors detected`. It also uses this supress/reconnect in the tests that currently produce verbose errors when running `test_bitcoin`. Output of `test_bitcoin` on current master: ``` gertjaap@gjdesktop:~/src/bitcoin$ src/test/test_bitcoin Running 351 test cases... Error: Specified -walletdir "/tmp/test_common_Bitcoin Core/1561389554_943311758/tempdir/path_does_not_exist" does not exist Error: Specified -walletdir "/tmp/test_common_Bitcoin Core/1561389554_643733972/tempdir/not_a_directory.dat" is not a directory Error: Specified -walletdir "wallets" is a relative path *** No errors detected ``` Output after this code is merged: ``` gertjaap@gjdesktop:~/src/bitcoin$ src/test/test_bitcoin Running 351 test cases... *** No errors detected ``` ACKs for top commit: l2a5b1: ACK 7a0c224 - tested and reviewed. laanwj: ACK 7a0c224 Tree-SHA512: c7881f7a431a065329360ffa9937ce4742694c646c90c019d3aff95dfd7fccbdcda9116c5762feb6dfd1108d14f9fb386e203b173c4bde9093afb2b8c977d13d
2 parents 7981627 + 7a0c224 commit e653eef

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

src/noui.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
#include <string>
1414

1515
#include <boost/signals2/connection.hpp>
16+
#include <boost/signals2/signal.hpp>
17+
18+
/** Store connections so we can disconnect them when suppressing output */
19+
boost::signals2::connection noui_ThreadSafeMessageBoxConn;
20+
boost::signals2::connection noui_ThreadSafeQuestionConn;
21+
boost::signals2::connection noui_InitMessageConn;
1622

1723
bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style)
1824
{
@@ -57,7 +63,39 @@ void noui_InitMessage(const std::string& message)
5763

5864
void noui_connect()
5965
{
60-
uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
61-
uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
62-
uiInterface.InitMessage_connect(noui_InitMessage);
66+
noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
67+
noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
68+
noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
69+
}
70+
71+
bool noui_ThreadSafeMessageBoxSuppressed(const std::string& message, const std::string& caption, unsigned int style)
72+
{
73+
return false;
74+
}
75+
76+
bool noui_ThreadSafeQuestionSuppressed(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
77+
{
78+
return false;
6379
}
80+
81+
void noui_InitMessageSuppressed(const std::string& message)
82+
{
83+
}
84+
85+
void noui_suppress()
86+
{
87+
noui_ThreadSafeMessageBoxConn.disconnect();
88+
noui_ThreadSafeQuestionConn.disconnect();
89+
noui_InitMessageConn.disconnect();
90+
noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBoxSuppressed);
91+
noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionSuppressed);
92+
noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessageSuppressed);
93+
}
94+
95+
void noui_reconnect()
96+
{
97+
noui_ThreadSafeMessageBoxConn.disconnect();
98+
noui_ThreadSafeQuestionConn.disconnect();
99+
noui_InitMessageConn.disconnect();
100+
noui_connect();
101+
}

src/noui.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@ void noui_InitMessage(const std::string& message);
1717
/** Connect all bitcoind signal handlers */
1818
void noui_connect();
1919

20+
/** Suppress all bitcoind signal handlers. Used to suppress output during test runs that produce expected errors */
21+
void noui_suppress();
22+
23+
/** Reconnects the regular Non-GUI handlers after having used noui_suppress */
24+
void noui_reconnect();
25+
2026
#endif // BITCOIN_NOUI_H

src/wallet/test/init_tests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <boost/test/unit_test.hpp>
66

7+
#include <noui.h>
78
#include <test/setup_common.h>
89
#include <util/system.h>
910
#include <wallet/test/init_test_fixture.h>
@@ -33,21 +34,27 @@ BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_custom)
3334
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_does_not_exist)
3435
{
3536
SetWalletDir(m_walletdir_path_cases["nonexistent"]);
37+
noui_suppress();
3638
bool result = m_chain_client->verify();
39+
noui_reconnect();
3740
BOOST_CHECK(result == false);
3841
}
3942

4043
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_directory)
4144
{
4245
SetWalletDir(m_walletdir_path_cases["file"]);
46+
noui_suppress();
4347
bool result = m_chain_client->verify();
48+
noui_reconnect();
4449
BOOST_CHECK(result == false);
4550
}
4651

4752
BOOST_AUTO_TEST_CASE(walletinit_verify_walletdir_is_not_relative)
4853
{
4954
SetWalletDir(m_walletdir_path_cases["relative"]);
55+
noui_suppress();
5056
bool result = m_chain_client->verify();
57+
noui_reconnect();
5158
BOOST_CHECK(result == false);
5259
}
5360

0 commit comments

Comments
 (0)