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/cppsourceprocessor_test.cpp | |
parent | cb3c7538be3f5ddb26f48b5dfce23bd3ea6daacc (diff) | |
download | qt-creator-6cafc424e837aa64ecfad3828fb840d08b747452.tar.gz |
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/cppsourceprocessor_test.cpp')
-rw-r--r-- | src/plugins/cpptools/cppsourceprocessor_test.cpp | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/src/plugins/cpptools/cppsourceprocessor_test.cpp b/src/plugins/cpptools/cppsourceprocessor_test.cpp index 624f730d68..d40fcfb889 100644 --- a/src/plugins/cpptools/cppsourceprocessor_test.cpp +++ b/src/plugins/cpptools/cppsourceprocessor_test.cpp @@ -63,22 +63,16 @@ public: cleanUp(); } - Document::Ptr run(const QByteArray &source) + Document::Ptr run(const QString &filePath) { - const QString fileName = TestIncludePaths::testFilePath(); - - FileWriterAndRemover scopedFile(fileName, source); - if (!scopedFile.writtenSuccessfully()) - return Document::Ptr(); - QScopedPointer<CppSourceProcessor> sourceProcessor( CppModelManager::createSourceProcessor()); const ProjectPart::HeaderPath hp(TestIncludePaths::directoryOfTestFile(), ProjectPart::HeaderPath::IncludePath); sourceProcessor->setHeaderPaths(ProjectPart::HeaderPaths() << hp); - sourceProcessor->run(fileName); + sourceProcessor->run(filePath); - Document::Ptr document = m_cmm->document(fileName); + Document::Ptr document = m_cmm->document(filePath); return document; } @@ -101,14 +95,11 @@ private: /// Check: Resolved and unresolved includes are properly tracked. void CppToolsPlugin::test_cppsourceprocessor_includes_resolvedUnresolved() { - QByteArray source = - "#include \"header.h\"\n" - "#include \"notresolvable.h\"\n" - "\n" - ; + const QString testFilePath + = TestIncludePaths::testFilePath(QLatin1String("test_main_resolvedUnresolved.cpp")); SourcePreprocessor processor; - Document::Ptr document = processor.run(source); + Document::Ptr document = processor.run(testFilePath); QVERIFY(document); const QList<Document::Include> resolvedIncludes = document->resolvedIncludes(); @@ -167,15 +158,11 @@ void CppToolsPlugin::test_cppsourceprocessor_includes_cyclic() /// Check: All include errors are reported as diagnostic messages. void CppToolsPlugin::test_cppsourceprocessor_includes_allDiagnostics() { - QByteArray source = - "#include <NotResolvable1>\n" - "#include <NotResolvable2>\n" - "#include \"/some/nonexisting/file123.h\"\n" - "\n" - ; + const QString testFilePath + = TestIncludePaths::testFilePath(QLatin1String("test_main_allDiagnostics.cpp")); SourcePreprocessor processor; - Document::Ptr document = processor.run(source); + Document::Ptr document = processor.run(testFilePath); QVERIFY(document); QCOMPARE(document->resolvedIncludes().size(), 0); @@ -185,15 +172,11 @@ void CppToolsPlugin::test_cppsourceprocessor_includes_allDiagnostics() void CppToolsPlugin::test_cppsourceprocessor_macroUses() { - QByteArray source = - "#define SOMEDEFINE 1\n" - "#if SOMEDEFINE == 1\n" - " int someNumber;\n" - "#endif\n" - ; + const QString testFilePath + = TestIncludePaths::testFilePath(QLatin1String("test_main_macroUses.cpp")); SourcePreprocessor processor; - Document::Ptr document = processor.run(source); + Document::Ptr document = processor.run(testFilePath); QVERIFY(document); const QList<Document::MacroUse> macroUses = document->macroUses(); QCOMPARE(macroUses.size(), 1); |