From a93a9ea915332196821db9c197856955bedbfd26 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 11 Jun 2021 14:33:41 +0200 Subject: Fix QFAIL() to interract correctly with QEXPECT_FAIL() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, it went direct to QTestResults::addFailure() without going via the checking for expected failure. Add QTestResults::fail() to take care of this checking, as for verify() and compare(). Tidied up the code implementing expected failure and QFAIL(), while I was about it. Adjusted an existing test to verify that expecting a QFAIL() works, by using QFAIL() instead of QVERIFY(false). Remove the QVERIFY(false) whose comment brought this to my attention. [ChangeLog][QtTestLib][QFAIL] QEXPECT_FAIL() now correctly anticipates a subsequent QFAIL(). Previously QFAIL() counted as a fail regardless. Change-Id: Icc28cf70e5ff3006363791ea03aa01f2f591eb71 Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- src/testlib/qtestresult.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/testlib/qtestresult.cpp') diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index ee038d3704..96c7af29d5 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtTest module of the Qt Toolkit. @@ -237,7 +237,6 @@ bool QTestResult::expectFail(const char *dataIndex, const char *comment, if (QTest::expectFailMode) { delete[] comment; - clearExpectFail(); addFailure("Already expecting a fail", file, line); return false; } @@ -278,6 +277,11 @@ static bool checkStatement(bool statement, const char *msg, const char *file, in return false; } +void QTestResult::fail(const char *msg, const char *file, int line) +{ + checkStatement(false, msg, file, line); +} + bool QTestResult::verify(bool statement, const char *statementStr, const char *description, const char *file, int line) { @@ -290,10 +294,11 @@ bool QTestResult::verify(bool statement, const char *statementStr, QTestLog::info(msg, file, line); } - if (!statement && !QTest::expectFailMode) - qsnprintf(msg, 1024, "'%s' returned FALSE. (%s)", statementStr, description ? description : ""); - else if (statement && QTest::expectFailMode) - qsnprintf(msg, 1024, "'%s' returned TRUE unexpectedly. (%s)", statementStr, description ? description : ""); + if (statement == !!QTest::expectFailMode) { + qsnprintf(msg, 1024, + statement ? "'%s' returned TRUE unexpectedly. (%s)" : "'%s' returned FALSE. (%s)", + statementStr, description ? description : ""); + } return checkStatement(statement, msg, file, line); } -- cgit v1.2.3