AutoTest: fine tune quick test case specs

and fix multiple inheritance

Change-Id: I031c8518437b7b396f5b17a51d2067e4b3661530
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2019-07-30 13:17:35 +02:00
committed by Christian Stenger
parent c020fb6e3e
commit 6e84529a88
3 changed files with 49 additions and 51 deletions

View File

@@ -86,34 +86,29 @@ static bool isDerivedFromTestCase(QmlJS::AST::UiQualifiedId *id, const QmlJS::Do
bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
{
const QStringRef name = ast->qualifiedTypeNameId->name;
m_objectStack.push(name.toString());
m_objectIsTestStack.push(false);
if (name != "TestCase") {
m_insideTestCase = false;
if (!isDerivedFromTestCase(ast->qualifiedTypeNameId, m_currentDoc, m_snapshot))
return true;
} else if (!documentImportsQtTest(m_currentDoc.data())) {
return true; // find nested TestCase items as well
}
m_typeIsTestCase = true;
m_insideTestCase = true;
m_objectIsTestStack.top() = true;
const auto sourceLocation = ast->firstSourceLocation();
QuickTestCaseSpec currentSpec;
currentSpec.m_name = m_currentDoc->fileName();
currentSpec.m_line = sourceLocation.startLine;
currentSpec.m_column = sourceLocation.startColumn - 1;
currentSpec.m_type = TestTreeItem::TestCase;
m_testCases.push(currentSpec);
currentSpec.m_locationAndType.m_name = 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;
m_caseParseStack.push(currentSpec);
return true;
}
void TestQmlVisitor::endVisit(QmlJS::AST::UiObjectDefinition *)
{
if (!m_objectStack.isEmpty() && m_objectStack.pop() == "TestCase") {
if (!m_testCases.isEmpty())
m_testCases.pop();
m_insideTestCase = !m_objectStack.isEmpty() && m_objectStack.top() == "TestCase";
}
if (!m_objectIsTestStack.isEmpty() && m_objectIsTestStack.pop() && !m_caseParseStack.isEmpty())
m_testCases << m_caseParseStack.pop();
}
bool TestQmlVisitor::visit(QmlJS::AST::ExpressionStatement *ast)
@@ -124,7 +119,7 @@ bool TestQmlVisitor::visit(QmlJS::AST::ExpressionStatement *ast)
bool TestQmlVisitor::visit(QmlJS::AST::UiScriptBinding *ast)
{
if (m_insideTestCase)
if (m_objectIsTestStack.top())
m_expectTestCaseName = ast->qualifiedId->name == "name";
return m_expectTestCaseName;
}
@@ -137,6 +132,9 @@ void TestQmlVisitor::endVisit(QmlJS::AST::UiScriptBinding *)
bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
{
if (m_caseParseStack.isEmpty())
return false;
const QStringRef name = ast->name;
if (name.startsWith("test_")
|| name.startsWith("benchmark_")
@@ -154,13 +152,8 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
else
locationAndType.m_type = TestTreeItem::TestFunction;
if (m_testCases.isEmpty()) // invalid qml code
return false;
QuickTestCaseSpec testCaseWithFunc = m_testCases.top();
testCaseWithFunc.m_functionName = name.toString();
testCaseWithFunc.m_functionLocationAndType = locationAndType;
m_testFunctions.append(testCaseWithFunc);
m_caseParseStack.top().m_functions.append(
QuickTestFunctionSpec{name.toString(), locationAndType});
}
return false;
}
@@ -168,8 +161,8 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
bool TestQmlVisitor::visit(QmlJS::AST::StringLiteral *ast)
{
if (m_expectTestCaseName) {
QTC_ASSERT(!m_testCases.isEmpty(), return false);
m_testCases.top().m_caseName = ast->value.toString();
QTC_ASSERT(!m_caseParseStack.isEmpty(), return false);
m_caseParseStack.top().m_caseName = ast->value.toString();
m_expectTestCaseName = false;
}
return false;