tst_QCompareHelpers: port to QTEST_THROW_ON_FAIL

Dogfooding the new QtTest 6.8 feature.

Removes a lot of manual currentTestFailed() calls.

Change-Id: Id8bb0bad9b90b0a51315e9a9677d7009ebc090e4
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
(cherry picked from commit 561a1cae9df85a7a03f73ce77948ef235fff7c5d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-01-25 17:54:10 +01:00 committed by Qt Cherry-pick Bot
parent 6f3d68e590
commit f7f19961c4
4 changed files with 23 additions and 25 deletions

View File

@ -4,7 +4,9 @@
if(NOT INTEGRITY)
add_subdirectory(qcompare)
endif()
if(NOT WASM) # QTBUG-121822
add_subdirectory(qcomparehelpers)
endif()
add_subdirectory(qflags)
add_subdirectory(q_func_info)
add_subdirectory(qgetputenv)

View File

@ -11,6 +11,10 @@ qt_internal_add_test(tst_qcomparehelpers
SOURCES
tst_qcomparehelpers.h tst_qcomparehelpers.cpp tst_qcomparehelpers1.cpp
wrappertypes.h
NO_BATCH # QTBUG-121815
DEFINES
QTEST_THROW_ON_FAIL
QTEST_THROW_ON_SKIP
LIBRARIES
Qt::TestPrivate
)
@ -22,7 +26,10 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.20" AND NOT MACOS AND NOT VXWORKS AND
SOURCES
tst_qcomparehelpers.h tst_qcomparehelpers.cpp tst_qcomparehelpers1.cpp
wrappertypes.h
NO_BATCH # QTBUG-121815
DEFINES
QTEST_THROW_ON_FAIL
QTEST_THROW_ON_SKIP
tst_QCompareHelpers=tst_QCompareHelpersCpp23
LIBRARIES
Qt::TestPrivate

View File

@ -4,6 +4,8 @@
#include "tst_qcomparehelpers.h"
#include "wrappertypes.h"
#include <QtCore/qscopeguard.h>
#if defined(__STDCPP_FLOAT16_T__) && __has_include(<stdfloat>)
#include <stdfloat>
#endif
@ -109,32 +111,12 @@ void tst_QCompareHelpers::compareStringData()
void tst_QCompareHelpers::comparisonCompiles()
{
QTestPrivate::testAllComparisonOperatorsCompile<IntWrapper>();
if (QTest::currentTestFailed())
return;
QTestPrivate::testAllComparisonOperatorsCompile<IntWrapper, int>();
if (QTest::currentTestFailed())
return;
QTestPrivate::testAllComparisonOperatorsCompile<DoubleWrapper>();
if (QTest::currentTestFailed())
return;
QTestPrivate::testAllComparisonOperatorsCompile<DoubleWrapper, double>();
if (QTest::currentTestFailed())
return;
QTestPrivate::testAllComparisonOperatorsCompile<DoubleWrapper, IntWrapper>();
if (QTest::currentTestFailed())
return;
QTestPrivate::testAllComparisonOperatorsCompile<StringWrapper<QString>>();
if (QTest::currentTestFailed())
return;
QTestPrivate::testAllComparisonOperatorsCompile<StringWrapper<QString>, QAnyStringView>();
if (QTest::currentTestFailed())
return;
}
void tst_QCompareHelpers::compare_IntWrapper_data()
@ -498,11 +480,14 @@ enum class TestEnum : quint8 {
void tst_QCompareHelpers::builtinOrder()
{
#define TEST_BUILTIN(Left, Right) \
testOrderForTypes<Left, Right>(); \
if (QTest::currentTestFailed()) { \
qDebug("Failed Qt::compareThreeWay() test for builtin types " #Left " and " #Right); \
return; \
}
do { \
auto printOnFailure = qScopeGuard([] { \
qDebug("Failed Qt::compareThreeWay() test for builtin types %s and %s", \
#Left, #Right); \
}); \
testOrderForTypes<Left, Right>(); \
printOnFailure.dismiss(); \
} while (false);
// some combinations
TEST_BUILTIN(char, char)

View File

@ -9,6 +9,10 @@
#include <QtTest/qtest.h>
#include <QtTest/private/qcomparisontesthelper_p.h>
#ifndef QTEST_THROW_ON_FAIL
# error This test requires QTEST_THROW_ON_FAIL being active.
#endif
class tst_QCompareHelpers : public QObject
{
Q_OBJECT