From 78c92e83145b027d693792a79e1e25ab3f745f01 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Wed, 6 May 2020 15:09:51 +0200 Subject: [PATCH] Tests: Allow specifying test suit name --- tests/main.cpp | 47 +++++++++++++++++++++++++------ tests/src/core/MemoryPoolTest.cpp | 5 ++-- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/tests/main.cpp b/tests/main.cpp index 2cf71aaa5..42ad8e39f 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -6,20 +6,49 @@ #include "Engine.h" +void printAvailableSuits() +{ + QStringList suitNames; + for (QTestSuite* suite : QTestSuite::suites()) { + suitNames.push_back(suite->metaObject()->className()); + } + qDebug().noquote() << "Available test suits are: " << suitNames.join(", "); +} + +int runSuit(const QString& name, const QStringList& args) +{ + for (QTestSuite* suite : QTestSuite::suites()) { + if (suite->metaObject()->className() == name) { + return QTest::qExec(suite, args); + } + } + throw std::invalid_argument("No such test suit " + name.toStdString()); +} + int main(int argc, char* argv[]) { - new QCoreApplication(argc, argv); + auto app = new QCoreApplication(argc, argv); Engine::init(true); - int numsuites = QTestSuite::suites().size(); - qDebug() << ">> Will run" << numsuites << "test suites"; - int failed = 0; - for (QTestSuite*& suite : QTestSuite::suites()) - { - failed += QTest::qExec(suite, argc, argv); + int rc = 0; + + if (app->arguments().size() > 1) { + try { + runSuit(app->arguments()[1], app->arguments().mid(1)); + } catch (const std::invalid_argument& e) { + qDebug().noquote() << e.what(); + printAvailableSuits(); + rc = -1; + } + } else { + int numsuites = QTestSuite::suites().size(); + qDebug() << ">> Will run" << numsuites << "test suites"; + for (QTestSuite* suite : QTestSuite::suites()) { + rc += QTest::qExec(suite, argc, argv); + } + qDebug() << "<<" << rc << "out of"<; - MemoryPool pool(256); + int n = 256; + MemoryPool pool(n); std::stack ptrs; - for (int i=0; i < 256; i++) { + for (int i=0; i < n; i++) { ptrs.push(pool.allocate_bounded()); QVERIFY(ptrs.top()); }