forked from qt-creator/qt-creator
AutoTest: Fix detection of Quick tests name
Avoid setting and overwriting the test case name with any string literal we find inside the TestCase item. Instead use only the string literal used for the name property and do not overwrite it after it had been set. Task-number: QTCREATORBUG-20642 Change-Id: I69aedfc9f51df4943370c4736e6aa2af4c39b697 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -84,7 +84,9 @@ 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());
|
||||
if (name != "TestCase") {
|
||||
m_insideTestCase = false;
|
||||
if (!isDerivedFromTestCase(ast->qualifiedTypeNameId, m_currentDoc, m_snapshot))
|
||||
return true;
|
||||
} else if (!documentImportsQtTest(m_currentDoc.data())) {
|
||||
@@ -92,6 +94,7 @@ bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
|
||||
}
|
||||
|
||||
m_typeIsTestCase = true;
|
||||
m_insideTestCase = true;
|
||||
m_currentTestCaseName.clear();
|
||||
const auto sourceLocation = ast->firstSourceLocation();
|
||||
m_testCaseLocation.m_name = m_currentDoc->fileName();
|
||||
@@ -101,6 +104,11 @@ bool TestQmlVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestQmlVisitor::endVisit(QmlJS::AST::UiObjectDefinition *)
|
||||
{
|
||||
m_insideTestCase = m_objectStack.pop() == "TestCase";
|
||||
}
|
||||
|
||||
bool TestQmlVisitor::visit(QmlJS::AST::ExpressionStatement *ast)
|
||||
{
|
||||
const QmlJS::AST::ExpressionNode *expr = ast->expression;
|
||||
@@ -109,8 +117,15 @@ bool TestQmlVisitor::visit(QmlJS::AST::ExpressionStatement *ast)
|
||||
|
||||
bool TestQmlVisitor::visit(QmlJS::AST::UiScriptBinding *ast)
|
||||
{
|
||||
const QStringRef name = ast->qualifiedId->name;
|
||||
return name == "name";
|
||||
if (m_insideTestCase)
|
||||
m_expectTestCaseName = ast->qualifiedId->name == "name";
|
||||
return m_expectTestCaseName;
|
||||
}
|
||||
|
||||
void TestQmlVisitor::endVisit(QmlJS::AST::UiScriptBinding *)
|
||||
{
|
||||
if (m_expectTestCaseName)
|
||||
m_expectTestCaseName = false;
|
||||
}
|
||||
|
||||
bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
|
||||
@@ -139,8 +154,10 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
|
||||
|
||||
bool TestQmlVisitor::visit(QmlJS::AST::StringLiteral *ast)
|
||||
{
|
||||
if (m_typeIsTestCase)
|
||||
if (m_expectTestCaseName && m_currentTestCaseName.isEmpty()) {
|
||||
m_currentTestCaseName = ast->value.toString();
|
||||
m_expectTestCaseName = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user