summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-11-23 09:01:13 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-11-26 18:28:50 +0100
commited343669f7c219b89449762cce086cb036a9a8f2 (patch)
treec9d888772ef5418900dd20117798f4505cd39317 /tests/auto/testlib/selftests
parent6a1a9365371f6e456bafe5120467c100cf7ca105 (diff)
Long live QVERIFY_THROWS_NO_EXCEPTION!
Counter-part to QVERIFY_THROWS_EXCEPTION. [ChangeLog][QTest] Added QVERIFY_THROWS_NO_EXCEPTION macro. Change-Id: Ib6a80c8e810d5e2298ff00d608dae04e7a0c3e8f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/testlib/selftests')
-rw-r--r--tests/auto/testlib/selftests/expected_verifyexceptionthrown.junitxml6
-rw-r--r--tests/auto/testlib/selftests/expected_verifyexceptionthrown.lightxml10
-rw-r--r--tests/auto/testlib/selftests/expected_verifyexceptionthrown.tap30
-rw-r--r--tests/auto/testlib/selftests/expected_verifyexceptionthrown.teamcity5
-rw-r--r--tests/auto/testlib/selftests/expected_verifyexceptionthrown.txt5
-rw-r--r--tests/auto/testlib/selftests/expected_verifyexceptionthrown.xml10
-rw-r--r--tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp15
7 files changed, 68 insertions, 13 deletions
diff --git a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.junitxml b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.junitxml
index d6b48dfd66..970057fe5a 100644
--- a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.junitxml
+++ b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.junitxml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<testsuite name="tst_VerifyExceptionThrown" timestamp="@TEST_START_TIME@" hostname="@HOSTNAME@" tests="11" failures="6" errors="0" skipped="0" time="@TEST_DURATION@">
+<testsuite name="tst_VerifyExceptionThrown" timestamp="@TEST_START_TIME@" hostname="@HOSTNAME@" tests="13" failures="7" errors="0" skipped="0" time="@TEST_DURATION@">
<properties>
<property name="QTestVersion" value="@INSERT_QT_VERSION_HERE@"/>
<property name="QtVersion" value="@INSERT_QT_VERSION_HERE@"/>
@@ -9,6 +9,7 @@
<testcase name="testCorrectStdTypes" classname="tst_VerifyExceptionThrown" time="@TEST_DURATION@"/>
<testcase name="testCorrectStdExceptions" classname="tst_VerifyExceptionThrown" time="@TEST_DURATION@"/>
<testcase name="testCorrectMyExceptions" classname="tst_VerifyExceptionThrown" time="@TEST_DURATION@"/>
+ <testcase name="testCorrectNoException" classname="tst_VerifyExceptionThrown" time="@TEST_DURATION@"/>
<testcase name="testFailInt" classname="tst_VerifyExceptionThrown" time="@TEST_DURATION@">
<failure type="fail" message="Expected an exception of type double to be thrown, but caught unknown exception"/>
</testcase>
@@ -27,5 +28,8 @@
<testcase name="testFailNoException" classname="tst_VerifyExceptionThrown" time="@TEST_DURATION@">
<failure type="fail" message="Expected exception of type std::exception to be thrown but no exception caught"/>
</testcase>
+ <testcase name="testFailNoException2" classname="tst_VerifyExceptionThrown" time="@TEST_DURATION@">
+ <failure type="fail" message="Expected no exception to be thrown, but caught std::exception with message This line doesn&apos;t throw"/>
+ </testcase>
<testcase name="cleanupTestCase" classname="tst_VerifyExceptionThrown" time="@TEST_DURATION@"/>
</testsuite>
diff --git a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.lightxml b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.lightxml
index 576385339f..1e74f8f4e0 100644
--- a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.lightxml
+++ b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.lightxml
@@ -19,6 +19,10 @@
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
</TestFunction>
+<TestFunction name="testCorrectNoException">
+<Incident type="pass" file="" line="0" />
+ <Duration msecs="0"/>
+</TestFunction>
<TestFunction name="testFailInt">
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp" line="0">
<Description><![CDATA[Expected an exception of type double to be thrown, but caught unknown exception]]></Description>
@@ -55,6 +59,12 @@
</Incident>
<Duration msecs="0"/>
</TestFunction>
+<TestFunction name="testFailNoException2">
+<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp" line="0">
+ <Description><![CDATA[Expected no exception to be thrown, but caught std::exception with message This line doesn't throw]]></Description>
+</Incident>
+ <Duration msecs="0"/>
+</TestFunction>
<TestFunction name="cleanupTestCase">
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
diff --git a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.tap b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.tap
index 5bba34dda6..2233d78aed 100644
--- a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.tap
+++ b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.tap
@@ -4,50 +4,58 @@ ok 1 - initTestCase()
ok 2 - testCorrectStdTypes()
ok 3 - testCorrectStdExceptions()
ok 4 - testCorrectMyExceptions()
-not ok 5 - testFailInt()
+ok 5 - testCorrectNoException()
+not ok 6 - testFailInt()
---
# Expected an exception of type double to be thrown, but caught unknown exception
at: tst_VerifyExceptionThrown::testFailInt() (qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp:0)
file: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
line: 0
...
-not ok 6 - testFailStdString()
+not ok 7 - testFailStdString()
---
# Expected an exception of type char* to be thrown, but caught unknown exception
at: tst_VerifyExceptionThrown::testFailStdString() (qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp:0)
file: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
line: 0
...
-not ok 7 - testFailStdRuntimeError()
+not ok 8 - testFailStdRuntimeError()
---
# Expected an exception of type std::runtime_error to be thrown, but caught std::exception with message logic error
at: tst_VerifyExceptionThrown::testFailStdRuntimeError() (qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp:0)
file: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
line: 0
...
-not ok 8 - testFailMyException()
+not ok 9 - testFailMyException()
---
# Expected an exception of type MyBaseException to be thrown, but caught std::exception with message logic error
at: tst_VerifyExceptionThrown::testFailMyException() (qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp:0)
file: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
line: 0
...
-not ok 9 - testFailMyDerivedException()
+not ok 10 - testFailMyDerivedException()
---
# Expected an exception of type std::runtime_error to be thrown, but caught std::exception with message MyDerivedException
at: tst_VerifyExceptionThrown::testFailMyDerivedException() (qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp:0)
file: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
line: 0
...
-not ok 10 - testFailNoException()
+not ok 11 - testFailNoException()
---
# Expected exception of type std::exception to be thrown but no exception caught
at: tst_VerifyExceptionThrown::testFailNoException() (qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp:0)
file: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
line: 0
...
-ok 11 - cleanupTestCase()
-1..11
-# tests 11
-# pass 5
-# fail 6
+not ok 12 - testFailNoException2()
+ ---
+ # Expected no exception to be thrown, but caught std::exception with message This line doesn't throw
+ at: tst_VerifyExceptionThrown::testFailNoException2() (qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp:0)
+ file: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
+ line: 0
+ ...
+ok 13 - cleanupTestCase()
+1..13
+# tests 13
+# pass 6
+# fail 7
diff --git a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.teamcity b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.teamcity
index df6b393321..53adeed74a 100644
--- a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.teamcity
+++ b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.teamcity
@@ -7,6 +7,8 @@
##teamcity[testFinished name='testCorrectStdExceptions()' flowId='tst_VerifyExceptionThrown']
##teamcity[testStarted name='testCorrectMyExceptions()' flowId='tst_VerifyExceptionThrown']
##teamcity[testFinished name='testCorrectMyExceptions()' flowId='tst_VerifyExceptionThrown']
+##teamcity[testStarted name='testCorrectNoException()' flowId='tst_VerifyExceptionThrown']
+##teamcity[testFinished name='testCorrectNoException()' flowId='tst_VerifyExceptionThrown']
##teamcity[testStarted name='testFailInt()' flowId='tst_VerifyExceptionThrown']
##teamcity[testFailed name='testFailInt()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp(0)|]' details='Expected an exception of type double to be thrown, but caught unknown exception' flowId='tst_VerifyExceptionThrown']
##teamcity[testFinished name='testFailInt()' flowId='tst_VerifyExceptionThrown']
@@ -25,6 +27,9 @@
##teamcity[testStarted name='testFailNoException()' flowId='tst_VerifyExceptionThrown']
##teamcity[testFailed name='testFailNoException()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp(0)|]' details='Expected exception of type std::exception to be thrown but no exception caught' flowId='tst_VerifyExceptionThrown']
##teamcity[testFinished name='testFailNoException()' flowId='tst_VerifyExceptionThrown']
+##teamcity[testStarted name='testFailNoException2()' flowId='tst_VerifyExceptionThrown']
+##teamcity[testFailed name='testFailNoException2()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp(0)|]' details='Expected no exception to be thrown, but caught std::exception with message This line doesn|'t throw' flowId='tst_VerifyExceptionThrown']
+##teamcity[testFinished name='testFailNoException2()' flowId='tst_VerifyExceptionThrown']
##teamcity[testStarted name='cleanupTestCase()' flowId='tst_VerifyExceptionThrown']
##teamcity[testFinished name='cleanupTestCase()' flowId='tst_VerifyExceptionThrown']
##teamcity[testSuiteFinished name='tst_VerifyExceptionThrown' flowId='tst_VerifyExceptionThrown']
diff --git a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.txt b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.txt
index 302a63ab15..485ec6a606 100644
--- a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.txt
+++ b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.txt
@@ -4,6 +4,7 @@ PASS : tst_VerifyExceptionThrown::initTestCase()
PASS : tst_VerifyExceptionThrown::testCorrectStdTypes()
PASS : tst_VerifyExceptionThrown::testCorrectStdExceptions()
PASS : tst_VerifyExceptionThrown::testCorrectMyExceptions()
+PASS : tst_VerifyExceptionThrown::testCorrectNoException()
FAIL! : tst_VerifyExceptionThrown::testFailInt() Expected an exception of type double to be thrown, but caught unknown exception
Loc: [qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp(0)]
FAIL! : tst_VerifyExceptionThrown::testFailStdString() Expected an exception of type char* to be thrown, but caught unknown exception
@@ -16,6 +17,8 @@ FAIL! : tst_VerifyExceptionThrown::testFailMyDerivedException() Expected an exc
Loc: [qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp(0)]
FAIL! : tst_VerifyExceptionThrown::testFailNoException() Expected exception of type std::exception to be thrown but no exception caught
Loc: [qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp(0)]
+FAIL! : tst_VerifyExceptionThrown::testFailNoException2() Expected no exception to be thrown, but caught std::exception with message This line doesn't throw
+ Loc: [qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp(0)]
PASS : tst_VerifyExceptionThrown::cleanupTestCase()
-Totals: 5 passed, 6 failed, 0 skipped, 0 blacklisted, 0ms
+Totals: 6 passed, 7 failed, 0 skipped, 0 blacklisted, 0ms
********* Finished testing of tst_VerifyExceptionThrown *********
diff --git a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.xml b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.xml
index 32c98347e9..d79af58db2 100644
--- a/tests/auto/testlib/selftests/expected_verifyexceptionthrown.xml
+++ b/tests/auto/testlib/selftests/expected_verifyexceptionthrown.xml
@@ -21,6 +21,10 @@
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
</TestFunction>
+<TestFunction name="testCorrectNoException">
+<Incident type="pass" file="" line="0" />
+ <Duration msecs="0"/>
+</TestFunction>
<TestFunction name="testFailInt">
<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp" line="0">
<Description><![CDATA[Expected an exception of type double to be thrown, but caught unknown exception]]></Description>
@@ -57,6 +61,12 @@
</Incident>
<Duration msecs="0"/>
</TestFunction>
+<TestFunction name="testFailNoException2">
+<Incident type="fail" file="qtbase/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp" line="0">
+ <Description><![CDATA[Expected no exception to be thrown, but caught std::exception with message This line doesn't throw]]></Description>
+</Incident>
+ <Duration msecs="0"/>
+</TestFunction>
<TestFunction name="cleanupTestCase">
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
diff --git a/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp b/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
index 391031d1f4..8276ad76b8 100644
--- a/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
+++ b/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp
@@ -57,6 +57,9 @@ class tst_VerifyExceptionThrown: public QObject
Q_OBJECT
private:
void doSomething() const {}
+#ifndef QT_NO_EXCEPTIONS
+ void throwSomething() const { throw std::logic_error("This line doesn't throw"); }
+#endif
private slots:
// Remove all test cases if exceptions are not available
@@ -64,6 +67,7 @@ private slots:
void testCorrectStdTypes() const;
void testCorrectStdExceptions() const;
void testCorrectMyExceptions() const;
+ void testCorrectNoException() const;
void testFailInt() const;
void testFailStdString() const;
@@ -72,6 +76,7 @@ private slots:
void testFailMyDerivedException() const;
void testFailNoException() const;
+ void testFailNoException2() const;
#endif // !QT_NO_EXCEPTIONS
};
@@ -148,6 +153,11 @@ void tst_VerifyExceptionThrown::testCorrectMyExceptions() const
#endif
}
+void tst_VerifyExceptionThrown::testCorrectNoException() const
+{
+ QVERIFY_THROWS_NO_EXCEPTION(doSomething());
+}
+
void tst_VerifyExceptionThrown::testFailInt() const
{
try {
@@ -182,6 +192,11 @@ void tst_VerifyExceptionThrown::testFailNoException() const
QVERIFY_THROWS_EXCEPTION(std::exception, doSomething());
}
+void tst_VerifyExceptionThrown::testFailNoException2() const
+{
+ QVERIFY_THROWS_NO_EXCEPTION(throwSomething());
+}
+
#endif // !QT_NO_EXCEPTIONS