From ed343669f7c219b89449762cce086cb036a9a8f2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 23 Nov 2021 09:01:13 +0100 Subject: 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 --- .../expected_verifyexceptionthrown.junitxml | 6 ++++- .../expected_verifyexceptionthrown.lightxml | 10 ++++++++ .../selftests/expected_verifyexceptionthrown.tap | 30 ++++++++++++++-------- .../expected_verifyexceptionthrown.teamcity | 5 ++++ .../selftests/expected_verifyexceptionthrown.txt | 5 +++- .../selftests/expected_verifyexceptionthrown.xml | 10 ++++++++ .../tst_verifyexceptionthrown.cpp | 15 +++++++++++ 7 files changed, 68 insertions(+), 13 deletions(-) (limited to 'tests/auto') 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 @@ - + @@ -9,6 +9,7 @@ + @@ -27,5 +28,8 @@ + + + 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 @@ + + + + @@ -55,6 +59,12 @@ + + + + + + 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 @@ + + + + @@ -57,6 +61,12 @@ + + + + + + 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 -- cgit v1.2.3