diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2014-12-09 18:42:15 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2014-12-19 10:29:16 +0100 |
commit | 6cafc424e837aa64ecfad3828fb840d08b747452 (patch) | |
tree | 4b48d06bb2ba0117481944393f82b0f99b67d806 /src/plugins/cpptools/cpptoolstestcase.cpp | |
parent | cb3c7538be3f5ddb26f48b5dfce23bd3ea6daacc (diff) |
CppTools: Tests: Stop writing into source dir
Instead, always write into a unique temporary directory in
QDir::tempPath().
Where applicable, read the test source from files instead of first
writing the file.
Some clean ups in test_codegen*.
Change-Id: Id48dc50c6ca16252edfd9fc8a86ba0de9f9be486
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'src/plugins/cpptools/cpptoolstestcase.cpp')
-rw-r--r-- | src/plugins/cpptools/cpptoolstestcase.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp index 271410bf4cb..8ee8aa63041 100644 --- a/src/plugins/cpptools/cpptoolstestcase.cpp +++ b/src/plugins/cpptools/cpptoolstestcase.cpp @@ -77,8 +77,12 @@ TestDocument::TestDocument(const QByteArray &fileName, const QByteArray &source, QString TestDocument::filePath() const { + if (!m_baseDirectory.isEmpty()) + return QDir::cleanPath(m_baseDirectory + QLatin1Char('/') + m_fileName); + if (!QFileInfo(m_fileName).isAbsolute()) return QDir::tempPath() + QLatin1Char('/') + m_fileName; + return m_fileName; } @@ -263,10 +267,26 @@ void ProjectOpenerAndCloser::onGcFinished() m_gcFinished = true; } -TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath) +TemporaryDir::TemporaryDir() : m_temporaryDir(QDir::tempPath() + QLatin1String("/qtcreator-tests-XXXXXX")) , m_isValid(m_temporaryDir.isValid()) { +} + +QString TemporaryDir::createFile(const QByteArray &relativePath, const QByteArray &contents) +{ + const QString relativePathString = QString::fromUtf8(relativePath); + if (relativePathString.isEmpty() || QFileInfo(relativePathString).isAbsolute()) + return QString(); + + const QString filePath = m_temporaryDir.path() + QLatin1Char('/') + relativePathString; + if (!TestCase::writeFile(filePath, contents)) + return QString(); + return filePath; +} + +TemporaryCopiedDir::TemporaryCopiedDir(const QString &sourceDirPath) +{ if (!m_isValid) return; |