summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests/subtest/tst_subtest.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-09-07 15:30:34 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2022-01-13 19:47:22 +0100
commit13d2e13290d61fbe85c0744b6dc4115c07d4a1fa (patch)
treedef4ec6f2090046b78eb76b2fc34ea87242b97e6 /tests/auto/testlib/selftests/subtest/tst_subtest.cpp
parent95e49966889069ffafca0167d7766cbc40fda8eb (diff)
Make counts of various types of test result add up correctly
Added tests for repeated skips and failures (from within void lambdas, to simulate skips and failures from within event handlers). These exhibit yet more ways to count more than one outcome for a test. The new QTest::failOnWarning() can also provoke more than one failure from a single test, and several existing selftests exhibited various ways for the Totals line's counts to add up to more than the number of actual tests run. Fixed counting so that only the first decisive incident is counted. Tests can still report later failure or skipping, but only the first is counted. Added a currentTestState in qtestlog.cpp, by which it keeps track of whether the test has resolved to a result, and clearCurrentTestState() by which other code can reset that at the end of each test. This brought to light various places where test-end clean-up was not being handled - due to failure or skipping in a *_data() method or init, or a skip in cleanup. Fixes: QTBUG-95661 Change-Id: I5d24a37a53d3db225fa602649d8aad8f5ed6c1ad Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/testlib/selftests/subtest/tst_subtest.cpp')
-rw-r--r--tests/auto/testlib/selftests/subtest/tst_subtest.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/tests/auto/testlib/selftests/subtest/tst_subtest.cpp b/tests/auto/testlib/selftests/subtest/tst_subtest.cpp
index fff8d4068f..c5f5cd6c04 100644
--- a/tests/auto/testlib/selftests/subtest/tst_subtest.cpp
+++ b/tests/auto/testlib/selftests/subtest/tst_subtest.cpp
@@ -49,6 +49,7 @@ private slots:
void test3();
void multiFail();
+ void multiSkip();
private:
void logNames(const char *caller);
void table_data();
@@ -136,13 +137,20 @@ void tst_Subtest::test3()
void tst_Subtest::multiFail()
{
// Simulates tests which call a shared function that does common checks, or
- // that do checks in code run asynchronously from a messae loop.
+ // that do checks in code run asynchronously from a message loop.
for (int i = 0; i < 10; ++i)
[]() { QFAIL("This failure message should be repeated ten times"); }();
- // FIXME QTBUG-95661: it gets counted as eleven failures, of course.
QFAIL("But this test should only contribute one to the failure count");
}
+void tst_Subtest::multiSkip()
+{
+ // Similar to multiFail()
+ for (int i = 0; i < 10; ++i)
+ []() { QSKIP("This skip should be repeated ten times"); }();
+ QSKIP("But this test should only contribute one to the skip count");
+}
+
QTEST_MAIN(tst_Subtest)
#include "tst_subtest.moc"