From bc2546ba5f40cb29b49ea51128dcdd204d1967d9 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 6 Sep 2022 10:27:03 -0700 Subject: [PATCH] tst_QFile::setPermissions: add QScopeGuard to remove temporary file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If5d5ef6220874ae8858efffd17125580b5943cc2 Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit 0193b4d2193b989d44dd28deda6dce12ae11ca4e) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 334e2b19901..902e0d734b1 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -1422,8 +1422,9 @@ void tst_QFile::setPermissions() #ifdef Q_OS_QNX QSKIP("This test doesn't pass on QNX and no one has cared to investigate."); #endif - if ( QFile::exists( "createme.txt" ) ) - QFile::remove( "createme.txt" ); + auto remove = []() { QFile::remove("createme.txt"); }; + auto guard = qScopeGuard(remove); + remove(); QVERIFY( !QFile::exists( "createme.txt" ) ); QFile f("createme.txt");