diff options
author | Dimitrios Apostolou <jimis@qt.io> | 2022-05-10 16:32:29 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-06-28 17:14:44 +0000 |
commit | 2b1be235e0c2288d1e074e71d068589a680d5245 (patch) | |
tree | 220b761585048e1f797f30d74a74282ba02bc2d4 /src/testlib | |
parent | 74989b09147dd0a47d3e3d0324c6f4ee37a0c667 (diff) | |
download | qtbase-2b1be235e0c2288d1e074e71d068589a680d5245.tar.gz |
qtestlib: exit with error if a test is invoked with unknown data tag
Previously trying to execute a test function with an unknown data tag
would print an error message but exit with 0.
This patch stores a test failure, and continues trying to execute the
rest of the command line arguments, if any. In the end the process exits
with the usual exit code (number of failed tests) which is now !=0.
Fixes: QTBUG-24240
Change-Id: Id4d422035f173e01e77ca88028dfd94dc0f9085c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit d23dcc05425dcd2ab0eb621f5f2ea793a78fcc9f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestcase.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index f55d4ba38f..242246d279 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1292,6 +1292,26 @@ public: #endif // QT_CONFIG(thread) +static void printUnknownDataTagError(QLatin1StringView name, QLatin1StringView tag, + const QTestTable &lTable, const QTestTable &gTable) +{ + fprintf(stderr, "Unknown testdata for function %s(): '%s'\n", name.constData(), tag.data()); + const int localDataCount = lTable.dataCount(); + if (localDataCount) { + fputs("Available test-specific data tags:\n", stderr); + for (int i = 0; i < localDataCount; ++i) + fprintf(stderr, "\t%s\n", lTable.testData(i)->dataTag()); + } + const int globalDataCount = gTable.dataCount(); + if (globalDataCount) { + fputs("Available global data tags:\n", stderr); + for (int i = 0; i < globalDataCount; ++i) + fprintf(stderr, "\t%s\n", gTable.testData(i)->dataTag()); + } + if (localDataCount == 0 && globalDataCount == 0) + fputs("Function has no data tags\n", stderr); +} + /*! \internal @@ -1352,13 +1372,6 @@ bool TestMethods::invokeTest(int index, QLatin1StringView tag, WatchDog *watchDo return dataCount ? table.testData(index)->dataTag() : nullptr; }; - // Data tag requested but none available? - if (!tag.isEmpty() && !dataCount && !globalDataCount) { - fprintf(stderr, "Unknown test data tag for function %s(): '%s'\n" - "Function has no testdata.\n", name.constData(), tag.data()); - return false; - } - /* For each entry in this test's data table, do: */ do { QTestResult::setSkipCurrentTest(false); @@ -1366,7 +1379,6 @@ bool TestMethods::invokeTest(int index, QLatin1StringView tag, WatchDog *watchDo if (dataTagMatches(tag, QLatin1StringView(dataTag(curDataIndex)), QLatin1StringView(globalDataTag(curGlobalDataIndex)))) { foundFunction = true; - QTestPrivate::checkBlackLists(name.constData(), dataTag(curDataIndex), globalDataTag(curGlobalDataIndex)); @@ -1391,20 +1403,9 @@ bool TestMethods::invokeTest(int index, QLatin1StringView tag, WatchDog *watchDo } while (curGlobalDataIndex < globalDataCount); if (!tag.isEmpty() && !foundFunction) { - fprintf(stderr, "Unknown testdata for function %s(): '%s'\n", name.constData(), tag.data()); - if (table.dataCount()) { - fputs("Available test-specific data tags:\n", stderr); - for (int i = 0; i < table.dataCount(); ++i) - fprintf(stderr, "\t%s\n", table.testData(i)->dataTag()); - } - if (globalDataCount) { - fputs("Available global data tags:\n", stderr); - for (int i = 0; i < globalDataCount; ++i) - fprintf(stderr, "\t%s\n", gTable->testData(i)->dataTag()); - } - return false; + printUnknownDataTagError(QLatin1StringView(name), tag, table, *gTable); + QTestResult::addFailure(qPrintable("Data tag not found: %1"_L1.arg(tag))); } - QTestResult::finishedCurrentTestFunction(); QTestResult::setSkipCurrentTest(false); QTestResult::setBlacklistCurrentTest(false); |