diff options
author | Jason McDonald <jason.mcdonald@nokia.com> | 2012-02-01 15:42:00 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-08 03:13:21 +0100 |
commit | da18ada6bf60e0a6724ee55abb619d367f8c4633 (patch) | |
tree | 0900a1ad36240032eaa76567f7ddeb71d4737633 /src | |
parent | 684a1559f0de4354cd9427e4c9a86e4a6a4e238a (diff) |
testlib: Clear expected failures after every data row.
Previously, expected failures were only cleared at the end of each test
function, i.e. after all data rows were finished. This meant that if a
data-driven test function called QEXPECT_FAIL and then didn't perform
any further verification steps to trigger the expected failure, the
expected failure would be carried over to the next data row, probably
causing the first verification step in the test function to XPASS (with
a seemingly irrelevant error message) for the next data row.
This commit adds the new function QTestResult::finishedCurrentTestData()
to cleanup after each data row is executed. This function treats calls
to QEXPECT_FAIL without subsequent verification steps as a test failure.
This commit also adds a regression test to demonstrate that expected
failures can no longer be carried over from one data row to another. If
run against the previous version of testlib, the new test would report a
pass instead of an error.
Change-Id: Ida5c7f080815b0dca9531131fed582b0918334cb
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/qtestcase.cpp | 2 | ||||
-rw-r--r-- | src/testlib/qtestresult.cpp | 9 | ||||
-rw-r--r-- | src/testlib/qtestresult_p.h | 1 |
3 files changed, 10 insertions, 2 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index b76ff39de4..84b03b7323 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1506,6 +1506,8 @@ static void qInvokeTestMethodDataEntry(char *slot) if (!invokeOk) QTestResult::addFailure("Unable to execute slot", __FILE__, __LINE__); + QTestResult::finishedCurrentTestData(); + QTestResult::setCurrentTestLocation(QTestResult::CleanupFunc); invokeMethod(QTest::currentTestObject, "cleanup()"); QTestResult::setCurrentTestLocation(QTestResult::NoWhere); diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index d6846f363b..c3634eb01e 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -127,6 +127,13 @@ static void clearExpectFail() QTest::expectFailComment = 0; } +void QTestResult::finishedCurrentTestData() +{ + if (QTest::expectFailMode) + addFailure("QEXPECT_FAIL was called without any subsequent verification statements", 0, 0); + clearExpectFail(); +} + void QTestResult::finishedCurrentTestFunction() { if (!QTest::failed && QTestLog::unhandledIgnoreMessages()) { @@ -143,8 +150,6 @@ void QTestResult::finishedCurrentTestFunction() QTest::location = NoWhere; QTestLog::leaveTestFunction(); - - clearExpectFail(); } const char *QTestResult::currentTestFunction() diff --git a/src/testlib/qtestresult_p.h b/src/testlib/qtestresult_p.h index 5bbb7e2d27..81e11180ef 100644 --- a/src/testlib/qtestresult_p.h +++ b/src/testlib/qtestresult_p.h @@ -73,6 +73,7 @@ public: static TestLocation currentTestLocation(); static const char *currentDataTag(); static const char *currentGlobalDataTag(); + static void finishedCurrentTestData(); static void finishedCurrentTestFunction(); static void reset(); |