forked from qt-creator/qt-creator
Unit tests: Explicitly check for success from runner.
We will otherwise miss runner failures for any file that does not contribute to the diagnostics count. Note: The tool can also fail during the building stage, but in this case we will get notified by the signal spy timing out. Change-Id: Ia9aa797d658b1752e3da6e08a652ee55868955ba Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -214,6 +214,7 @@ QList<ClangStaticAnalyzerRunControl::AnalyzeUnit> ClangStaticAnalyzerRunControl:
|
||||
|
||||
bool ClangStaticAnalyzerRunControl::startEngine()
|
||||
{
|
||||
m_success = false;
|
||||
emit starting(this);
|
||||
|
||||
QTC_ASSERT(m_projectInfo.isValid(), emit finished(); return false);
|
||||
@@ -277,6 +278,7 @@ bool ClangStaticAnalyzerRunControl::startEngine()
|
||||
m_runners.clear();
|
||||
const int parallelRuns = ClangStaticAnalyzerSettings::instance()->simultaneousProcesses();
|
||||
QTC_ASSERT(parallelRuns >= 1, emit finished(); return false);
|
||||
m_success = true;
|
||||
while (m_runners.size() < parallelRuns && !m_unitsToProcess.isEmpty())
|
||||
analyzeNextFile();
|
||||
return true;
|
||||
@@ -373,6 +375,7 @@ void ClangStaticAnalyzerRunControl::onRunnerFinishedWithFailure(const QString &e
|
||||
qCDebug(LOG) << "onRunnerFinishedWithFailure:" << errorMessage << errorDetails;
|
||||
|
||||
++m_filesNotAnalyzed;
|
||||
m_success = false;
|
||||
const QString filePath = qobject_cast<ClangStaticAnalyzerRunner *>(sender())->filePath();
|
||||
appendMessage(tr("Failed to analyze \"%1\": %2").arg(filePath, errorMessage)
|
||||
+ QLatin1Char('\n')
|
||||
|
@@ -52,6 +52,8 @@ public:
|
||||
bool startEngine();
|
||||
void stopEngine();
|
||||
|
||||
bool success() const { return m_success; } // For testing.
|
||||
|
||||
signals:
|
||||
void newDiagnosticsAvailable(const QList<Diagnostic> &diagnostics);
|
||||
|
||||
@@ -80,6 +82,7 @@ private:
|
||||
int m_initialFilesToProcessSize;
|
||||
int m_filesAnalyzed;
|
||||
int m_filesNotAnalyzed;
|
||||
bool m_success;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -228,10 +228,10 @@ void ClangStaticAnalyzerTool::startTool()
|
||||
m_diagnosticModel->clear();
|
||||
setBusyCursor(true);
|
||||
Project *project = SessionManager::startupProject();
|
||||
QTC_ASSERT(project, return);
|
||||
QTC_ASSERT(project, emit finished(false); return);
|
||||
m_diagnosticFilterModel->setProject(project);
|
||||
m_projectInfoBeforeBuild = CppTools::CppModelManager::instance()->projectInfo(project);
|
||||
QTC_ASSERT(m_projectInfoBeforeBuild.isValid(), return);
|
||||
QTC_ASSERT(m_projectInfoBeforeBuild.isValid(), emit finished(false); return);
|
||||
m_running = true;
|
||||
handleStateUpdate();
|
||||
|
||||
@@ -284,7 +284,7 @@ void ClangStaticAnalyzerTool::onEngineFinished()
|
||||
resetCursorAndProjectInfoBeforeBuild();
|
||||
m_running = false;
|
||||
handleStateUpdate();
|
||||
emit finished();
|
||||
emit finished(static_cast<ClangStaticAnalyzerRunControl *>(sender())->success());
|
||||
}
|
||||
|
||||
void ClangStaticAnalyzerTool::setBusyCursor(bool busy)
|
||||
|
@@ -57,7 +57,7 @@ public:
|
||||
void startTool();
|
||||
|
||||
signals:
|
||||
void finished(); // For testing.
|
||||
void finished(bool success); // For testing.
|
||||
|
||||
private:
|
||||
void onEngineIsStarting();
|
||||
|
@@ -83,10 +83,10 @@ void ClangStaticAnalyzerUnitTests::testProject()
|
||||
QVERIFY(projectInfo.isValid());
|
||||
AnalyzerManager::selectTool(ClangStaticAnalyzerToolId);
|
||||
AnalyzerManager::startTool();
|
||||
if (m_analyzerTool->isRunning()) {
|
||||
QSignalSpy waiter(m_analyzerTool, SIGNAL(finished()));
|
||||
QSignalSpy waiter(m_analyzerTool, SIGNAL(finished(bool)));
|
||||
QVERIFY(waiter.wait(30000));
|
||||
}
|
||||
const QList<QVariant> arguments = waiter.takeFirst();
|
||||
QVERIFY(arguments.first().toBool());
|
||||
QCOMPARE(m_analyzerTool->diagnostics().count(), expectedDiagCount);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user