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;
|
<< 1 << 0 << 0 << 0;
|
||||||
QTest::newRow("mixedAutoTestAndQuickTests")
|
QTest::newRow("mixedAutoTestAndQuickTests")
|
||||||
<< QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.pro")
|
<< QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.pro")
|
||||||
<< 4 << 10 << 4 << 10;
|
<< 4 << 10 << 5 << 10;
|
||||||
QTest::newRow("plainAutoTestQbs")
|
QTest::newRow("plainAutoTestQbs")
|
||||||
<< QString(m_tmpDir->path() + "/plain/plain.qbs")
|
<< QString(m_tmpDir->path() + "/plain/plain.qbs")
|
||||||
<< 1 << 0 << 0 << 0;
|
<< 1 << 0 << 0 << 0;
|
||||||
QTest::newRow("mixedAutoTestAndQuickTestsQbs")
|
QTest::newRow("mixedAutoTestAndQuickTestsQbs")
|
||||||
<< QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.qbs")
|
<< QString(m_tmpDir->path() + "/mixed_atp/mixed_atp.qbs")
|
||||||
<< 4 << 10 << 4 << 10;
|
<< 4 << 10 << 5 << 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTestUnitTests::testCodeParserSwitchStartup()
|
void AutoTestUnitTests::testCodeParserSwitchStartup()
|
||||||
@@ -184,7 +184,7 @@ void AutoTestUnitTests::testCodeParserSwitchStartup_data()
|
|||||||
|
|
||||||
QList<int> expectedAutoTests = QList<int>() << 1 << 4 << 1 << 4;
|
QList<int> expectedAutoTests = QList<int>() << 1 << 4 << 1 << 4;
|
||||||
QList<int> expectedNamedQuickTests = QList<int>() << 0 << 10 << 0 << 10;
|
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;
|
QList<int> expectedDataTagsCount = QList<int>() << 0 << 10 << 0 << 10;
|
||||||
|
|
||||||
QTest::newRow("loadMultipleProjects")
|
QTest::newRow("loadMultipleProjects")
|
||||||
|
@@ -95,7 +95,8 @@ bool QtTestResult::isDirectParentOf(const TestResult *other, bool *needsIntermed
|
|||||||
return qtOther->m_dataTag == m_dataTag;
|
return qtOther->m_dataTag == m_dataTag;
|
||||||
}
|
}
|
||||||
} else if (qtOther->isTestFunction()) {
|
} else if (qtOther->isTestFunction()) {
|
||||||
return isTestCase() || m_function == qtOther->m_function;
|
return isTestCase() || (m_function == qtOther->m_function
|
||||||
|
&& qtOther->result() != ResultType::TestStart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@@ -329,7 +329,8 @@ TestTreeItem *QuickTestTreeItem::find(const TestParseResult *result)
|
|||||||
case GroupNode:
|
case GroupNode:
|
||||||
return findChildByNameAndFile(result->name, result->fileName);
|
return findChildByNameAndFile(result->name, result->fileName);
|
||||||
case TestCase:
|
case TestCase:
|
||||||
return name().isEmpty() ? findChildByNameAndFile(result->name, result->fileName)
|
return name().isEmpty() ? findChildByNameFileAndLine(result->name, result->fileName,
|
||||||
|
result->line)
|
||||||
: findChildByName(result->name);
|
: findChildByName(result->name);
|
||||||
default:
|
default:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -351,7 +352,8 @@ TestTreeItem *QuickTestTreeItem::findChild(const TestTreeItem *other)
|
|||||||
case TestCase:
|
case TestCase:
|
||||||
if (otherType != TestFunction && otherType != TestDataFunction && otherType != TestSpecialFunction)
|
if (otherType != TestFunction && otherType != TestDataFunction && otherType != TestSpecialFunction)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return name().isEmpty() ? findChildByNameAndFile(other->name(), other->filePath())
|
return name().isEmpty() ? findChildByNameFileAndLine(other->name(), other->filePath(),
|
||||||
|
other->line())
|
||||||
: findChildByName(other->name());
|
: findChildByName(other->name());
|
||||||
default:
|
default:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -368,8 +370,7 @@ bool QuickTestTreeItem::modify(const TestParseResult *result)
|
|||||||
case TestFunction:
|
case TestFunction:
|
||||||
case TestDataFunction:
|
case TestDataFunction:
|
||||||
case TestSpecialFunction:
|
case TestSpecialFunction:
|
||||||
return name().isEmpty() ? modifyLineAndColumn(result)
|
return modifyTestFunctionContent(result);
|
||||||
: modifyTestFunctionContent(result);
|
|
||||||
default:
|
default:
|
||||||
return false;
|
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
|
TestTreeItem *QuickTestTreeItem::unnamedQuickTests() const
|
||||||
{
|
{
|
||||||
if (type() != Root)
|
if (type() != Root)
|
||||||
|
@@ -59,6 +59,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
TestTreeItem *findChildByFileNameAndType(const QString &filePath, const QString &name,
|
TestTreeItem *findChildByFileNameAndType(const QString &filePath, const QString &name,
|
||||||
Type tType);
|
Type tType);
|
||||||
|
TestTreeItem *findChildByNameFileAndLine(const QString &name, const QString &filePath,
|
||||||
|
unsigned line);
|
||||||
TestTreeItem *unnamedQuickTests() const;
|
TestTreeItem *unnamedQuickTests() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -152,8 +152,17 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
|
|||||||
else
|
else
|
||||||
locationAndType.m_type = TestTreeItem::TestFunction;
|
locationAndType.m_type = TestTreeItem::TestFunction;
|
||||||
|
|
||||||
|
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(
|
m_caseParseStack.top().m_functions.append(
|
||||||
QuickTestFunctionSpec{name.toString(), locationAndType});
|
QuickTestFunctionSpec{nameStr, locationAndType});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -67,5 +67,11 @@ TestCase {
|
|||||||
verify(true);
|
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