diff options
author | Christian Stenger <christian.stenger@qt.io> | 2021-06-04 14:28:03 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2021-06-07 12:05:37 +0000 |
commit | 9db6569c43bd2acfb453b5e67f13d7f0ee4448a6 (patch) | |
tree | 941c842f26d35875a1115529c1cdfe58405087c4 /src/plugins/autotest/quick/quicktestparser.cpp | |
parent | 684c5f75293634bac7a315ca62bf917e93af28f9 (diff) | |
download | qt-creator-9db6569c43bd2acfb453b5e67f13d7f0ee4448a6.tar.gz |
AutoTest: Take precompiled headers into account
Test frameworks might be added to the precompiled
headers. This in turn would make some pre-checks
whether a file has to be processed or not fail.
Fixes: QTCREATORBUG-25821
Change-Id: Iff69c1a83889cb6f79a3e3f9b2e59c5383989ccd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/autotest/quick/quicktestparser.cpp')
-rw-r--r-- | src/plugins/autotest/quick/quicktestparser.cpp | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/plugins/autotest/quick/quicktestparser.cpp b/src/plugins/autotest/quick/quicktestparser.cpp index fdd045bb31..598f8a2e79 100644 --- a/src/plugins/autotest/quick/quicktestparser.cpp +++ b/src/plugins/autotest/quick/quicktestparser.cpp @@ -87,6 +87,14 @@ static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc, return true; } } + + for (const QString &prefix : expectedHeaderPrefixes) { + if (CppParser::precompiledHeaderContains(snapshot, + Utils::FilePath::fromString(doc->fileName()), + QString("%1/quicktest.h").arg(prefix))) { + return true; + } + } return false; } @@ -115,6 +123,7 @@ static QString quickTestSrcDir(const CppTools::CppModelManager *cppMM, QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) const { const QList<CPlusPlus::Document::MacroUse> macros = doc->macroUses(); + const Utils::FilePath filePath = Utils::FilePath::fromString(doc->fileName()); for (const CPlusPlus::Document::MacroUse ¯o : macros) { if (!macro.isFunctionLike()) @@ -122,22 +131,45 @@ QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) cons const QByteArray name = macro.macro().name(); if (QuickTestUtils::isQuickTestMacro(name)) { CPlusPlus::Document::Block arg = macro.arguments().at(0); - return QLatin1String(getFileContent(Utils::FilePath::fromString(doc->fileName())) + return QLatin1String(getFileContent(filePath) .mid(int(arg.bytesBegin()), int(arg.bytesEnd() - arg.bytesBegin()))); } } + + const QByteArray &fileContent = getFileContent(filePath); // check for using quick_test_main() directly - const QString fileName = doc->fileName(); - const QByteArray &fileContent = getFileContent(Utils::FilePath::fromString(fileName)); - CPlusPlus::Document::Ptr document = m_cppSnapshot.preprocessedDocument(fileContent, fileName); + CPlusPlus::Document::Ptr document = m_cppSnapshot.preprocessedDocument(fileContent, filePath); if (document.isNull()) return QString(); document->check(); CPlusPlus::AST *ast = document->translationUnit()->ast(); QuickTestAstVisitor astVisitor(document, m_cppSnapshot); astVisitor.accept(ast); - return astVisitor.testBaseName(); + if (!astVisitor.testBaseName().isEmpty()) + return astVisitor.testBaseName(); + + // check for precompiled headers + static QStringList expectedHeaderPrefixes + = Utils::HostOsInfo::isMacHost() + ? QStringList({"QtQuickTest.framework/Headers", "QtQuickTest"}) + : QStringList({"QtQuickTest"}); + bool pchIncludes = false; + for (const QString &prefix : expectedHeaderPrefixes) { + if (CppParser::precompiledHeaderContains(m_cppSnapshot, filePath, + QString("%1/quicktest.h").arg(prefix))) { + pchIncludes = true; + break; + } + } + + if (pchIncludes) { + const QRegularExpression regex("\\bQUICK_TEST_(MAIN|OPENGL_MAIN|MAIN_WITH_SETUP)"); + const QRegularExpressionMatch match = regex.match(QString::fromUtf8(fileContent)); + if (match.hasMatch()) + return match.captured(); // we do not care for the name, just return something non-empty + } + return {}; } QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const QString &srcDir) |