forked from qt-creator/qt-creator
AutoTest: Add option to disable derived checks
Previously the quick test parser would always check each symbol its interested in to see if it might be derived from "TestCase". This is very expensive. This patch adds an option allowing the user to enable or disable the check. By default the check is disabled. Change-Id: Ia6b230b344add672e53ad7fb52845c78a2914b99 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "quicktest_utils.h"
|
||||
#include "../testcodeparser.h"
|
||||
#include "../testtreemodel.h"
|
||||
#include "../qtest/qttestsettings.h"
|
||||
|
||||
#include <cppeditor/cppmodelmanager.h>
|
||||
#include <cppeditor/projectpart.h>
|
||||
@@ -201,14 +202,15 @@ QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const Ut
|
||||
static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr> &futureInterface,
|
||||
const Document::Ptr &qmlJSDoc,
|
||||
ITestFramework *framework,
|
||||
const Utils::FilePath &proFile = Utils::FilePath())
|
||||
const Utils::FilePath &proFile = Utils::FilePath(),
|
||||
bool checkForDerivedTest = false)
|
||||
{
|
||||
if (qmlJSDoc.isNull())
|
||||
return false;
|
||||
AST::Node *ast = qmlJSDoc->ast();
|
||||
QTC_ASSERT(ast, return false);
|
||||
Snapshot snapshot = ModelManagerInterface::instance()->snapshot();
|
||||
TestQmlVisitor qmlVisitor(qmlJSDoc, snapshot);
|
||||
TestQmlVisitor qmlVisitor(qmlJSDoc, snapshot, checkForDerivedTest);
|
||||
AST::Node::accept(ast, &qmlVisitor);
|
||||
if (!qmlVisitor.isValid())
|
||||
return false;
|
||||
@@ -272,7 +274,11 @@ bool QuickTestParser::handleQtQuickTest(QFutureInterface<TestParseResultPtr> &fu
|
||||
for (const Document::Ptr &qmlJSDoc : qmlDocs) {
|
||||
if (futureInterface.isCanceled())
|
||||
break;
|
||||
result |= checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, framework, proFile);
|
||||
result |= checkQmlDocumentForQuickTestCode(futureInterface,
|
||||
qmlJSDoc,
|
||||
framework,
|
||||
proFile,
|
||||
m_checkForDerivedTests);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -354,6 +360,10 @@ void QuickTestParser::init(const Utils::FilePaths &filesToParse, bool fullParse)
|
||||
// get rid of all cached main cpp files
|
||||
m_mainCppFiles.clear();
|
||||
}
|
||||
|
||||
auto qtSettings = static_cast<QtTestSettings *>(framework()->testSettings());
|
||||
m_checkForDerivedTests = qtSettings->quickCheckForDerivedTests.value();
|
||||
|
||||
CppParser::init(filesToParse, fullParse);
|
||||
}
|
||||
|
||||
@@ -372,7 +382,11 @@ bool QuickTestParser::processDocument(QFutureInterface<TestParseResultPtr> &futu
|
||||
if (proFile.isEmpty())
|
||||
return false;
|
||||
Document::Ptr qmlJSDoc = m_qmlSnapshot.document(fileName);
|
||||
return checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, framework(), proFile);
|
||||
return checkQmlDocumentForQuickTestCode(futureInterface,
|
||||
qmlJSDoc,
|
||||
framework(),
|
||||
proFile,
|
||||
m_checkForDerivedTests);
|
||||
}
|
||||
|
||||
CPlusPlus::Document::Ptr cppdoc = document(fileName);
|
||||
|
||||
@@ -33,7 +33,8 @@ public:
|
||||
|
||||
private:
|
||||
bool handleQtQuickTest(QFutureInterface<TestParseResultPtr> &futureInterface,
|
||||
CPlusPlus::Document::Ptr document, ITestFramework *framework);
|
||||
CPlusPlus::Document::Ptr document,
|
||||
ITestFramework *framework);
|
||||
void handleDirectoryChanged(const QString &directory);
|
||||
void doUpdateWatchPaths(const QStringList &directories);
|
||||
QString quickTestName(const CPlusPlus::Document::Ptr &doc) const;
|
||||
@@ -43,6 +44,7 @@ private:
|
||||
QFileSystemWatcher m_directoryWatcher;
|
||||
QMap<QString, QMap<QString, QDateTime> > m_watchedFiles;
|
||||
QMap<Utils::FilePath, Utils::FilePath> m_mainCppFiles;
|
||||
bool m_checkForDerivedTests = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -18,9 +18,12 @@ namespace Internal {
|
||||
|
||||
static QStringList specialFunctions({"initTestCase", "cleanupTestCase", "init", "cleanup"});
|
||||
|
||||
TestQmlVisitor::TestQmlVisitor(QmlJS::Document::Ptr doc, const QmlJS::Snapshot &snapshot)
|
||||
TestQmlVisitor::TestQmlVisitor(QmlJS::Document::Ptr doc,
|
||||
const QmlJS::Snapshot &snapshot,
|
||||
bool checkForDerivedTest)
|
||||
: m_currentDoc(doc)
|
||||
, m_snapshot(snapshot)
|
||||
, m_checkForDerivedTest(checkForDerivedTest)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -68,8 +71,10 @@ bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
|
||||
const QStringView name = ast->qualifiedTypeNameId->name;
|
||||
m_objectIsTestStack.push(false);
|
||||
if (name != QLatin1String("TestCase")) {
|
||||
if (!isDerivedFromTestCase(ast->qualifiedTypeNameId, m_currentDoc, m_snapshot))
|
||||
if (!m_checkForDerivedTest
|
||||
|| !isDerivedFromTestCase(ast->qualifiedTypeNameId, m_currentDoc, m_snapshot)) {
|
||||
return true;
|
||||
}
|
||||
} else if (!documentImportsQtTest(m_currentDoc.data())) {
|
||||
return true; // find nested TestCase items as well
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ public:
|
||||
class TestQmlVisitor : public QmlJS::AST::Visitor
|
||||
{
|
||||
public:
|
||||
explicit TestQmlVisitor(QmlJS::Document::Ptr doc, const QmlJS::Snapshot &snapshot);
|
||||
TestQmlVisitor(QmlJS::Document::Ptr doc,
|
||||
const QmlJS::Snapshot &snapshot,
|
||||
bool checkForDerivedTest);
|
||||
|
||||
bool visit(QmlJS::AST::UiObjectDefinition *ast) override;
|
||||
void endVisit(QmlJS::AST::UiObjectDefinition *ast) override;
|
||||
@@ -48,6 +50,7 @@ private:
|
||||
QVector<QuickTestCaseSpec> m_testCases;
|
||||
QStack<bool> m_objectIsTestStack;
|
||||
bool m_expectTestCaseName = false;
|
||||
bool m_checkForDerivedTest = false;
|
||||
};
|
||||
|
||||
class QuickTestAstVisitor : public CPlusPlus::ASTVisitor
|
||||
|
||||
Reference in New Issue
Block a user