diff options
author | Rohan McGovern <rohan.mcgovern@nokia.com> | 2009-05-19 03:33:21 (GMT) |
---|---|---|
committer | Rohan McGovern <rohan.mcgovern@nokia.com> | 2009-05-19 04:06:55 (GMT) |
commit | ba7e2d913deb4adeef071002e3518f43949e6a08 (patch) | |
tree | 820e1ae297c9b94550e1d932201aa5e409c53043 | |
parent | 73dd402265ebc07e8c86e42321e881a903ec316e (diff) | |
download | Qt-ba7e2d913deb4adeef071002e3518f43949e6a08.zip Qt-ba7e2d913deb4adeef071002e3518f43949e6a08.tar.gz Qt-ba7e2d913deb4adeef071002e3518f43949e6a08.tar.bz2 |
Fixed incorrect pass/fail semantics for xpass/xfail when using
xunitxml testlib logger.
In the testlib plain logger, xfail is considered a pass and xpass
considered a fail. xunitxml had the opposite behavior; change it
to be the same.
Autotest: included
-rw-r--r-- | src/testlib/qtestlogger.cpp | 21 | ||||
-rw-r--r-- | tests/auto/selftests/expected_xunit.txt | 13 | ||||
-rw-r--r-- | tests/auto/selftests/xunit/tst_xunit.cpp | 29 |
3 files changed, 56 insertions, 7 deletions
diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index 2249e8a..46af232 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -180,7 +180,7 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, switch (type) { case QAbstractTestLogger::XPass: - ++passCounter; + ++failureCounter; typeBuf = "xpass"; break; case QAbstractTestLogger::Pass: @@ -188,7 +188,7 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, typeBuf = "pass"; break; case QAbstractTestLogger::XFail: - ++failureCounter; + ++passCounter; typeBuf = "xfail"; break; case QAbstractTestLogger::Fail: @@ -200,7 +200,8 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, break; } - if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XFail) { + if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XPass + || ((format != TLF_XunitXml) && (type == QAbstractTestLogger::XFail))) { QTestElement *failureElement = new QTestElement(QTest::LET_Failure); failureElement->addAttribute(QTest::AI_Result, typeBuf); if(file) @@ -230,10 +231,10 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, if (!strcmp(oldResult, "pass")) { overwrite = true; } - else if (!strcmp(oldResult, "xpass")) { - overwrite = (type == QAbstractTestLogger::XFail || type == QAbstractTestLogger::Fail); - } else if (!strcmp(oldResult, "xfail")) { + overwrite = (type == QAbstractTestLogger::XPass || type == QAbstractTestLogger::Fail); + } + else if (!strcmp(oldResult, "xpass")) { overwrite = (type == QAbstractTestLogger::Fail); } if (overwrite) { @@ -251,6 +252,14 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, QTest::qt_snprintf(buf, sizeof(buf), "%i", line); currentLogElement->addAttribute(QTest::AI_Line, buf); + + /* + Since XFAIL does not add a failure to the testlog in xunitxml, add a message, so we still + have some information about the expected failure. + */ + if (format == TLF_XunitXml && type == QAbstractTestLogger::XFail) { + QTestLogger::addMessage(QAbstractTestLogger::Info, description, file, line); + } } void QTestLogger::addBenchmarkResult(const QBenchmarkResult &result) diff --git a/tests/auto/selftests/expected_xunit.txt b/tests/auto/selftests/expected_xunit.txt index 875dda6..cb74491 100644 --- a/tests/auto/selftests/expected_xunit.txt +++ b/tests/auto/selftests/expected_xunit.txt @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<testsuite errors="3" failures="2" tests="6" name="tst_Xunit"> +<testsuite errors="5" failures="3" tests="9" name="tst_Xunit"> <properties> <property value="4.6.0" name="QTestVersion"/> <property value="4.6.0" name="QtVersion"/> @@ -20,10 +20,21 @@ <testcase result="fail" name="testFunc4"> <failure message="a forced failure!" result="fail"/> </testcase> + <testcase result="xfail" name="testFunc5"> + <!-- message="this failure is expected" type="info" --> + </testcase> + <testcase result="xfail" name="testFunc6"> + <!-- message="this failure is also expected" type="info" --> + </testcase> + <testcase result="xpass" name="testFunc7"> + <failure message="'true' returned FALSE. ()" result="xpass"/> + </testcase> <testcase result="pass" name="cleanupTestCase"/> <system-err> <![CDATA[just a QWARN() !]]> <![CDATA[a qDebug() call with comment-ending stuff -->]]> <![CDATA[skipping this function!]]> +<![CDATA[this failure is expected]]> +<![CDATA[this failure is also expected]]> </system-err> </testsuite> diff --git a/tests/auto/selftests/xunit/tst_xunit.cpp b/tests/auto/selftests/xunit/tst_xunit.cpp index dbe9fec..c3c90ab 100644 --- a/tests/auto/selftests/xunit/tst_xunit.cpp +++ b/tests/auto/selftests/xunit/tst_xunit.cpp @@ -53,6 +53,9 @@ private slots: void testFunc2(); void testFunc3(); void testFunc4(); + void testFunc5(); + void testFunc6(); + void testFunc7(); }; tst_Xunit::tst_Xunit() @@ -81,6 +84,32 @@ void tst_Xunit::testFunc4() QFAIL("a forced failure!"); } +/* + Note there are two testfunctions which give expected failures. + This is so we can test that expected failures don't add to failure + counts and unexpected passes do. If we had one xfail and one xpass + testfunction, we couldn't test which one of them adds to the failure + count. +*/ + +void tst_Xunit::testFunc5() +{ + QEXPECT_FAIL("", "this failure is expected", Abort); + QVERIFY(false); +} + +void tst_Xunit::testFunc6() +{ + QEXPECT_FAIL("", "this failure is also expected", Abort); + QVERIFY(false); +} + +void tst_Xunit::testFunc7() +{ + QEXPECT_FAIL("", "this pass is unexpected", Abort); + QVERIFY(true); +} + QTEST_APPLESS_MAIN(tst_Xunit) #include "tst_xunit.moc" |