Skip to content

Commit

Permalink
merge bitcoin-core/gui#337: Use Regex Search in Apptests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Oct 24, 2024
1 parent 3a18f08 commit 17a7e9b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/qt/test/apptests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <qt/rpcconsole.h>
#include <shutdown.h>
#include <test/util/setup_common.h>
#include <univalue.h>
#include <validation.h>

#if defined(HAVE_CONFIG_H)
Expand All @@ -21,16 +20,25 @@

#include <QAction>
#include <QLineEdit>
#include <QRegularExpression>
#include <QScopedPointer>
#include <QSettings>
#include <QSignalSpy>
#include <QString>
#include <QTest>
#include <QTextEdit>
#include <QtGlobal>
#include <QtTest/QtTestWidgets>
#include <QtTest/QtTestGui>

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)
{
Expand All @@ -42,10 +50,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.indexOf("{")).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

Expand Down

0 comments on commit 17a7e9b

Please sign in to comment.