Commit f967545c authored by Christian Stenger's avatar Christian Stenger

AutoTest: Fix handling of enabled state for code parser

Avoid unintentional re-enabling of the code parser.
Handling of the enabled state broke several times before,
therefore separate it from other states of the parser to
avoid breaking it again when not taking enough care while
refactoring or adding features related to states.

Change-Id: If1eb0dd649225f10bfc3bf06f09851649da75983
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent b5f587ef
......@@ -178,6 +178,7 @@ void AutotestPlugin::onRunSelectedTriggered()
void AutotestPlugin::updateMenuItemsEnabledState()
{
const bool enabled = !TestRunner::instance()->isTestRunning()
&& TestTreeModel::instance()->parser()->enabled()
&& TestTreeModel::instance()->parser()->state() == TestCodeParser::Idle;
const bool hasTests = TestTreeModel::instance()->hasTests();
......
......@@ -81,7 +81,7 @@ TestCodeParser::~TestCodeParser()
void TestCodeParser::setState(State state)
{
if (m_parserState == Shutdown)
if (m_parserState == Shutdown || !m_enabled)
return;
qCDebug(LOG) << "setState(" << state << "), currentState:" << m_parserState;
// avoid triggering parse before code model parsing has finished, but mark as dirty
......@@ -91,17 +91,13 @@ void TestCodeParser::setState(State state)
return;
}
if ((state == Disabled || state == Idle)
&& (m_parserState == PartialParse || m_parserState == FullParse)) {
if ((state == Idle) && (m_parserState == PartialParse || m_parserState == FullParse)) {
qCDebug(LOG) << "Not setting state, parse is running";
return;
}
m_parserState = state;
if (m_parserState == Disabled) {
m_fullUpdatePostponed = m_partialUpdatePostponed = false;
m_postponedFiles.clear();
} else if (m_parserState == Idle && ProjectExplorer::SessionManager::startupProject()) {
if (m_parserState == Idle && ProjectExplorer::SessionManager::startupProject()) {
if (m_fullUpdatePostponed || m_dirty) {
emitUpdateTestTree();
} else if (m_partialUpdatePostponed) {
......@@ -115,7 +111,7 @@ void TestCodeParser::setState(State state)
void TestCodeParser::syncTestFrameworks(const QVector<Core::Id> &frameworkIds)
{
if (m_parserState != Disabled && m_parserState != Idle) {
if (m_enabled && m_parserState != Idle) {
// there's a running parse
m_fullUpdatePostponed = m_partialUpdatePostponed = false;
m_postponedFiles.clear();
......@@ -129,7 +125,7 @@ void TestCodeParser::syncTestFrameworks(const QVector<Core::Id> &frameworkIds)
QTC_ASSERT(testParser, continue);
m_testCodeParsers.append(testParser);
}
if (m_parserState != Disabled)
if (m_enabled)
updateTestTree();
}
......@@ -211,7 +207,7 @@ void TestCodeParser::onProjectPartsUpdated(ProjectExplorer::Project *project)
{
if (project != ProjectExplorer::SessionManager::startupProject())
return;
if (m_codeModelParsing || m_parserState == Disabled)
if (m_codeModelParsing || !m_enabled)
m_fullUpdatePostponed = true;
else
emitUpdateTestTree();
......@@ -276,7 +272,6 @@ bool TestCodeParser::postponed(const QStringList &fileList)
m_partialUpdatePostponed = true;
}
return true;
case Disabled:
case Shutdown:
break;
}
......@@ -297,7 +292,9 @@ static void parseFileForTests(const QVector<ITestParser *> &parsers,
void TestCodeParser::scanForTests(const QStringList &fileList)
{
if (m_parserState == Disabled || m_parserState == Shutdown) {
if (m_parserState == Shutdown)
return;
if (!m_enabled) {
m_dirty = true;
if (fileList.isEmpty()) {
m_fullUpdatePostponed = true;
......@@ -419,11 +416,6 @@ void TestCodeParser::onFinished()
}
m_dirty = false;
break;
case Disabled: // can happen if all Test related widgets become hidden while parsing
qCDebug(LOG) << "emitting parsingFinished (onFinished, Disabled)";
emit parsingFinished();
qCDebug(LOG) << QDateTime::currentDateTime().toString("hh:mm:ss.zzz") << "ParsingFin";
break;
case Shutdown:
qCDebug(LOG) << "Shutdown complete - not emitting parsingFinished (onFinished)";
break;
......
......@@ -49,7 +49,6 @@ public:
Idle,
PartialParse,
FullParse,
Disabled,
Shutdown
};
......@@ -57,6 +56,8 @@ public:
virtual ~TestCodeParser();
void setState(State state);
State state() const { return m_parserState; }
void setEnabled(bool enabled) { m_enabled = enabled; }
bool enabled() const { return m_enabled; }
bool isParsing() const { return m_parserState == PartialParse || m_parserState == FullParse; }
void setDirty() { m_dirty = true; }
void syncTestFrameworks(const QVector<Core::Id> &frameworkIds);
......@@ -95,6 +96,7 @@ private:
TestTreeModel *m_model;
bool m_enabled = false;
bool m_codeModelParsing = false;
bool m_fullUpdatePostponed = false;
bool m_partialUpdatePostponed = false;
......@@ -102,7 +104,7 @@ private:
bool m_singleShotScheduled = false;
bool m_reparseTimerTimedOut = false;
QSet<QString> m_postponedFiles;
State m_parserState = Disabled;
State m_parserState = Idle;
QFutureWatcher<TestParseResultPtr> m_futureWatcher;
QVector<ITestParser *> m_testCodeParsers; // ptrs are still owned by TestFrameworkManager
QTimer m_reparseTimer;
......
......@@ -115,7 +115,7 @@ TestNavigationWidget::~TestNavigationWidget()
void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
{
const bool enabled = !TestRunner::instance()->isTestRunning()
&& m_model->parser()->state() == TestCodeParser::Idle;
&& m_model->parser()->enabled() && m_model->parser()->state() == TestCodeParser::Idle;
const bool hasTests = m_model->hasTests();
QMenu menu;
......
......@@ -90,6 +90,7 @@ void TestTreeModel::setupParsingConnections()
if (!m_connectionsInitialized)
m_parser->setDirty();
m_parser->setEnabled(true);
m_parser->setState(TestCodeParser::Idle);
if (m_connectionsInitialized)
return;
......@@ -117,13 +118,13 @@ void TestTreeModel::setupParsingConnections()
void TestTreeModel::disableParsing()
{
if (!m_refCounter.deref() && !AutotestPlugin::instance()->settings()->alwaysParse)
m_parser->setState(TestCodeParser::Disabled);
m_parser->setEnabled(false);
}
void TestTreeModel::disableParsingFromSettings()
{
if (!m_refCounter.load())
m_parser->setState(TestCodeParser::Disabled);
m_parser->setEnabled(false);
}
bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment