AutoTest: Prefer ITestParser to ITestFramework in TestCodeParser

Preserves the level of abstraction.

Change-Id: I01354fc8fcdf846dd2ef2a20fce12f6e9c4756b2
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Bernhard Beschow
2021-01-01 19:19:33 +01:00
parent 2674e9c62e
commit c16f8ce988
3 changed files with 29 additions and 37 deletions

View File

@@ -108,7 +108,7 @@ void TestCodeParser::setState(State state)
}
}
void TestCodeParser::syncTestFrameworks(const QList<ITestFramework *> &frameworks)
void TestCodeParser::syncTestFrameworks(const QList<ITestParser *> &parsers)
{
if (m_parserState != Idle) {
// there's a running parse
@@ -116,13 +116,8 @@ void TestCodeParser::syncTestFrameworks(const QList<ITestFramework *> &framework
m_postponedFiles.clear();
Core::ProgressManager::cancelTasks(Constants::TASK_PARSE);
}
m_testCodeParsers.clear();
qCDebug(LOG) << "Setting" << frameworks << "as current parsers";
for (ITestFramework *framework : frameworks) {
ITestParser *testParser = framework->testParser();
QTC_ASSERT(testParser, continue); // buildsystem based frameworks have no code parser
m_testCodeParsers.append(testParser);
}
qCDebug(LOG) << "Setting" << parsers << "as current parsers";
m_testCodeParsers = parsers;
}
void TestCodeParser::emitUpdateTestTree(ITestParser *parser)
@@ -130,7 +125,7 @@ void TestCodeParser::emitUpdateTestTree(ITestParser *parser)
if (m_testCodeParsers.isEmpty())
return;
if (parser)
m_updateParsers.insert(parser->framework());
m_updateParsers.insert(parser);
else
m_updateParsers.clear();
if (m_singleShotScheduled) {
@@ -143,18 +138,18 @@ void TestCodeParser::emitUpdateTestTree(ITestParser *parser)
QTimer::singleShot(1000, this, [this]() { updateTestTree(m_updateParsers); });
}
void TestCodeParser::updateTestTree(const QSet<ITestFramework *> &frameworks)
void TestCodeParser::updateTestTree(const QSet<ITestParser *> &parsers)
{
m_singleShotScheduled = false;
if (m_codeModelParsing) {
m_fullUpdatePostponed = true;
m_partialUpdatePostponed = false;
m_postponedFiles.clear();
if (frameworks.isEmpty()) {
if (parsers.isEmpty()) {
m_updateParsers.clear();
} else {
for (ITestFramework *framework : frameworks)
m_updateParsers.insert(framework);
for (ITestParser *parser : parsers)
m_updateParsers.insert(parser);
}
return;
}
@@ -164,9 +159,11 @@ void TestCodeParser::updateTestTree(const QSet<ITestFramework *> &frameworks)
m_fullUpdatePostponed = false;
qCDebug(LOG) << "calling scanForTests (updateTestTree)";
TestFrameworks sortedFrameworks = Utils::toList(frameworks);
Utils::sort(sortedFrameworks, &ITestFramework::priority);
scanForTests(QStringList(), sortedFrameworks);
QList<ITestParser *> sortedParsers = Utils::toList(parsers);
Utils::sort(sortedParsers, [](const ITestParser *lhs, const ITestParser *rhs) {
return lhs->framework()->priority() < rhs->framework()->priority();
});
scanForTests(QStringList(), sortedParsers);
}
/****** threaded parsing stuff *******/
@@ -296,7 +293,7 @@ static void parseFileForTests(const QList<ITestParser *> &parsers,
}
}
void TestCodeParser::scanForTests(const QStringList &fileList, const QList<ITestFramework *> &parsers)
void TestCodeParser::scanForTests(const QStringList &fileList, const QList<ITestParser *> &parsers)
{
if (m_parserState == Shutdown || m_testCodeParsers.isEmpty())
return;
@@ -337,18 +334,16 @@ void TestCodeParser::scanForTests(const QStringList &fileList, const QList<ITest
return !fn.endsWith(".qml");
});
if (!parsers.isEmpty()) {
for (ITestFramework *framework : parsers) {
QTC_ASSERT(framework->testParser(), continue); // mark only frameworks with a parser
framework->rootNode()->markForRemovalRecursively(true);
for (ITestParser *parser : parsers) {
parser->framework()->rootNode()->markForRemovalRecursively(true);
}
} else {
emit requestRemoveAllFrameworkItems();
}
} else if (!parsers.isEmpty()) {
for (ITestFramework *framework : parsers) {
for (ITestParser *parser: parsers) {
for (const QString &filePath : qAsConst(list)) {
QTC_ASSERT(framework->testParser(), continue);
framework->rootNode()->markForRemovalRecursively(filePath);
parser->framework()->rootNode()->markForRemovalRecursively(filePath);
}
}
} else {
@@ -359,9 +354,7 @@ void TestCodeParser::scanForTests(const QStringList &fileList, const QList<ITest
QTC_ASSERT(!(isFullParse && list.isEmpty()), onFinished(); return);
// use only a single parser or all current active?
const QList<ITestParser *> codeParsers
= parsers.isEmpty() ? m_testCodeParsers
: Utils::transform(parsers, &ITestFramework::testParser);
const QList<ITestParser *> codeParsers = parsers.isEmpty() ? m_testCodeParsers : parsers;
qCDebug(LOG) << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "StartParsing";
for (ITestParser *parser : codeParsers)
parser->init(list, isFullParse);