From cfe3c0be34b63f8c4326f2d01cf880f6c28c9eb5 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Fri, 13 Jun 2014 12:59:24 -0400 Subject: CppTools: Remove test file after test In test_includeGroups_detectIncludeGroupsByIncludeType the test file was not removed and thus subsequent and isolated executions of this test failed. Change-Id: I5eeb4f004f5b146ac794ca913b4092629131fca3 Reviewed-by: Erik Verbruggen --- src/plugins/cpptools/cpptoolstestcase.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/plugins/cpptools/cpptoolstestcase.cpp') diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp index 05eb856821..554a993596 100644 --- a/src/plugins/cpptools/cpptoolstestcase.cpp +++ b/src/plugins/cpptools/cpptoolstestcase.cpp @@ -189,5 +189,28 @@ bool TestCase::writeFile(const QString &filePath, const QByteArray &contents) return true; } +FileWriterAndRemover::FileWriterAndRemover(const QString &filePath, const QByteArray &contents) + : m_filePath(filePath) +{ + if (QFileInfo(filePath).exists()) { + const QString warning = QString::fromLatin1( + "Will not overwrite existing file: \"%1\"." + " If this file is left over due to a(n) abort/crash, please remove manually.") + .arg(m_filePath); + QWARN(qPrintable(warning)); + m_writtenSuccessfully = false; + } else { + m_writtenSuccessfully = TestCase::writeFile(filePath, contents); + } +} + +FileWriterAndRemover::~FileWriterAndRemover() +{ + if (m_writtenSuccessfully && !QFile::remove(m_filePath)) { + const QString warning = QLatin1String("Failed to remove file from disk: ") + m_filePath; + QWARN(qPrintable(warning)); + } +} + } // namespace Tests } // namespace CppTools -- cgit v1.2.1