From d09d1cf1a267b1c5563d8876aa55c4e8f70f0562 Mon Sep 17 00:00:00 2001 From: Jarol Rodriguez Date: Sun, 16 May 2021 20:36:59 -0400 Subject: [PATCH 1/2] qt, test: introduce FindInConsole function Allows for regex searching into the console output. --- src/qt/test/apptests.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp index cb3dbd2267..c5f9b570a1 100644 --- a/src/qt/test/apptests.cpp +++ b/src/qt/test/apptests.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -30,6 +31,13 @@ #include namespace { +//! Regex find a string group inside of the console output +QString FindInConsole(const QString& output, const QString& pattern) +{ + const QRegularExpression re(pattern); + return re.match(output).captured(1); +} + //! Call getblockchaininfo RPC and check first field of JSON output. void TestRpcCommand(RPCConsole* console) { From 6969b2bb98a2f44e1b51c905db92ec2e28345078 Mon Sep 17 00:00:00 2001 From: Jarol Rodriguez Date: Sun, 16 May 2021 23:43:41 -0400 Subject: [PATCH 2/2] qt, test: use regex search in apptests use the FindInConsole function to regex search for values in apptests instead of Univalue read. --- src/qt/test/apptests.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp index c5f9b570a1..318a0edf6e 100644 --- a/src/qt/test/apptests.cpp +++ b/src/qt/test/apptests.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #if defined(HAVE_CONFIG_H) @@ -24,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -49,10 +49,9 @@ void TestRpcCommand(RPCConsole* console) QTest::keyClick(lineEdit, Qt::Key_Return); QVERIFY(mw_spy.wait(1000)); QCOMPARE(mw_spy.count(), 4); - QString output = messagesWidget->toPlainText(); - UniValue value; - value.read(output.right(output.size() - output.lastIndexOf(QChar::ObjectReplacementCharacter) - 1).toStdString()); - QCOMPARE(value["chain"].get_str(), std::string("regtest")); + const QString output = messagesWidget->toPlainText(); + const QString pattern = QStringLiteral("\"chain\": \"(\\w+)\""); + QCOMPARE(FindInConsole(output, pattern), QString("regtest")); } } // namespace