Commit d9c70f43 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

CppEditor: Tests: Use QTemporaryDir and avoid writing into creator source tree



This should improve results of CI tests where multiple creator instances
execute the plugin tests.

Change-Id: I557a0964568655662108df201589ba369096f4bf
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 71c27ba4
......@@ -73,9 +73,13 @@ public:
{
QVERIFY(succeededSoFar());
// Write files to disk
CppTools::Tests::TemporaryDir temporaryDir;
QVERIFY(temporaryDir.isValid());
TestDocument testDocument("file.cpp", original, '|');
QVERIFY(testDocument.hasCursorMarker());
testDocument.m_source.remove(testDocument.m_cursorPosition, 1);
testDocument.setBaseDirectory(temporaryDir.path());
QVERIFY(testDocument.writeToDisk());
// Update Code Model
......
......@@ -82,22 +82,24 @@ public:
QSet<QString> filePaths;
const int sourceListSize = sourceList.size();
CppTools::Tests::TemporaryDir temporaryDir;
QVERIFY(temporaryDir.isValid());
for (int i = 0; i < sourceListSize; ++i) {
const QByteArray &source = sourceList.at(i);
// Write source to file
const QString fileName = QString::fromLatin1("%1/file%2.h").arg(QDir::tempPath())
.arg(i+1);
QVERIFY(writeFile(fileName, source));
filePaths << fileName;
const QString fileName = QString::fromLatin1("file%1.h").arg(i+1);
const QString absoluteFilePath = temporaryDir.createFile(fileName.toLatin1(), source);
filePaths << absoluteFilePath;
}
// Update Code Model
QVERIFY(parseFiles(filePaths));
// Open Editor
const QString fileName = QDir::tempPath() + QLatin1String("/file1.h");
const QString fileName = temporaryDir.path() + QLatin1String("/file1.h");
CppEditor *editor;
QVERIFY(openCppEditor(fileName, &editor));
closeEditorAtEndOfTestCase(editor);
......
This diff is collapsed.
......@@ -82,6 +82,8 @@ protected:
QList<QuickFixTestDocument::Ptr> m_testDocuments;
private:
QScopedPointer<CppTools::Tests::TemporaryDir> m_temporaryDirectory;
CppTools::CppCodeStylePreferences *m_cppCodeStylePreferences;
QByteArray m_cppCodeStylePreferencesOriginalDelegateId;
......
......@@ -89,6 +89,10 @@ UseSelectionsTestCase::UseSelectionsTestCase(TestDocument &testFile,
QVERIFY(testFile.hasCursorMarker());
testFile.m_source.remove(testFile.m_cursorPosition, 1);
CppTools::Tests::TemporaryDir temporaryDir;
QVERIFY(temporaryDir.isValid());
testFile.setBaseDirectory(temporaryDir.path());
testFile.writeToDisk();
QVERIFY(openCppEditor(testFile.filePath(), &testFile.m_editor, &m_editorWidget));
......
......@@ -270,8 +270,13 @@ F2TestCase::F2TestCase(CppEditorAction action,
"No test file with target cursor marker is provided.");
// Write files to disk
foreach (TestDocumentPtr testFile, testFiles)
CppTools::Tests::TemporaryDir temporaryDir;
QVERIFY(temporaryDir.isValid());
foreach (TestDocumentPtr testFile, testFiles) {
QVERIFY(testFile->baseDirectory().isEmpty());
testFile->setBaseDirectory(temporaryDir.path());
QVERIFY(testFile->writeToDisk());
}
// Update Code Model
QSet<QString> filePaths;
......
......@@ -60,6 +60,7 @@ class CPPTOOLS_EXPORT TestDocument
public:
TestDocument(const QByteArray &fileName, const QByteArray &source, char cursorMarker = '@');
QString baseDirectory() const { return m_baseDirectory; }
void setBaseDirectory(const QString &baseDirectory) { m_baseDirectory = baseDirectory; }
QString filePath() const;
......@@ -127,7 +128,7 @@ private:
QList<ProjectExplorer::Project *> m_openProjects;
};
class TemporaryDir
class CPPTOOLS_EXPORT TemporaryDir
{
Q_DISABLE_COPY(TemporaryDir)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment