diff options
Diffstat (limited to 'src/plugins/cpptools/cpptoolstestcase.cpp')
-rw-r--r-- | src/plugins/cpptools/cpptoolstestcase.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
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 |