forked from qt-creator/qt-creator
Refactor TestCodeParser
Change-Id: I5fdb6429e8509468b7a710414af250ea6464d92d Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
@@ -53,10 +53,11 @@ TestCodeParser::TestCodeParser(TestTreeModel *parent)
|
|||||||
m_pendingUpdate(false)
|
m_pendingUpdate(false)
|
||||||
{
|
{
|
||||||
// connect to ProgressManager to post-pone test parsing when CppModelManager is parsing
|
// connect to ProgressManager to post-pone test parsing when CppModelManager is parsing
|
||||||
Core::ProgressManager *pm = qobject_cast<Core::ProgressManager *>(
|
auto progressManager = qobject_cast<Core::ProgressManager *>(Core::ProgressManager::instance());
|
||||||
Core::ProgressManager::instance());
|
connect(progressManager, &Core::ProgressManager::taskStarted,
|
||||||
connect(pm, &Core::ProgressManager::taskStarted, this, &TestCodeParser::onTaskStarted);
|
this, &TestCodeParser::onTaskStarted);
|
||||||
connect(pm, &Core::ProgressManager::allTasksFinished, this, &TestCodeParser::onAllTasksFinished);
|
connect(progressManager, &Core::ProgressManager::allTasksFinished,
|
||||||
|
this, &TestCodeParser::onAllTasksFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCodeParser::~TestCodeParser()
|
TestCodeParser::~TestCodeParser()
|
||||||
@@ -91,8 +92,8 @@ void TestCodeParser::updateTestTree()
|
|||||||
m_model->removeAllAutoTests();
|
m_model->removeAllAutoTests();
|
||||||
m_model->removeAllQuickTests();
|
m_model->removeAllQuickTests();
|
||||||
|
|
||||||
if (ProjectExplorer::Project *proj = currentProject()) {
|
if (ProjectExplorer::Project *project = currentProject()) {
|
||||||
if (auto qmakeProject = qobject_cast<QmakeProjectManager::QmakeProject *>(proj)) {
|
if (auto qmakeProject = qobject_cast<QmakeProjectManager::QmakeProject *>(project)) {
|
||||||
connect(qmakeProject, &QmakeProjectManager::QmakeProject::proFilesEvaluated,
|
connect(qmakeProject, &QmakeProjectManager::QmakeProject::proFilesEvaluated,
|
||||||
this, &TestCodeParser::onProFileEvaluated, Qt::UniqueConnection);
|
this, &TestCodeParser::onProFileEvaluated, Qt::UniqueConnection);
|
||||||
}
|
}
|
||||||
@@ -200,10 +201,11 @@ static QString quickTestSrcDir(const CppTools::CppModelManager *cppMM,
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString testClass(const CPlusPlus::Document::Ptr &doc)
|
static QString testClass(const CppTools::CppModelManager *modelManager,
|
||||||
|
CPlusPlus::Document::Ptr &document)
|
||||||
{
|
{
|
||||||
static const QByteArray qtTestMacros[] = {"QTEST_MAIN", "QTEST_APPLESS_MAIN", "QTEST_GUILESS_MAIN"};
|
static const QByteArray qtTestMacros[] = {"QTEST_MAIN", "QTEST_APPLESS_MAIN", "QTEST_GUILESS_MAIN"};
|
||||||
const QList<CPlusPlus::Document::MacroUse> macros = doc->macroUses();
|
const QList<CPlusPlus::Document::MacroUse> macros = document->macroUses();
|
||||||
|
|
||||||
foreach (const CPlusPlus::Document::MacroUse ¯o, macros) {
|
foreach (const CPlusPlus::Document::MacroUse ¯o, macros) {
|
||||||
if (!macro.isFunctionLike())
|
if (!macro.isFunctionLike())
|
||||||
@@ -211,10 +213,19 @@ static QString testClass(const CPlusPlus::Document::Ptr &doc)
|
|||||||
const QByteArray name = macro.macro().name();
|
const QByteArray name = macro.macro().name();
|
||||||
if (name == qtTestMacros[0] || name == qtTestMacros[1] || name == qtTestMacros[2]) {
|
if (name == qtTestMacros[0] || name == qtTestMacros[1] || name == qtTestMacros[2]) {
|
||||||
const CPlusPlus::Document::Block arg = macro.arguments().at(0);
|
const CPlusPlus::Document::Block arg = macro.arguments().at(0);
|
||||||
return QLatin1String(getFileContent(doc->fileName()).mid(arg.bytesBegin(), arg.bytesEnd() - arg.bytesBegin()));
|
return QLatin1String(getFileContent(document->fileName())
|
||||||
|
.mid(arg.bytesBegin(), arg.bytesEnd() - arg.bytesBegin()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QString();
|
// check if one has used a self-defined macro or QTest::qExec() directly
|
||||||
|
const CPlusPlus::Snapshot snapshot = modelManager->snapshot();
|
||||||
|
const QByteArray fileContent = getFileContent(document->fileName());
|
||||||
|
document = snapshot.preprocessedDocument(fileContent, document->fileName());
|
||||||
|
document->check();
|
||||||
|
CPlusPlus::AST *ast = document->translationUnit()->ast();
|
||||||
|
TestAstVisitor astVisitor(document);
|
||||||
|
astVisitor.accept(ast);
|
||||||
|
return astVisitor.className();
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString quickTestName(const CPlusPlus::Document::Ptr &doc)
|
static QString quickTestName(const CPlusPlus::Document::Ptr &doc)
|
||||||
@@ -228,7 +239,8 @@ static QString quickTestName(const CPlusPlus::Document::Ptr &doc)
|
|||||||
const QByteArray name = macro.macro().name();
|
const QByteArray name = macro.macro().name();
|
||||||
if (name == qtTestMacros[0] || name == qtTestMacros[1] || name == qtTestMacros[2]) {
|
if (name == qtTestMacros[0] || name == qtTestMacros[1] || name == qtTestMacros[2]) {
|
||||||
CPlusPlus::Document::Block arg = macro.arguments().at(0);
|
CPlusPlus::Document::Block arg = macro.arguments().at(0);
|
||||||
return QLatin1String(getFileContent(doc->fileName()).mid(arg.bytesBegin(), arg.bytesEnd() - arg.bytesBegin()));
|
return QLatin1String(getFileContent(doc->fileName())
|
||||||
|
.mid(arg.bytesBegin(), arg.bytesEnd() - arg.bytesBegin()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
@@ -268,323 +280,186 @@ static QList<QmlJS::Document::Ptr> scanDirectoryForQuickTestQmlFiles(const QStri
|
|||||||
return foundDocs;
|
return foundDocs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****** end of helpers ******/
|
static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc,
|
||||||
|
const QString &testCaseName,
|
||||||
void TestCodeParser::checkDocumentForTestCode(CPlusPlus::Document::Ptr doc)
|
unsigned *line, unsigned *column)
|
||||||
{
|
{
|
||||||
const QString file = doc->fileName();
|
|
||||||
const CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
|
||||||
|
|
||||||
QList<CppTools::ProjectPart::Ptr> projParts = cppMM->projectPart(file);
|
|
||||||
if (projParts.size())
|
|
||||||
if (!projParts.at(0)->selectedForBuilding) {
|
|
||||||
removeTestsIfNecessary(file);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (includesQtQuickTest(doc, cppMM)) {
|
|
||||||
handleQtQuickTest(doc);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (includesQtTest(doc, cppMM) && qtTestLibDefined(cppMM, file)) {
|
|
||||||
QString tc(testClass(doc));
|
|
||||||
if (tc.isEmpty()) {
|
|
||||||
// one might have used an approach without macros or defined own macros
|
|
||||||
const CPlusPlus::Snapshot snapshot = cppMM->snapshot();
|
|
||||||
const QByteArray fileContent = getFileContent(file);
|
|
||||||
doc = snapshot.preprocessedDocument(fileContent, file);
|
|
||||||
doc->check();
|
|
||||||
CPlusPlus::AST *ast = doc->translationUnit()->ast();
|
|
||||||
TestAstVisitor astVisitor(doc);
|
|
||||||
astVisitor.accept(ast);
|
|
||||||
tc = astVisitor.className();
|
|
||||||
}
|
|
||||||
if (!tc.isEmpty()) {
|
|
||||||
// construct the new/modified TestTreeItem
|
|
||||||
const QModelIndex autoTestRootIndex = m_model->index(0, 0);
|
|
||||||
TestTreeItem *autoTestRootItem = static_cast<TestTreeItem *>(autoTestRootIndex.internalPointer());
|
|
||||||
TestTreeItem *ttItem = new TestTreeItem(tc, file, TestTreeItem::TEST_CLASS,
|
|
||||||
autoTestRootItem);
|
|
||||||
QString declFileName;
|
|
||||||
CPlusPlus::TypeOfExpression toe;
|
|
||||||
toe.init(doc, cppMM->snapshot());
|
|
||||||
CPlusPlus::Document::Ptr declaringDoc = doc;
|
CPlusPlus::Document::Ptr declaringDoc = doc;
|
||||||
const QList<CPlusPlus::LookupItem> toeItems = toe(tc.toUtf8(), doc->globalNamespace());
|
const CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
||||||
if (toeItems.size()) {
|
CPlusPlus::TypeOfExpression typeOfExpr;
|
||||||
CPlusPlus::Class *toeClass = toeItems.first().declaration()->asClass();
|
typeOfExpr.init(doc, cppMM->snapshot());
|
||||||
|
|
||||||
|
auto lookupItems = typeOfExpr(testCaseName.toUtf8(), doc->globalNamespace());
|
||||||
|
if (lookupItems.size()) {
|
||||||
|
CPlusPlus::Class *toeClass = lookupItems.first().declaration()->asClass();
|
||||||
if (toeClass) {
|
if (toeClass) {
|
||||||
declFileName = QLatin1String(toeClass->fileId()->chars(),
|
const QString declFileName = QLatin1String(toeClass->fileId()->chars(),
|
||||||
toeClass->fileId()->size());
|
toeClass->fileId()->size());
|
||||||
declaringDoc = cppMM->snapshot().document(declFileName);
|
declaringDoc = cppMM->snapshot().document(declFileName);
|
||||||
ttItem->setFilePath(declFileName);
|
*line = toeClass->line();
|
||||||
ttItem->setLine(toeClass->line());
|
*column = toeClass->column() - 1;
|
||||||
ttItem->setColumn(toeClass->column() - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (declaringDoc.isNull()) {
|
return declaringDoc;
|
||||||
delete ttItem;
|
}
|
||||||
|
|
||||||
|
static TestTreeItem *constructTestTreeItem(const QString &fileName,
|
||||||
|
const QString &mainFile, // used for Quick Tests only
|
||||||
|
const QString &testCaseName,
|
||||||
|
int line, int column,
|
||||||
|
const QMap<QString, TestCodeLocationAndType> functions,
|
||||||
|
TestTreeItem *rootItem)
|
||||||
|
{
|
||||||
|
TestTreeItem *treeItem = new TestTreeItem(testCaseName, fileName, TestTreeItem::TEST_CLASS, rootItem);
|
||||||
|
treeItem->setMainFile(mainFile); // used for Quick Tests only
|
||||||
|
treeItem->setLine(line);
|
||||||
|
treeItem->setColumn(column);
|
||||||
|
|
||||||
|
foreach (const QString &functionName, functions.keys()) {
|
||||||
|
const TestCodeLocationAndType locationAndType = functions.value(functionName);
|
||||||
|
TestTreeItem *treeItemChild = new TestTreeItem(functionName, locationAndType.m_fileName,
|
||||||
|
locationAndType.m_type, treeItem);
|
||||||
|
treeItemChild->setLine(locationAndType.m_line);
|
||||||
|
treeItemChild->setColumn(locationAndType.m_column);
|
||||||
|
treeItem->appendChild(treeItemChild);
|
||||||
|
}
|
||||||
|
return treeItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****** end of helpers ******/
|
||||||
|
|
||||||
|
void TestCodeParser::checkDocumentForTestCode(CPlusPlus::Document::Ptr document)
|
||||||
|
{
|
||||||
|
const QString fileName = document->fileName();
|
||||||
|
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
||||||
|
|
||||||
|
QList<CppTools::ProjectPart::Ptr> projParts = modelManager->projectPart(fileName);
|
||||||
|
if (projParts.size())
|
||||||
|
if (!projParts.at(0)->selectedForBuilding) {
|
||||||
|
removeTestsIfNecessary(fileName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TestVisitor myVisitor(tc);
|
|
||||||
myVisitor.accept(declaringDoc->globalNamespace());
|
if (includesQtQuickTest(document, modelManager)) {
|
||||||
const QMap<QString, TestCodeLocationAndType> privSlots = myVisitor.privateSlots();
|
handleQtQuickTest(document);
|
||||||
foreach (const QString &privS, privSlots.keys()) {
|
return;
|
||||||
const TestCodeLocationAndType locationAndType = privSlots.value(privS);
|
|
||||||
TestTreeItem *ttSub = new TestTreeItem(privS, locationAndType.m_fileName,
|
|
||||||
locationAndType.m_type, ttItem);
|
|
||||||
ttSub->setLine(locationAndType.m_line);
|
|
||||||
ttSub->setColumn(locationAndType.m_column);
|
|
||||||
ttItem->appendChild(ttSub);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO refactoring?
|
if (includesQtTest(document, modelManager) && qtTestLibDefined(modelManager, fileName)) {
|
||||||
// update model and internal map
|
QString testCaseName(testClass(modelManager, document));
|
||||||
QString proFile;
|
if (!testCaseName.isEmpty()) {
|
||||||
QList<CppTools::ProjectPart::Ptr> ppList = cppMM->projectPart(file);
|
unsigned line = 0;
|
||||||
if (ppList.size())
|
unsigned column = 0;
|
||||||
proFile = ppList.at(0)->projectFile;
|
CPlusPlus::Document::Ptr declaringDoc = declaringDocument(document, testCaseName,
|
||||||
|
&line, &column);
|
||||||
|
if (declaringDoc.isNull())
|
||||||
|
return;
|
||||||
|
|
||||||
TestInfo info;
|
TestVisitor visitor(testCaseName);
|
||||||
int count;
|
visitor.accept(declaringDoc->globalNamespace());
|
||||||
if (m_cppDocMap.contains(file)) {
|
const QMap<QString, TestCodeLocationAndType> testFunctions = visitor.privateSlots();
|
||||||
info = m_cppDocMap.value(file);
|
|
||||||
count = autoTestRootItem->childCount();
|
const QModelIndex autoTestRootIndex = m_model->index(0, 0);
|
||||||
for (int i = 0; i < count; ++i) {
|
TestTreeItem *autoTestRootItem = static_cast<TestTreeItem *>(autoTestRootIndex.internalPointer());
|
||||||
TestTreeItem *currentItem = autoTestRootItem->child(i);
|
|
||||||
if (currentItem->filePath() == file) {
|
TestTreeItem *ttItem = constructTestTreeItem(declaringDoc->fileName(), QString(),
|
||||||
m_model->modifyAutoTestSubtree(i, ttItem);
|
testCaseName, line, column, testFunctions,
|
||||||
TestInfo ti(tc, privSlots.keys(), doc->revision(), doc->editorRevision());
|
autoTestRootItem);
|
||||||
ti.setProfile(proFile);
|
updateModelAndCppDocMap(document, declaringDoc->fileName(), ttItem, autoTestRootItem);
|
||||||
m_cppDocMap.insert(file, ti);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (declFileName != file) {
|
|
||||||
info = m_cppDocMap.value(declFileName);
|
|
||||||
count = autoTestRootItem->childCount();
|
|
||||||
for (int i = 0; i < count; ++i) {
|
|
||||||
TestTreeItem *currentItem = autoTestRootItem->child(i);
|
|
||||||
if (currentItem->filePath() == declFileName) {
|
|
||||||
m_model->modifyAutoTestSubtree(i, ttItem);
|
|
||||||
TestInfo ti(tc, privSlots.keys(), doc->revision(),
|
|
||||||
doc->editorRevision());
|
|
||||||
ti.setReferencingFile(file);
|
|
||||||
ti.setProfile(proFile);
|
|
||||||
m_cppDocMap.insert(declFileName, ti);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete ttItem;
|
|
||||||
} else {
|
|
||||||
m_model->addAutoTest(ttItem);
|
|
||||||
TestInfo ti(tc, privSlots.keys(), doc->revision(), doc->editorRevision());
|
|
||||||
ti.setProfile(proFile);
|
|
||||||
m_cppDocMap.insert(file, ti);
|
|
||||||
if (declFileName != file) {
|
|
||||||
TestInfo ti(tc, privSlots.keys(), doc->revision(), doc->editorRevision());
|
|
||||||
ti.setReferencingFile(file);
|
|
||||||
ti.setProfile(proFile);
|
|
||||||
m_cppDocMap.insert(declFileName, ti);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// could not find the class to test, but QTest is included and QT_TESTLIB_LIB defined
|
// could not find the class to test, but QTest is included and QT_TESTLIB_LIB defined
|
||||||
// maybe file is only a referenced file
|
// maybe file is only a referenced file
|
||||||
if (m_cppDocMap.contains(file)) {
|
if (m_cppDocMap.contains(fileName)) {
|
||||||
const TestInfo info = m_cppDocMap[file];
|
const TestInfo info = m_cppDocMap[fileName];
|
||||||
CPlusPlus::Snapshot snapshot = cppMM->snapshot();
|
CPlusPlus::Snapshot snapshot = modelManager->snapshot();
|
||||||
if (snapshot.contains(info.referencingFile())) {
|
if (snapshot.contains(info.referencingFile())) {
|
||||||
checkDocumentForTestCode(snapshot.find(info.referencingFile()).value());
|
checkDocumentForTestCode(snapshot.find(info.referencingFile()).value());
|
||||||
|
} else { // no referencing file too, so this test case is no more a test case
|
||||||
|
m_model->removeAutoTestSubtreeByFilePath(fileName);
|
||||||
|
m_cppDocMap.remove(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestCodeParser::handleQtQuickTest(CPlusPlus::Document::Ptr doc)
|
void TestCodeParser::handleQtQuickTest(CPlusPlus::Document::Ptr document)
|
||||||
{
|
{
|
||||||
const CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
||||||
|
|
||||||
if (quickTestName(doc).isEmpty())
|
if (quickTestName(document).isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QString srcDir = quickTestSrcDir(cppMM, doc->fileName());
|
const QString fileName = document->fileName();
|
||||||
|
const QString srcDir = quickTestSrcDir(modelManager, fileName);
|
||||||
if (srcDir.isEmpty())
|
if (srcDir.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QList<QmlJS::Document::Ptr> qmlDocs = scanDirectoryForQuickTestQmlFiles(srcDir);
|
|
||||||
foreach (const QmlJS::Document::Ptr &d, qmlDocs) {
|
|
||||||
QmlJS::AST::Node *ast = d->ast();
|
|
||||||
if (!ast) {
|
|
||||||
qDebug() << "ast is zero pointer" << d->fileName(); // should not happen
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TestQmlVisitor qmlVisitor(d);
|
|
||||||
QmlJS::AST::Node::accept(ast, &qmlVisitor);
|
|
||||||
|
|
||||||
const QString tcName = qmlVisitor.testCaseName();
|
|
||||||
const TestCodeLocationAndType tcLocationAndType = qmlVisitor.testCaseLocation();
|
|
||||||
const QMap<QString, TestCodeLocationAndType> testFunctions = qmlVisitor.testFunctions();
|
|
||||||
|
|
||||||
const QModelIndex quickTestRootIndex = m_model->index(1, 0);
|
const QModelIndex quickTestRootIndex = m_model->index(1, 0);
|
||||||
TestTreeItem *quickTestRootItem = static_cast<TestTreeItem *>(quickTestRootIndex.internalPointer());
|
TestTreeItem *quickTestRootItem = static_cast<TestTreeItem *>(quickTestRootIndex.internalPointer());
|
||||||
|
|
||||||
if (tcName.isEmpty()) {
|
const QList<QmlJS::Document::Ptr> qmlDocs = scanDirectoryForQuickTestQmlFiles(srcDir);
|
||||||
// if this test case was named before remove it
|
foreach (const QmlJS::Document::Ptr &qmlJSDoc, qmlDocs) {
|
||||||
if (m_quickDocMap.contains(d->fileName())) {
|
QmlJS::AST::Node *ast = qmlJSDoc->ast();
|
||||||
m_model->removeQuickTestSubtreeByFilePath(d->fileName());
|
if (!ast) {
|
||||||
m_quickDocMap.remove(d->fileName());
|
qDebug() << "ast is zero pointer" << qmlJSDoc->fileName(); // should not happen
|
||||||
}
|
continue;
|
||||||
TestTreeItem *unnamedQTItem = m_model->unnamedQuickTests();
|
|
||||||
if (unnamedQTItem) {
|
|
||||||
// remove unnamed quick tests that are already found for this qml file
|
|
||||||
if (m_model->removeUnnamedQuickTests(d->fileName())) {
|
|
||||||
// make sure m_quickDocMap does not have a inconsistent state now
|
|
||||||
TestInfo ti = m_quickDocMap[tr(Constants::UNNAMED_QUICKTESTS)];
|
|
||||||
QStringList tiFunctions = ti.testFunctions();
|
|
||||||
foreach (const QString &func, testFunctions.keys())
|
|
||||||
tiFunctions.removeOne(func);
|
|
||||||
ti.setTestFunctions(tiFunctions);
|
|
||||||
if (tiFunctions.size() == 0)
|
|
||||||
m_quickDocMap.remove(tr(Constants::UNNAMED_QUICKTESTS));
|
|
||||||
else
|
|
||||||
m_quickDocMap.insert(tr(Constants::UNNAMED_QUICKTESTS), ti);
|
|
||||||
}
|
|
||||||
// as removeUnnamedQuickTests() could delete this item itself try to get it again
|
|
||||||
unnamedQTItem = m_model->unnamedQuickTests();
|
|
||||||
}
|
|
||||||
// construct new/modified TestTreeItem
|
|
||||||
TestTreeItem *ttItem = new TestTreeItem(QString(), QString(),
|
|
||||||
TestTreeItem::TEST_CLASS,
|
|
||||||
quickTestRootItem);
|
|
||||||
if (unnamedQTItem) {
|
|
||||||
for (int i = 0, count = unnamedQTItem->childCount(); i < count; ++i) {
|
|
||||||
TestTreeItem *child = new TestTreeItem(*unnamedQTItem->child(i));
|
|
||||||
child->setParent(ttItem);
|
|
||||||
ttItem->appendChild(child);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
TestQmlVisitor qmlVisitor(qmlJSDoc);
|
||||||
|
QmlJS::AST::Node::accept(ast, &qmlVisitor);
|
||||||
|
|
||||||
foreach (const QString &func, testFunctions.keys()) {
|
const QString testCaseName = qmlVisitor.testCaseName();
|
||||||
const TestCodeLocationAndType locationAndType = testFunctions.value(func);
|
const TestCodeLocationAndType tcLocationAndType = qmlVisitor.testCaseLocation();
|
||||||
TestTreeItem *ttSub = new TestTreeItem(func, locationAndType.m_fileName,
|
const QMap<QString, TestCodeLocationAndType> testFunctions = qmlVisitor.testFunctions();
|
||||||
locationAndType.m_type, ttItem);
|
|
||||||
ttSub->setLine(locationAndType.m_line);
|
|
||||||
ttSub->setColumn(locationAndType.m_column);
|
|
||||||
ttSub->setMainFile(doc->fileName());
|
|
||||||
ttItem->appendChild(ttSub);
|
|
||||||
}
|
|
||||||
TestInfo info = m_quickDocMap.contains(tr(Constants::UNNAMED_QUICKTESTS))
|
|
||||||
? m_quickDocMap[tr(Constants::UNNAMED_QUICKTESTS)]
|
|
||||||
: TestInfo(QString(), QStringList(), 666);
|
|
||||||
QStringList originalFunctions(info.testFunctions());
|
|
||||||
foreach (const QString &func, testFunctions.keys())
|
|
||||||
originalFunctions.append(func);
|
|
||||||
info.setTestFunctions(originalFunctions);
|
|
||||||
|
|
||||||
if (unnamedQTItem) {
|
|
||||||
m_model->modifyQuickTestSubtree(unnamedQTItem->row(), ttItem);
|
|
||||||
delete ttItem;
|
|
||||||
} else {
|
|
||||||
m_model->addQuickTest(ttItem);
|
|
||||||
}
|
|
||||||
m_quickDocMap.insert(tr(Constants::UNNAMED_QUICKTESTS), info);
|
|
||||||
|
|
||||||
|
if (testCaseName.isEmpty()) {
|
||||||
|
// remove found test functions before re-adding them
|
||||||
|
removeUnnamedQuickTests(qmlJSDoc->fileName(), testFunctions.keys());
|
||||||
|
// re-create TestTreeItem for unnamed Quick Tests
|
||||||
|
recreateUnnamedQuickTest(testFunctions, fileName, quickTestRootItem);
|
||||||
continue;
|
continue;
|
||||||
} // end of handling test cases without name property
|
} // end of handling test cases without name property
|
||||||
|
|
||||||
// construct new/modified TestTreeItem
|
// construct new/modified TestTreeItem
|
||||||
TestTreeItem *ttItem = new TestTreeItem(tcName, tcLocationAndType.m_fileName,
|
TestTreeItem *testTreeItem
|
||||||
tcLocationAndType.m_type, quickTestRootItem);
|
= constructTestTreeItem(tcLocationAndType.m_fileName, fileName, testCaseName,
|
||||||
ttItem->setLine(tcLocationAndType.m_line);
|
tcLocationAndType.m_line, tcLocationAndType.m_column,
|
||||||
ttItem->setColumn(tcLocationAndType.m_column);
|
testFunctions, quickTestRootItem);
|
||||||
ttItem->setMainFile(doc->fileName());
|
|
||||||
|
|
||||||
foreach (const QString &func, testFunctions.keys()) {
|
|
||||||
const TestCodeLocationAndType locationAndType = testFunctions.value(func);
|
|
||||||
TestTreeItem *ttSub = new TestTreeItem(func, locationAndType.m_fileName,
|
|
||||||
locationAndType.m_type, ttItem);
|
|
||||||
ttSub->setLine(locationAndType.m_line);
|
|
||||||
ttSub->setColumn(locationAndType.m_column);
|
|
||||||
ttItem->appendChild(ttSub);
|
|
||||||
}
|
|
||||||
|
|
||||||
// update model and internal map
|
// update model and internal map
|
||||||
const QString fileName(tcLocationAndType.m_fileName);
|
|
||||||
const QmlJS::Document::Ptr qmlDoc =
|
const QmlJS::Document::Ptr qmlDoc =
|
||||||
QmlJSTools::Internal::ModelManager::instance()->snapshot().document(fileName);
|
QmlJSTools::Internal::ModelManager::instance()->snapshot().document(tcLocationAndType.m_fileName);
|
||||||
QString proFile;
|
updateModelAndQuickDocMap(qmlDoc, qmlJSDoc->fileName(), fileName, testTreeItem,
|
||||||
QList<CppTools::ProjectPart::Ptr> ppList = cppMM->projectPart(doc->fileName());
|
quickTestRootItem);
|
||||||
if (ppList.size())
|
|
||||||
proFile = ppList.at(0)->projectFile;
|
|
||||||
|
|
||||||
if (m_quickDocMap.contains(fileName)) {
|
|
||||||
for (int i = 0; i < quickTestRootItem->childCount(); ++i) {
|
|
||||||
if (quickTestRootItem->child(i)->filePath() == fileName) {
|
|
||||||
m_model->modifyQuickTestSubtree(i, ttItem);
|
|
||||||
TestInfo ti(tcName, testFunctions.keys(), 0, qmlDoc->editorRevision());
|
|
||||||
ti.setReferencingFile(doc->fileName());
|
|
||||||
ti.setProfile(proFile);
|
|
||||||
m_quickDocMap.insert(fileName, ti);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delete ttItem;
|
|
||||||
} else {
|
|
||||||
// if it was formerly unnamed remove the respective items
|
|
||||||
if (m_quickDocMap.contains(tr(Constants::UNNAMED_QUICKTESTS))) {
|
|
||||||
if (m_model->removeUnnamedQuickTests(d->fileName())) {
|
|
||||||
// make sure m_quickDocMap does not have a inconsistent state now
|
|
||||||
TestInfo unnamedInfo = m_quickDocMap[tr(Constants::UNNAMED_QUICKTESTS)];
|
|
||||||
QStringList functions = unnamedInfo.testFunctions();
|
|
||||||
foreach (const QString &func, testFunctions.keys())
|
|
||||||
if (functions.contains(func))
|
|
||||||
functions.removeOne(func);
|
|
||||||
unnamedInfo.setTestFunctions(functions);
|
|
||||||
if (functions.size() == 0)
|
|
||||||
m_quickDocMap.remove(tr(Constants::UNNAMED_QUICKTESTS));
|
|
||||||
else
|
|
||||||
m_quickDocMap.insert(tr(Constants::UNNAMED_QUICKTESTS), unnamedInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_model->addQuickTest(ttItem);
|
void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &document)
|
||||||
TestInfo ti(tcName, testFunctions.keys(), 0, qmlDoc->editorRevision());
|
|
||||||
ti.setReferencingFile(doc->fileName());
|
|
||||||
ti.setProfile(proFile);
|
|
||||||
m_quickDocMap.insert(tcLocationAndType.m_fileName, ti);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &doc)
|
|
||||||
{
|
{
|
||||||
ProjectExplorer::Project *project = currentProject();
|
ProjectExplorer::Project *project = currentProject();
|
||||||
if (!project)
|
if (!project)
|
||||||
return;
|
return;
|
||||||
const QString fileName = doc->fileName();
|
const QString fileName = document->fileName();
|
||||||
if (m_cppDocMap.contains(fileName)) {
|
if (m_cppDocMap.contains(fileName)) {
|
||||||
if (m_cppDocMap[fileName].revision() == doc->revision()
|
if (m_cppDocMap[fileName].revision() == document->revision()
|
||||||
&& m_cppDocMap[fileName].editorRevision() == doc->editorRevision()) {
|
&& m_cppDocMap[fileName].editorRevision() == document->editorRevision()) {
|
||||||
qDebug("Skipped due revision equality"); // added to verify if this ever happens..
|
qDebug("Skipped due revision equality"); // added to verify if this ever happens..
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (!project->files(ProjectExplorer::Project::AllFiles).contains(fileName)) {
|
} else if (!project->files(ProjectExplorer::Project::AllFiles).contains(fileName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkDocumentForTestCode(doc);
|
checkDocumentForTestCode(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &doc)
|
void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &document)
|
||||||
{
|
{
|
||||||
ProjectExplorer::Project *project = currentProject();
|
ProjectExplorer::Project *project = currentProject();
|
||||||
if (!project)
|
if (!project)
|
||||||
return;
|
return;
|
||||||
const QString fileName = doc->fileName();
|
const QString fileName = document->fileName();
|
||||||
if (m_quickDocMap.contains(fileName)) {
|
if (m_quickDocMap.contains(fileName)) {
|
||||||
if ((int)m_quickDocMap[fileName].editorRevision() == doc->editorRevision()) {
|
if ((int)m_quickDocMap[fileName].editorRevision() == document->editorRevision()) {
|
||||||
qDebug("Skipped due revision equality (QML)"); // added to verify this ever happens....
|
qDebug("Skipped due revision equality (QML)"); // added to verify this ever happens....
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -692,29 +567,28 @@ void TestCodeParser::removeTestsIfNecessary(const QString &fileName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestCodeParser::removeTestsIfNecessaryByProFile(const QString &proFile)
|
void TestCodeParser::removeTestsIfNecessaryByProFile(const QString &proFile)
|
||||||
{
|
{
|
||||||
QList<QString> fl;
|
QList<QString> fList;
|
||||||
foreach (const QString &fn, m_cppDocMap.keys()) {
|
foreach (const QString &fileName, m_cppDocMap.keys()) {
|
||||||
if (m_cppDocMap[fn].proFile() == proFile)
|
if (m_cppDocMap[fileName].proFile() == proFile)
|
||||||
fl.append(fn);
|
fList.append(fileName);
|
||||||
}
|
}
|
||||||
foreach (const QString &fn, fl) {
|
foreach (const QString &fileName, fList) {
|
||||||
m_cppDocMap.remove(fn);
|
m_cppDocMap.remove(fileName);
|
||||||
m_model->removeAutoTestSubtreeByFilePath(fn);
|
m_model->removeAutoTestSubtreeByFilePath(fileName);
|
||||||
}
|
}
|
||||||
fl.clear();
|
fList.clear();
|
||||||
foreach (const QString &fn, m_quickDocMap.keys()) {
|
foreach (const QString &fileName, m_quickDocMap.keys()) {
|
||||||
if (m_quickDocMap[fn].proFile() == proFile)
|
if (m_quickDocMap[fileName].proFile() == proFile)
|
||||||
fl.append(fn);
|
fList.append(fileName);
|
||||||
}
|
}
|
||||||
foreach (const QString &fn, fl) {
|
foreach (const QString &fileName, fList) {
|
||||||
m_quickDocMap.remove(fn);
|
m_quickDocMap.remove(fileName);
|
||||||
m_model->removeQuickTestSubtreeByFilePath(fn);
|
m_model->removeQuickTestSubtreeByFilePath(fileName);
|
||||||
}
|
}
|
||||||
// handle unnamed Quick Tests
|
// handle unnamed Quick Tests
|
||||||
fl.clear(); // will now be re-used as function names storage
|
fList.clear(); // will now be re-used as function names storage
|
||||||
QSet<QString> filePaths;
|
QSet<QString> filePaths;
|
||||||
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
||||||
if (TestTreeItem *unnamedQT = m_model->unnamedQuickTests()) {
|
if (TestTreeItem *unnamedQT = m_model->unnamedQuickTests()) {
|
||||||
@@ -723,18 +597,18 @@ void TestCodeParser::removeTestsIfNecessaryByProFile(const QString &proFile)
|
|||||||
QList<CppTools::ProjectPart::Ptr> ppList = cppMM->projectPart(child->mainFile());
|
QList<CppTools::ProjectPart::Ptr> ppList = cppMM->projectPart(child->mainFile());
|
||||||
if (ppList.size() && ppList.at(0)->projectFile == proFile) {
|
if (ppList.size() && ppList.at(0)->projectFile == proFile) {
|
||||||
filePaths.insert(child->filePath());
|
filePaths.insert(child->filePath());
|
||||||
fl.append(child->name());
|
fList.append(child->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (const QString &fp, filePaths) {
|
foreach (const QString &filePath, filePaths) {
|
||||||
m_model->removeUnnamedQuickTests(fp);
|
m_model->removeUnnamedQuickTests(filePath);
|
||||||
}
|
}
|
||||||
// update info map
|
// update info map
|
||||||
TestInfo unnamedInfo = m_quickDocMap[tr(Constants::UNNAMED_QUICKTESTS)];
|
TestInfo unnamedInfo = m_quickDocMap[tr(Constants::UNNAMED_QUICKTESTS)];
|
||||||
QStringList functions = unnamedInfo.testFunctions();
|
QStringList functions = unnamedInfo.testFunctions();
|
||||||
foreach (const QString &func, fl)
|
foreach (const QString &function, fList)
|
||||||
functions.removeOne(func);
|
functions.removeOne(function);
|
||||||
unnamedInfo.setTestFunctions(functions);
|
unnamedInfo.setTestFunctions(functions);
|
||||||
if (functions.size() == 0)
|
if (functions.size() == 0)
|
||||||
m_quickDocMap.remove(tr(Constants::UNNAMED_QUICKTESTS));
|
m_quickDocMap.remove(tr(Constants::UNNAMED_QUICKTESTS));
|
||||||
@@ -742,6 +616,74 @@ void TestCodeParser::removeTestsIfNecessaryByProFile(const QString &proFile)
|
|||||||
m_quickDocMap.insert(tr(Constants::UNNAMED_QUICKTESTS), unnamedInfo);
|
m_quickDocMap.insert(tr(Constants::UNNAMED_QUICKTESTS), unnamedInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestCodeParser::removeUnnamedQuickTests(const QString &fileName,
|
||||||
|
const QStringList &testFunctions)
|
||||||
|
{
|
||||||
|
// if this test case was named before remove it
|
||||||
|
if (m_quickDocMap.contains(fileName)) {
|
||||||
|
m_model->removeQuickTestSubtreeByFilePath(fileName);
|
||||||
|
m_quickDocMap.remove(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_model->unnamedQuickTests()) {
|
||||||
|
// remove unnamed quick tests that are already found for this qml file
|
||||||
|
if (m_model->removeUnnamedQuickTests(fileName)) {
|
||||||
|
// make sure m_quickDocMap does not have a inconsistent state now
|
||||||
|
TestInfo testInfo = m_quickDocMap[tr(Constants::UNNAMED_QUICKTESTS)];
|
||||||
|
QStringList testFunctionNames = testInfo.testFunctions();
|
||||||
|
foreach (const QString &func, testFunctions)
|
||||||
|
testFunctionNames.removeOne(func);
|
||||||
|
testInfo.setTestFunctions(testFunctionNames);
|
||||||
|
if (testFunctionNames.size() == 0)
|
||||||
|
m_quickDocMap.remove(tr(Constants::UNNAMED_QUICKTESTS));
|
||||||
|
else
|
||||||
|
m_quickDocMap.insert(tr(Constants::UNNAMED_QUICKTESTS), testInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCodeParser::recreateUnnamedQuickTest(const QMap<QString, TestCodeLocationAndType> &testFunctions,
|
||||||
|
const QString &mainFile, TestTreeItem *rootItem)
|
||||||
|
{
|
||||||
|
TestTreeItem *testTreeItem = new TestTreeItem(QString(), QString(), TestTreeItem::TEST_CLASS,
|
||||||
|
rootItem);
|
||||||
|
TestTreeItem *unnamedQTItem = m_model->unnamedQuickTests();
|
||||||
|
// if there are still other unnamed Quick Tests re-parent them to the new
|
||||||
|
if (unnamedQTItem) {
|
||||||
|
for (int i = 0, count = unnamedQTItem->childCount(); i < count; ++i) {
|
||||||
|
TestTreeItem *child = new TestTreeItem(*unnamedQTItem->child(i));
|
||||||
|
child->setParent(testTreeItem);
|
||||||
|
testTreeItem->appendChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// add test functions of the current
|
||||||
|
foreach (const QString &function, testFunctions.keys()) {
|
||||||
|
const TestCodeLocationAndType locationAndType = testFunctions.value(function);
|
||||||
|
TestTreeItem *testTreeFunction = new TestTreeItem(function, locationAndType.m_fileName,
|
||||||
|
locationAndType.m_type, testTreeItem);
|
||||||
|
testTreeFunction->setLine(locationAndType.m_line);
|
||||||
|
testTreeFunction->setColumn(locationAndType.m_column);
|
||||||
|
testTreeFunction->setMainFile(mainFile);
|
||||||
|
testTreeItem->appendChild(testTreeFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
TestInfo info = m_quickDocMap.contains(tr(Constants::UNNAMED_QUICKTESTS))
|
||||||
|
? m_quickDocMap[tr(Constants::UNNAMED_QUICKTESTS)]
|
||||||
|
: TestInfo(QString(), QStringList(), 666);
|
||||||
|
QStringList originalFunctions(info.testFunctions());
|
||||||
|
foreach (const QString &function, testFunctions.keys())
|
||||||
|
originalFunctions.append(function);
|
||||||
|
info.setTestFunctions(originalFunctions);
|
||||||
|
|
||||||
|
if (unnamedQTItem) {
|
||||||
|
m_model->modifyQuickTestSubtree(unnamedQTItem->row(), testTreeItem);
|
||||||
|
delete testTreeItem;
|
||||||
|
} else {
|
||||||
|
m_model->addQuickTest(testTreeItem);
|
||||||
|
}
|
||||||
|
m_quickDocMap.insert(tr(Constants::UNNAMED_QUICKTESTS), info);
|
||||||
|
}
|
||||||
|
|
||||||
void TestCodeParser::onTaskStarted(Core::Id type)
|
void TestCodeParser::onTaskStarted(Core::Id type)
|
||||||
{
|
{
|
||||||
if (type != CppTools::Constants::TASK_INDEX
|
if (type != CppTools::Constants::TASK_INDEX
|
||||||
@@ -760,14 +702,96 @@ void TestCodeParser::onAllTasksFinished(Core::Id type)
|
|||||||
updateTestTree();
|
updateTestTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestCodeParser::updateModelAndCppDocMap(CPlusPlus::Document::Ptr document,
|
||||||
|
const QString &declFileName,
|
||||||
|
TestTreeItem *testItem, TestTreeItem *rootItem)
|
||||||
|
{
|
||||||
|
const CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
||||||
|
const QString fileName = document->fileName();
|
||||||
|
const QString testCaseName = testItem->name();
|
||||||
|
QString proFile;
|
||||||
|
const QList<CppTools::ProjectPart::Ptr> ppList = cppMM->projectPart(fileName);
|
||||||
|
if (ppList.size())
|
||||||
|
proFile = ppList.at(0)->projectFile;
|
||||||
|
|
||||||
|
if (m_cppDocMap.contains(fileName)) {
|
||||||
|
QStringList files = QStringList() << fileName;
|
||||||
|
if (fileName != declFileName)
|
||||||
|
files << declFileName;
|
||||||
|
foreach (const QString &file, files) {
|
||||||
|
const bool setReferencingFile = (files.size() == 2 && file == declFileName);
|
||||||
|
const int count = rootItem->childCount();
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
TestTreeItem *currentItem = rootItem->child(i);
|
||||||
|
if (currentItem->filePath() == file) {
|
||||||
|
m_model->modifyAutoTestSubtree(i, testItem);
|
||||||
|
TestInfo testInfo(testCaseName, testItem->getChildNames(),
|
||||||
|
document->revision(), document->editorRevision());
|
||||||
|
testInfo.setProfile(proFile);
|
||||||
|
if (setReferencingFile)
|
||||||
|
testInfo.setReferencingFile(fileName);
|
||||||
|
m_cppDocMap.insert(file, testInfo);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete testItem; // this item is no more needed as model updates the original with its content
|
||||||
|
} else {
|
||||||
|
m_model->addAutoTest(testItem);
|
||||||
|
TestInfo ti(testCaseName, testItem->getChildNames(),
|
||||||
|
document->revision(), document->editorRevision());
|
||||||
|
ti.setProfile(proFile);
|
||||||
|
m_cppDocMap.insert(fileName, ti);
|
||||||
|
if (declFileName != fileName) {
|
||||||
|
ti.setReferencingFile(fileName);
|
||||||
|
m_cppDocMap.insert(declFileName, ti);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCodeParser::updateModelAndQuickDocMap(QmlJS::Document::Ptr qmlDoc, const QString ¤tQmlJSFile,
|
||||||
|
const QString &referencingFileName,
|
||||||
|
TestTreeItem *testItem, TestTreeItem *rootItem)
|
||||||
|
{
|
||||||
|
const CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
||||||
|
const QString fileName = qmlDoc->fileName();
|
||||||
|
QString proFile;
|
||||||
|
QList<CppTools::ProjectPart::Ptr> ppList = cppMM->projectPart(referencingFileName);
|
||||||
|
if (ppList.size())
|
||||||
|
proFile = ppList.at(0)->projectFile;
|
||||||
|
|
||||||
|
if (m_quickDocMap.contains(fileName)) {
|
||||||
|
for (int i = 0; i < rootItem->childCount(); ++i) {
|
||||||
|
if (rootItem->child(i)->filePath() == fileName) {
|
||||||
|
m_model->modifyQuickTestSubtree(i, testItem);
|
||||||
|
TestInfo testInfo(testItem->name(), testItem->getChildNames(), 0, qmlDoc->editorRevision());
|
||||||
|
testInfo.setReferencingFile(referencingFileName);
|
||||||
|
testInfo.setProfile(proFile);
|
||||||
|
m_quickDocMap.insert(fileName, testInfo);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete testItem; // this item is no more needed as model updates the original with its content
|
||||||
|
} else {
|
||||||
|
// if it was formerly unnamed remove the respective items
|
||||||
|
removeUnnamedQuickTests(currentQmlJSFile, testItem->getChildNames());
|
||||||
|
|
||||||
|
m_model->addQuickTest(testItem);
|
||||||
|
TestInfo testInfo(testItem->name(), testItem->getChildNames(), 0, qmlDoc->editorRevision());
|
||||||
|
testInfo.setReferencingFile(referencingFileName);
|
||||||
|
testInfo.setProfile(proFile);
|
||||||
|
m_quickDocMap.insert(testItem->filePath(), testInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TestCodeParser::onProFileEvaluated()
|
void TestCodeParser::onProFileEvaluated()
|
||||||
{
|
{
|
||||||
ProjectExplorer::Project *project = currentProject();
|
ProjectExplorer::Project *project = currentProject();
|
||||||
if (!project)
|
if (!project)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
||||||
const QList<CppTools::ProjectPart::Ptr> pp = cppMM->projectInfo(project).projectParts();
|
const QList<CppTools::ProjectPart::Ptr> pp = modelManager->projectInfo(project).projectParts();
|
||||||
foreach (const CppTools::ProjectPart::Ptr &p, pp) {
|
foreach (const CppTools::ProjectPart::Ptr &p, pp) {
|
||||||
if (!p->selectedForBuilding)
|
if (!p->selectedForBuilding)
|
||||||
removeTestsIfNecessaryByProFile(p->projectFile);
|
removeTestsIfNecessaryByProFile(p->projectFile);
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ class Id;
|
|||||||
namespace Autotest {
|
namespace Autotest {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
struct TestCodeLocationAndType;
|
||||||
class TestInfo;
|
class TestInfo;
|
||||||
class TestTreeModel;
|
class TestTreeModel;
|
||||||
|
class TestTreeItem;
|
||||||
|
|
||||||
class TestCodeParser : public QObject
|
class TestCodeParser : public QObject
|
||||||
{
|
{
|
||||||
@@ -48,11 +50,11 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void emitUpdateTestTree();
|
void emitUpdateTestTree();
|
||||||
void updateTestTree();
|
void updateTestTree();
|
||||||
void checkDocumentForTestCode(CPlusPlus::Document::Ptr doc);
|
void checkDocumentForTestCode(CPlusPlus::Document::Ptr document);
|
||||||
void handleQtQuickTest(CPlusPlus::Document::Ptr doc);
|
void handleQtQuickTest(CPlusPlus::Document::Ptr document);
|
||||||
|
|
||||||
void onCppDocumentUpdated(const CPlusPlus::Document::Ptr &doc);
|
void onCppDocumentUpdated(const CPlusPlus::Document::Ptr &document);
|
||||||
void onQmlDocumentUpdated(const QmlJS::Document::Ptr &doc);
|
void onQmlDocumentUpdated(const QmlJS::Document::Ptr &document);
|
||||||
void removeFiles(const QStringList &files);
|
void removeFiles(const QStringList &files);
|
||||||
void onProFileEvaluated();
|
void onProFileEvaluated();
|
||||||
|
|
||||||
@@ -61,8 +63,16 @@ private:
|
|||||||
void clearMaps();
|
void clearMaps();
|
||||||
void removeTestsIfNecessary(const QString &fileName);
|
void removeTestsIfNecessary(const QString &fileName);
|
||||||
void removeTestsIfNecessaryByProFile(const QString &proFile);
|
void removeTestsIfNecessaryByProFile(const QString &proFile);
|
||||||
|
void removeUnnamedQuickTests(const QString &fileName, const QStringList &testFunctions);
|
||||||
|
void recreateUnnamedQuickTest(const QMap<QString, TestCodeLocationAndType> &testFunctions,
|
||||||
|
const QString &mainFile, TestTreeItem *rootItem);
|
||||||
void onTaskStarted(Core::Id type);
|
void onTaskStarted(Core::Id type);
|
||||||
void onAllTasksFinished(Core::Id type);
|
void onAllTasksFinished(Core::Id type);
|
||||||
|
void updateModelAndCppDocMap(CPlusPlus::Document::Ptr document, const QString &declFileName,
|
||||||
|
TestTreeItem *testItem, TestTreeItem *rootItem);
|
||||||
|
void updateModelAndQuickDocMap(QmlJS::Document::Ptr qmlDoc, const QString ¤tQmlJSFile,
|
||||||
|
const QString &referencingFileName,
|
||||||
|
TestTreeItem *testItem, TestTreeItem *rootItem);
|
||||||
|
|
||||||
TestTreeModel *m_model;
|
TestTreeModel *m_model;
|
||||||
QMap<QString, TestInfo> m_cppDocMap;
|
QMap<QString, TestInfo> m_cppDocMap;
|
||||||
|
|||||||
@@ -172,6 +172,14 @@ Qt::CheckState TestTreeItem::checked() const
|
|||||||
return Qt::Unchecked;
|
return Qt::Unchecked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QString> TestTreeItem::getChildNames() const
|
||||||
|
{
|
||||||
|
QList<QString> names;
|
||||||
|
foreach (TestTreeItem *item, m_children)
|
||||||
|
names << item->name();
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
void TestTreeItem::revalidateCheckState()
|
void TestTreeItem::revalidateCheckState()
|
||||||
{
|
{
|
||||||
if (m_children.size() == 0)
|
if (m_children.size() == 0)
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public:
|
|||||||
Qt::CheckState checked() const;
|
Qt::CheckState checked() const;
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
void setParent(TestTreeItem *parent) { m_parent = parent; }
|
void setParent(TestTreeItem *parent) { m_parent = parent; }
|
||||||
|
QList<QString> getChildNames() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void revalidateCheckState();
|
void revalidateCheckState();
|
||||||
|
|||||||
Reference in New Issue
Block a user