forked from qt-creator/qt-creator
AutoTest: Fix handling of unnamed QuickTests
..now that the parser understands multiple TestCase items inside a single qml file. As long a test function is located inside a different TestCase it is considered as a different one, so treat test functions even of unnamed test cases correct. Change-Id: I5cbfe1f63f896317523d51bbf67ea59169481a71 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -131,13 +131,13 @@ void AutoTestUnitTests::testCodeParser_data()
|
||||
<< 1 << 0 << 0 << 0;
|
||||
QTest::newRow("mixedAutoTestAndQuickTests")
|
||||
<< QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.pro")
|
||||
<< 4 << 10 << 4 << 10;
|
||||
<< 4 << 10 << 5 << 10;
|
||||
QTest::newRow("plainAutoTestQbs")
|
||||
<< QString(m_tmpDir->path() + "/plain/plain.qbs")
|
||||
<< 1 << 0 << 0 << 0;
|
||||
QTest::newRow("mixedAutoTestAndQuickTestsQbs")
|
||||
<< QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.qbs")
|
||||
<< 4 << 10 << 4 << 10;
|
||||
<< 4 << 10 << 5 << 10;
|
||||
}
|
||||
|
||||
void AutoTestUnitTests::testCodeParserSwitchStartup()
|
||||
@@ -184,7 +184,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup_data()
|
||||
|
||||
QList<int> expectedAutoTests = QList<int>() << 1 << 4 << 1 << 4;
|
||||
QList<int> expectedNamedQuickTests = QList<int>() << 0 << 10 << 0 << 10;
|
||||
QList<int> expectedUnnamedQuickTests = QList<int>() << 0 << 4 << 0 << 4;
|
||||
QList<int> expectedUnnamedQuickTests = QList<int>() << 0 << 5 << 0 << 5;
|
||||
QList<int> expectedDataTagsCount = QList<int>() << 0 << 10 << 0 << 10;
|
||||
|
||||
QTest::newRow("loadMultipleProjects")
|
||||
|
@@ -95,7 +95,8 @@ bool QtTestResult::isDirectParentOf(const TestResult *other, bool *needsIntermed
|
||||
return qtOther->m_dataTag == m_dataTag;
|
||||
}
|
||||
} else if (qtOther->isTestFunction()) {
|
||||
return isTestCase() || m_function == qtOther->m_function;
|
||||
return isTestCase() || (m_function == qtOther->m_function
|
||||
&& qtOther->result() != ResultType::TestStart);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@@ -329,7 +329,8 @@ TestTreeItem *QuickTestTreeItem::find(const TestParseResult *result)
|
||||
case GroupNode:
|
||||
return findChildByNameAndFile(result->name, result->fileName);
|
||||
case TestCase:
|
||||
return name().isEmpty() ? findChildByNameAndFile(result->name, result->fileName)
|
||||
return name().isEmpty() ? findChildByNameFileAndLine(result->name, result->fileName,
|
||||
result->line)
|
||||
: findChildByName(result->name);
|
||||
default:
|
||||
return nullptr;
|
||||
@@ -351,7 +352,8 @@ TestTreeItem *QuickTestTreeItem::findChild(const TestTreeItem *other)
|
||||
case TestCase:
|
||||
if (otherType != TestFunction && otherType != TestDataFunction && otherType != TestSpecialFunction)
|
||||
return nullptr;
|
||||
return name().isEmpty() ? findChildByNameAndFile(other->name(), other->filePath())
|
||||
return name().isEmpty() ? findChildByNameFileAndLine(other->name(), other->filePath(),
|
||||
other->line())
|
||||
: findChildByName(other->name());
|
||||
default:
|
||||
return nullptr;
|
||||
@@ -368,8 +370,7 @@ bool QuickTestTreeItem::modify(const TestParseResult *result)
|
||||
case TestFunction:
|
||||
case TestDataFunction:
|
||||
case TestSpecialFunction:
|
||||
return name().isEmpty() ? modifyLineAndColumn(result)
|
||||
: modifyTestFunctionContent(result);
|
||||
return modifyTestFunctionContent(result);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -454,6 +455,14 @@ TestTreeItem *QuickTestTreeItem::findChildByFileNameAndType(const QString &fileP
|
||||
});
|
||||
}
|
||||
|
||||
TestTreeItem *QuickTestTreeItem::findChildByNameFileAndLine(const QString &name,
|
||||
const QString &filePath, unsigned line)
|
||||
{
|
||||
return findFirstLevelChild([name, filePath, line](const TestTreeItem *other) {
|
||||
return other->filePath() == filePath && other->line() == line && other->name() == name;
|
||||
});
|
||||
}
|
||||
|
||||
TestTreeItem *QuickTestTreeItem::unnamedQuickTests() const
|
||||
{
|
||||
if (type() != Root)
|
||||
|
@@ -59,6 +59,8 @@ public:
|
||||
private:
|
||||
TestTreeItem *findChildByFileNameAndType(const QString &filePath, const QString &name,
|
||||
Type tType);
|
||||
TestTreeItem *findChildByNameFileAndLine(const QString &name, const QString &filePath,
|
||||
unsigned line);
|
||||
TestTreeItem *unnamedQuickTests() const;
|
||||
};
|
||||
|
||||
|
@@ -152,8 +152,17 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
|
||||
else
|
||||
locationAndType.m_type = TestTreeItem::TestFunction;
|
||||
|
||||
m_caseParseStack.top().m_functions.append(
|
||||
QuickTestFunctionSpec{name.toString(), locationAndType});
|
||||
const QString nameStr = name.toString();
|
||||
// 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;
|
||||
})) {
|
||||
m_caseParseStack.top().m_functions.append(
|
||||
QuickTestFunctionSpec{nameStr, locationAndType});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -67,5 +67,11 @@ TestCase {
|
||||
verify(true);
|
||||
}
|
||||
}
|
||||
|
||||
TestCase { // 2nd unnamed with same function name - legal as long it's a different TestCase
|
||||
function test_func() {
|
||||
verify(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user