From fab3e958daa6083ff01055dd019239edef621747 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 12 Feb 2025 10:00:43 -0800 Subject: [PATCH] QT_TEST_EQUALITY_OPS: insert QCOMPARE before the current code The macro, as it was, makes debugging REALLY hard: FAIL! : tst_QStorageInfo::operatorEqual() The computed value is expected to be equal to the baseline, but is not Computed (lhs == rhs) : 0 Baseline (expectedEqual): 1 Loc: [qcomparisontesthelper_p.h(178)] It prints the location of the macro helper, not the line that called it, so one has to guess which of the many uses in a function has failed. And it prints the boolean of whether the comparison result is the expected value, not the values of left and right. QT_TEST_ALL_COMPARISON_OPS also needs a similar fix, but I don't have time for it. Ideally we'd replace the qScopeGuard with a proper QTest failure report, which would extract the printers for Left and Right. Change-Id: I7a643066137c5fcdb9e7fffd83d9bf7cf4cccd6c Reviewed-by: Rym Bouabid Reviewed-by: Ivan Solovev (cherry picked from commit 4a4c4252919d4894c7e5c6f2e636dda5dc1b1d0d) Reviewed-by: Qt Cherry-pick Bot --- src/testlib/qcomparisontesthelper_p.h | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/testlib/qcomparisontesthelper_p.h b/src/testlib/qcomparisontesthelper_p.h index 735ea717993..1510d0dd5e3 100644 --- a/src/testlib/qcomparisontesthelper_p.h +++ b/src/testlib/qcomparisontesthelper_p.h @@ -173,12 +173,27 @@ void testAllComparisonOperatorsCompile() \endcode */ template -void testEqualityOperators(LeftType lhs, RightType rhs, bool expectedEqual) +void testEqualityOperators(LeftType lhs, RightType rhs, bool expectedEqual, + const char *lhsExpr, const char *rhsExpr, const char *expected, + const char *file, int line) { + if (expectedEqual) { + if (!QTest::qCompareOp(lhs, rhs, lhsExpr, rhsExpr, file, line)) + QTEST_FAIL_ACTION; + } else { + if (!QTest::qCompareOp(lhs, rhs, lhsExpr, rhsExpr, file, line)) + QTEST_FAIL_ACTION; + } + + auto report = qScopeGuard([=] { + qDebug("testEqualityOperators(%s,%s,%s) failed in %s on line %d", lhsExpr, rhsExpr, + expected, file, line); + }); CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, lhs, rhs, ==, expectedEqual); CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, lhs, rhs, !=, !expectedEqual); CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, rhs, lhs, ==, expectedEqual); CHECK_RUNTIME_CREF(CHECK_RUNTIME_LR, rhs, lhs, !=, !expectedEqual); + report.dismiss(); } /*! @@ -327,14 +342,10 @@ void testAllComparisonOperators(LeftType lhs, RightType rhs, OrderingType expect */ #define QT_TEST_EQUALITY_OPS(Left, Right, Expected) \ do { \ - auto report = qScopeGuard([] { \ - qDebug("testEqualityOperators(" #Left ", " #Right ", " #Expected ") " \ - "failed in " __FILE__ " on line %d", __LINE__); \ - }); \ - QTestPrivate::testEqualityOperators(Left, Right, Expected); \ + QTestPrivate::testEqualityOperators(Left, Right, Expected, #Left, #Right, #Expected, \ + __FILE__, __LINE__); \ if (QTest::currentTestFailed()) \ return; \ - report.dismiss(); \ } while (false) /*!