aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cpptools/cpptoolstestcase.cpp
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2014-06-13 12:59:24 -0400
committerNikolai Kosjar <nikolai.kosjar@digia.com>2014-06-16 14:44:24 +0200
commitcfe3c0be34b63f8c4326f2d01cf880f6c28c9eb5 (patch)
treedd1d49568528bd574e110a0ba5292781fb3a636a /src/plugins/cpptools/cpptoolstestcase.cpp
parent9acdb0bd3509bd62a4cb1811614af6a131f39b32 (diff)
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 <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cpptoolstestcase.cpp')
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp
index 05eb8568210..554a993596f 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