merge bitcoin-core/gui#337: Use Regex Search in Apptests

This commit is contained in:
Kittywhiskers Van Gogh 2021-05-16 20:36:59 -04:00
parent 3a18f087bf
commit 17a7e9ba85
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD

View File

@ -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)
@ -21,9 +20,11 @@
#include <QAction>
#include <QLineEdit>
#include <QRegularExpression>
#include <QScopedPointer>
#include <QSettings>
#include <QSignalSpy>
#include <QString>
#include <QTest>
#include <QTextEdit>
#include <QtGlobal>
@ -31,6 +32,13 @@
#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)
{
@ -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