diff options
author | Christian Stenger <christian.stenger@qt.io> | 2021-06-16 16:06:34 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2021-06-17 08:30:48 +0000 |
commit | 354a0b17abef403d698b0f81e567dc31a1fe6f5a (patch) | |
tree | 59f64cc065d6463b53952a7c34e2d69f6c7cdd35 | |
parent | 5482109c0587eca171b9b302543d23d51eab4b06 (diff) | |
download | qt-creator-354a0b17abef403d698b0f81e567dc31a1fe6f5a.tar.gz |
AutoTest: More filepathification
Change-Id: Ibb76f4332fa2e682709520cebe5e243dc3b70bb2
Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r-- | src/plugins/autotest/qtest/qttestparser.cpp | 24 | ||||
-rw-r--r-- | src/plugins/autotest/qtest/qttestparser.h | 2 | ||||
-rw-r--r-- | src/plugins/autotest/qtest/qttestvisitors.cpp | 9 | ||||
-rw-r--r-- | src/plugins/autotest/quick/quicktestparser.cpp | 14 | ||||
-rw-r--r-- | src/plugins/autotest/quick/quicktestvisitors.cpp | 19 | ||||
-rw-r--r-- | src/plugins/autotest/quick/quicktestvisitors.h | 9 | ||||
-rw-r--r-- | src/plugins/autotest/testtreeitem.h | 3 |
7 files changed, 37 insertions, 43 deletions
diff --git a/src/plugins/autotest/qtest/qttestparser.cpp b/src/plugins/autotest/qtest/qttestparser.cpp index a42d341eff..18e0f48ca5 100644 --- a/src/plugins/autotest/qtest/qttestparser.cpp +++ b/src/plugins/autotest/qtest/qttestparser.cpp @@ -188,24 +188,25 @@ static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc, return declaringDoc; } -static QSet<QString> filesWithDataFunctionDefinitions( +static QSet<Utils::FilePath> filesWithDataFunctionDefinitions( const QMap<QString, QtTestCodeLocationAndType> &testFunctions) { - QSet<QString> result; + QSet<Utils::FilePath> result; QMap<QString, QtTestCodeLocationAndType>::ConstIterator it = testFunctions.begin(); const QMap<QString, QtTestCodeLocationAndType>::ConstIterator end = testFunctions.end(); for ( ; it != end; ++it) { const QString &key = it.key(); if (key.endsWith("_data") && testFunctions.contains(key.left(key.size() - 5))) - result.insert(it.value().m_name); + result.insert(it.value().m_filePath); } return result; } -QHash<QString, QtTestCodeLocationList> QtTestParser::checkForDataTags(const QString &fileName) const +QHash<QString, QtTestCodeLocationList> QtTestParser::checkForDataTags( + const Utils::FilePath &fileName) const { - const QByteArray fileContent = getFileContent(Utils::FilePath::fromString(fileName)); + const QByteArray fileContent = getFileContent(fileName); CPlusPlus::Document::Ptr document = m_cppSnapshot.preprocessedDocument(fileContent, fileName); document->check(); CPlusPlus::AST *ast = document->translationUnit()->ast(); @@ -367,9 +368,8 @@ Utils::optional<bool> QtTestParser::fillTestCaseData( if (data.testFunctions.isEmpty() && testCaseName == "QObject" && isQObject(declaringDoc)) return true; // we did not handle it, but we do not expect any test defined there either - const QSet<QString> &files = filesWithDataFunctionDefinitions(data.testFunctions); - - for (const QString &file : files) + const QSet<Utils::FilePath> &files = filesWithDataFunctionDefinitions(data.testFunctions); + for (const Utils::FilePath &file : files) Utils::addToHash(&(data.dataTags), checkForDataTags(file)); data.fileName = Utils::FilePath::fromString(declaringDoc->fileName()); @@ -394,13 +394,11 @@ QtTestParseResult *QtTestParser::createParseResult( for ( ; it != end; ++it) { const QtTestCodeLocationAndType &location = it.value(); - QString functionName = it.key(); - functionName = functionName.mid(functionName.lastIndexOf(':') + 1); QtTestParseResult *func = new QtTestParseResult(framework()); func->itemType = location.m_type; - func->name = testCaseName + "::" + functionName; - func->displayName = functionName; - func->fileName = Utils::FilePath::fromString(location.m_name); + func->name = location.m_name; + func->displayName = location.m_name.mid(location.m_name.lastIndexOf(':') + 1); + func->fileName = location.m_filePath; func->line = location.m_line; func->column = location.m_column; func->setInherited(location.m_inherited); diff --git a/src/plugins/autotest/qtest/qttestparser.h b/src/plugins/autotest/qtest/qttestparser.h index 37cbdca468..2dd8be33a7 100644 --- a/src/plugins/autotest/qtest/qttestparser.h +++ b/src/plugins/autotest/qtest/qttestparser.h @@ -64,7 +64,7 @@ public: private: TestCases testCases(const CppTools::CppModelManager *modelManager, const Utils::FilePath &fileName) const; - QHash<QString, QtTestCodeLocationList> checkForDataTags(const QString &fileName) const; + QHash<QString, QtTestCodeLocationList> checkForDataTags(const Utils::FilePath &fileName) const; struct TestCaseData { Utils::FilePath fileName; int line = 0; diff --git a/src/plugins/autotest/qtest/qttestvisitors.cpp b/src/plugins/autotest/qtest/qttestvisitors.cpp index 372c03330a..ee6b386fa3 100644 --- a/src/plugins/autotest/qtest/qttestvisitors.cpp +++ b/src/plugins/autotest/qtest/qttestvisitors.cpp @@ -73,11 +73,13 @@ bool TestVisitor::visit(Class *symbol) Function *functionDefinition = m_symbolFinder.findMatchingDefinition( func, m_snapshot, true); if (functionDefinition && functionDefinition->fileId()) { - locationAndType.m_name = QString::fromUtf8(functionDefinition->fileName()); + locationAndType.m_filePath = Utils::FilePath::fromString( + QString::fromUtf8(functionDefinition->fileName())); locationAndType.m_line = functionDefinition->line(); locationAndType.m_column = functionDefinition->column() - 1; } else { // if we cannot find the definition use declaration as fallback - locationAndType.m_name = QString::fromUtf8(member->fileName()); + locationAndType.m_filePath = Utils::FilePath::fromString( + QString::fromUtf8(member->fileName())); locationAndType.m_line = member->line(); locationAndType.m_column = member->column() - 1; } @@ -88,7 +90,8 @@ bool TestVisitor::visit(Class *symbol) else locationAndType.m_type = TestTreeItem::TestFunction; locationAndType.m_inherited = m_inherited; - m_privSlots.insert(className + "::" + name, locationAndType); + locationAndType.m_name = className + "::" + name; + m_privSlots.insert(locationAndType.m_name, locationAndType); } } for (int counter = 0, end = symbol->baseClassCount(); counter < end; ++counter) { diff --git a/src/plugins/autotest/quick/quicktestparser.cpp b/src/plugins/autotest/quick/quicktestparser.cpp index 598f8a2e79..70875d4bd0 100644 --- a/src/plugins/autotest/quick/quicktestparser.cpp +++ b/src/plugins/autotest/quick/quicktestparser.cpp @@ -235,7 +235,7 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr parseResult->proFile = proFile; parseResult->itemType = TestTreeItem::TestCase; if (!testCaseName.isEmpty()) { - parseResult->fileName = Utils::FilePath::fromString(testCase.m_locationAndType.m_name); + parseResult->fileName = testCase.m_locationAndType.m_filePath; parseResult->name = testCaseName; parseResult->line = testCase.m_locationAndType.m_line; parseResult->column = testCase.m_locationAndType.m_column; @@ -243,12 +243,12 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr for (const auto &function : testCase.m_functions) { QuickTestParseResult *funcResult = new QuickTestParseResult(framework); - funcResult->name = function.m_functionName; - funcResult->displayName = function.m_functionName; - funcResult->itemType = function.m_locationAndType.m_type; - funcResult->fileName = Utils::FilePath::fromString(function.m_locationAndType.m_name); - funcResult->line = function.m_locationAndType.m_line; - funcResult->column = function.m_locationAndType.m_column; + funcResult->name = function.m_name; + funcResult->displayName = function.m_name; + funcResult->itemType = function.m_type; + funcResult->fileName = function.m_filePath; + funcResult->line = function.m_line; + funcResult->column = function.m_column; funcResult->proFile = proFile; parseResult->children.append(funcResult); diff --git a/src/plugins/autotest/quick/quicktestvisitors.cpp b/src/plugins/autotest/quick/quicktestvisitors.cpp index 6f51425d01..c91f6de2f6 100644 --- a/src/plugins/autotest/quick/quicktestvisitors.cpp +++ b/src/plugins/autotest/quick/quicktestvisitors.cpp @@ -99,7 +99,7 @@ bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast) m_objectIsTestStack.top() = true; const auto sourceLocation = ast->firstSourceLocation(); QuickTestCaseSpec currentSpec; - currentSpec.m_locationAndType.m_name = m_currentDoc->fileName(); + currentSpec.m_locationAndType.m_filePath = Utils::FilePath::fromString(m_currentDoc->fileName()); currentSpec.m_locationAndType.m_line = sourceLocation.startLine; currentSpec.m_locationAndType.m_column = sourceLocation.startColumn - 1; currentSpec.m_locationAndType.m_type = TestTreeItem::TestCase; @@ -139,10 +139,11 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast) const QString name = ast->name.toString(); if (name.startsWith("test_") || name.startsWith("benchmark_") || name.endsWith("_data") - || specialFunctions.contains(name)) { + || specialFunctions.contains(name)) { const auto sourceLocation = ast->firstSourceLocation(); TestCodeLocationAndType locationAndType; - locationAndType.m_name = m_currentDoc->fileName(); + locationAndType.m_name = name; + locationAndType.m_filePath = Utils::FilePath::fromString(m_currentDoc->fileName()); locationAndType.m_line = sourceLocation.startLine; locationAndType.m_column = sourceLocation.startColumn - 1; if (specialFunctions.contains(name)) @@ -152,16 +153,14 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast) else locationAndType.m_type = TestTreeItem::TestFunction; - const QString nameStr = name; // identical test functions inside the same file are not working - will fail at runtime if (!Utils::anyOf(m_caseParseStack.top().m_functions, - [nameStr, locationAndType](const QuickTestFunctionSpec func) { - return func.m_locationAndType.m_type == locationAndType.m_type - && func.m_functionName == nameStr - && func.m_locationAndType.m_name == locationAndType.m_name; + [locationAndType](const TestCodeLocationAndType &func) { + return func.m_type == locationAndType.m_type + && func.m_name == locationAndType.m_name + && func.m_filePath == locationAndType.m_filePath; })) { - m_caseParseStack.top().m_functions.append( - QuickTestFunctionSpec{nameStr, locationAndType}); + m_caseParseStack.top().m_functions.append(locationAndType); } } return false; diff --git a/src/plugins/autotest/quick/quicktestvisitors.h b/src/plugins/autotest/quick/quicktestvisitors.h index 5aff62f458..fe8c79c829 100644 --- a/src/plugins/autotest/quick/quicktestvisitors.h +++ b/src/plugins/autotest/quick/quicktestvisitors.h @@ -37,19 +37,12 @@ namespace Autotest { namespace Internal { -class QuickTestFunctionSpec -{ -public: - QString m_functionName; - TestCodeLocationAndType m_locationAndType; -}; - class QuickTestCaseSpec { public: QString m_caseName; TestCodeLocationAndType m_locationAndType; - QVector<QuickTestFunctionSpec> m_functions; + TestCodeLocationList m_functions; }; class TestQmlVisitor : public QmlJS::AST::Visitor diff --git a/src/plugins/autotest/testtreeitem.h b/src/plugins/autotest/testtreeitem.h index 43b41ca160..120d5b4680 100644 --- a/src/plugins/autotest/testtreeitem.h +++ b/src/plugins/autotest/testtreeitem.h @@ -193,7 +193,8 @@ private: class TestCodeLocationAndType { public: - QString m_name; // tag name for m_type == TestDataTag, file name for other values // FIXME + QString m_name; + Utils::FilePath m_filePath; int m_line = 0; int m_column = 0; TestTreeItem::Type m_type = TestTreeItem::Root; |