AutoTest: More filepathification

Change-Id: Ibb76f4332fa2e682709520cebe5e243dc3b70bb2
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2021-06-16 16:06:34 +02:00
parent 5482109c05
commit 354a0b17ab
7 changed files with 37 additions and 43 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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;
@@ -142,7 +142,8 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
|| 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;

View File

@@ -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

View File

@@ -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;