forked from qt-creator/qt-creator
AutoTest: More filepathification
Change-Id: Ibb76f4332fa2e682709520cebe5e243dc3b70bb2 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -188,24 +188,25 @@ static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc,
|
|||||||
return declaringDoc;
|
return declaringDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QSet<QString> filesWithDataFunctionDefinitions(
|
static QSet<Utils::FilePath> filesWithDataFunctionDefinitions(
|
||||||
const QMap<QString, QtTestCodeLocationAndType> &testFunctions)
|
const QMap<QString, QtTestCodeLocationAndType> &testFunctions)
|
||||||
{
|
{
|
||||||
QSet<QString> result;
|
QSet<Utils::FilePath> result;
|
||||||
QMap<QString, QtTestCodeLocationAndType>::ConstIterator it = testFunctions.begin();
|
QMap<QString, QtTestCodeLocationAndType>::ConstIterator it = testFunctions.begin();
|
||||||
const QMap<QString, QtTestCodeLocationAndType>::ConstIterator end = testFunctions.end();
|
const QMap<QString, QtTestCodeLocationAndType>::ConstIterator end = testFunctions.end();
|
||||||
|
|
||||||
for ( ; it != end; ++it) {
|
for ( ; it != end; ++it) {
|
||||||
const QString &key = it.key();
|
const QString &key = it.key();
|
||||||
if (key.endsWith("_data") && testFunctions.contains(key.left(key.size() - 5)))
|
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;
|
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);
|
CPlusPlus::Document::Ptr document = m_cppSnapshot.preprocessedDocument(fileContent, fileName);
|
||||||
document->check();
|
document->check();
|
||||||
CPlusPlus::AST *ast = document->translationUnit()->ast();
|
CPlusPlus::AST *ast = document->translationUnit()->ast();
|
||||||
@@ -367,9 +368,8 @@ Utils::optional<bool> QtTestParser::fillTestCaseData(
|
|||||||
if (data.testFunctions.isEmpty() && testCaseName == "QObject" && isQObject(declaringDoc))
|
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
|
return true; // we did not handle it, but we do not expect any test defined there either
|
||||||
|
|
||||||
const QSet<QString> &files = filesWithDataFunctionDefinitions(data.testFunctions);
|
const QSet<Utils::FilePath> &files = filesWithDataFunctionDefinitions(data.testFunctions);
|
||||||
|
for (const Utils::FilePath &file : files)
|
||||||
for (const QString &file : files)
|
|
||||||
Utils::addToHash(&(data.dataTags), checkForDataTags(file));
|
Utils::addToHash(&(data.dataTags), checkForDataTags(file));
|
||||||
|
|
||||||
data.fileName = Utils::FilePath::fromString(declaringDoc->fileName());
|
data.fileName = Utils::FilePath::fromString(declaringDoc->fileName());
|
||||||
@@ -394,13 +394,11 @@ QtTestParseResult *QtTestParser::createParseResult(
|
|||||||
|
|
||||||
for ( ; it != end; ++it) {
|
for ( ; it != end; ++it) {
|
||||||
const QtTestCodeLocationAndType &location = it.value();
|
const QtTestCodeLocationAndType &location = it.value();
|
||||||
QString functionName = it.key();
|
|
||||||
functionName = functionName.mid(functionName.lastIndexOf(':') + 1);
|
|
||||||
QtTestParseResult *func = new QtTestParseResult(framework());
|
QtTestParseResult *func = new QtTestParseResult(framework());
|
||||||
func->itemType = location.m_type;
|
func->itemType = location.m_type;
|
||||||
func->name = testCaseName + "::" + functionName;
|
func->name = location.m_name;
|
||||||
func->displayName = functionName;
|
func->displayName = location.m_name.mid(location.m_name.lastIndexOf(':') + 1);
|
||||||
func->fileName = Utils::FilePath::fromString(location.m_name);
|
func->fileName = location.m_filePath;
|
||||||
func->line = location.m_line;
|
func->line = location.m_line;
|
||||||
func->column = location.m_column;
|
func->column = location.m_column;
|
||||||
func->setInherited(location.m_inherited);
|
func->setInherited(location.m_inherited);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
TestCases testCases(const CppTools::CppModelManager *modelManager,
|
TestCases testCases(const CppTools::CppModelManager *modelManager,
|
||||||
const Utils::FilePath &fileName) const;
|
const Utils::FilePath &fileName) const;
|
||||||
QHash<QString, QtTestCodeLocationList> checkForDataTags(const QString &fileName) const;
|
QHash<QString, QtTestCodeLocationList> checkForDataTags(const Utils::FilePath &fileName) const;
|
||||||
struct TestCaseData {
|
struct TestCaseData {
|
||||||
Utils::FilePath fileName;
|
Utils::FilePath fileName;
|
||||||
int line = 0;
|
int line = 0;
|
||||||
|
|||||||
@@ -73,11 +73,13 @@ bool TestVisitor::visit(Class *symbol)
|
|||||||
Function *functionDefinition = m_symbolFinder.findMatchingDefinition(
|
Function *functionDefinition = m_symbolFinder.findMatchingDefinition(
|
||||||
func, m_snapshot, true);
|
func, m_snapshot, true);
|
||||||
if (functionDefinition && functionDefinition->fileId()) {
|
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_line = functionDefinition->line();
|
||||||
locationAndType.m_column = functionDefinition->column() - 1;
|
locationAndType.m_column = functionDefinition->column() - 1;
|
||||||
} else { // if we cannot find the definition use declaration as fallback
|
} 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_line = member->line();
|
||||||
locationAndType.m_column = member->column() - 1;
|
locationAndType.m_column = member->column() - 1;
|
||||||
}
|
}
|
||||||
@@ -88,7 +90,8 @@ bool TestVisitor::visit(Class *symbol)
|
|||||||
else
|
else
|
||||||
locationAndType.m_type = TestTreeItem::TestFunction;
|
locationAndType.m_type = TestTreeItem::TestFunction;
|
||||||
locationAndType.m_inherited = m_inherited;
|
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) {
|
for (int counter = 0, end = symbol->baseClassCount(); counter < end; ++counter) {
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr
|
|||||||
parseResult->proFile = proFile;
|
parseResult->proFile = proFile;
|
||||||
parseResult->itemType = TestTreeItem::TestCase;
|
parseResult->itemType = TestTreeItem::TestCase;
|
||||||
if (!testCaseName.isEmpty()) {
|
if (!testCaseName.isEmpty()) {
|
||||||
parseResult->fileName = Utils::FilePath::fromString(testCase.m_locationAndType.m_name);
|
parseResult->fileName = testCase.m_locationAndType.m_filePath;
|
||||||
parseResult->name = testCaseName;
|
parseResult->name = testCaseName;
|
||||||
parseResult->line = testCase.m_locationAndType.m_line;
|
parseResult->line = testCase.m_locationAndType.m_line;
|
||||||
parseResult->column = testCase.m_locationAndType.m_column;
|
parseResult->column = testCase.m_locationAndType.m_column;
|
||||||
@@ -243,12 +243,12 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr
|
|||||||
|
|
||||||
for (const auto &function : testCase.m_functions) {
|
for (const auto &function : testCase.m_functions) {
|
||||||
QuickTestParseResult *funcResult = new QuickTestParseResult(framework);
|
QuickTestParseResult *funcResult = new QuickTestParseResult(framework);
|
||||||
funcResult->name = function.m_functionName;
|
funcResult->name = function.m_name;
|
||||||
funcResult->displayName = function.m_functionName;
|
funcResult->displayName = function.m_name;
|
||||||
funcResult->itemType = function.m_locationAndType.m_type;
|
funcResult->itemType = function.m_type;
|
||||||
funcResult->fileName = Utils::FilePath::fromString(function.m_locationAndType.m_name);
|
funcResult->fileName = function.m_filePath;
|
||||||
funcResult->line = function.m_locationAndType.m_line;
|
funcResult->line = function.m_line;
|
||||||
funcResult->column = function.m_locationAndType.m_column;
|
funcResult->column = function.m_column;
|
||||||
funcResult->proFile = proFile;
|
funcResult->proFile = proFile;
|
||||||
|
|
||||||
parseResult->children.append(funcResult);
|
parseResult->children.append(funcResult);
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
|
|||||||
m_objectIsTestStack.top() = true;
|
m_objectIsTestStack.top() = true;
|
||||||
const auto sourceLocation = ast->firstSourceLocation();
|
const auto sourceLocation = ast->firstSourceLocation();
|
||||||
QuickTestCaseSpec currentSpec;
|
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_line = sourceLocation.startLine;
|
||||||
currentSpec.m_locationAndType.m_column = sourceLocation.startColumn - 1;
|
currentSpec.m_locationAndType.m_column = sourceLocation.startColumn - 1;
|
||||||
currentSpec.m_locationAndType.m_type = TestTreeItem::TestCase;
|
currentSpec.m_locationAndType.m_type = TestTreeItem::TestCase;
|
||||||
@@ -142,7 +142,8 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
|
|||||||
|| specialFunctions.contains(name)) {
|
|| specialFunctions.contains(name)) {
|
||||||
const auto sourceLocation = ast->firstSourceLocation();
|
const auto sourceLocation = ast->firstSourceLocation();
|
||||||
TestCodeLocationAndType locationAndType;
|
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_line = sourceLocation.startLine;
|
||||||
locationAndType.m_column = sourceLocation.startColumn - 1;
|
locationAndType.m_column = sourceLocation.startColumn - 1;
|
||||||
if (specialFunctions.contains(name))
|
if (specialFunctions.contains(name))
|
||||||
@@ -152,16 +153,14 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
|
|||||||
else
|
else
|
||||||
locationAndType.m_type = TestTreeItem::TestFunction;
|
locationAndType.m_type = TestTreeItem::TestFunction;
|
||||||
|
|
||||||
const QString nameStr = name;
|
|
||||||
// identical test functions inside the same file are not working - will fail at runtime
|
// identical test functions inside the same file are not working - will fail at runtime
|
||||||
if (!Utils::anyOf(m_caseParseStack.top().m_functions,
|
if (!Utils::anyOf(m_caseParseStack.top().m_functions,
|
||||||
[nameStr, locationAndType](const QuickTestFunctionSpec func) {
|
[locationAndType](const TestCodeLocationAndType &func) {
|
||||||
return func.m_locationAndType.m_type == locationAndType.m_type
|
return func.m_type == locationAndType.m_type
|
||||||
&& func.m_functionName == nameStr
|
&& func.m_name == locationAndType.m_name
|
||||||
&& func.m_locationAndType.m_name == locationAndType.m_name;
|
&& func.m_filePath == locationAndType.m_filePath;
|
||||||
})) {
|
})) {
|
||||||
m_caseParseStack.top().m_functions.append(
|
m_caseParseStack.top().m_functions.append(locationAndType);
|
||||||
QuickTestFunctionSpec{nameStr, locationAndType});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -37,19 +37,12 @@
|
|||||||
namespace Autotest {
|
namespace Autotest {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class QuickTestFunctionSpec
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
QString m_functionName;
|
|
||||||
TestCodeLocationAndType m_locationAndType;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QuickTestCaseSpec
|
class QuickTestCaseSpec
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QString m_caseName;
|
QString m_caseName;
|
||||||
TestCodeLocationAndType m_locationAndType;
|
TestCodeLocationAndType m_locationAndType;
|
||||||
QVector<QuickTestFunctionSpec> m_functions;
|
TestCodeLocationList m_functions;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestQmlVisitor : public QmlJS::AST::Visitor
|
class TestQmlVisitor : public QmlJS::AST::Visitor
|
||||||
|
|||||||
@@ -193,7 +193,8 @@ private:
|
|||||||
class TestCodeLocationAndType
|
class TestCodeLocationAndType
|
||||||
{
|
{
|
||||||
public:
|
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_line = 0;
|
||||||
int m_column = 0;
|
int m_column = 0;
|
||||||
TestTreeItem::Type m_type = TestTreeItem::Root;
|
TestTreeItem::Type m_type = TestTreeItem::Root;
|
||||||
|
|||||||
Reference in New Issue
Block a user