forked from qt-creator/qt-creator
When loading a Qt project, after the Scanning For Tests finished, the scanForTests() blocks the main thread for about 3.5 seconds on the calls to parser->init(). Refactor the code so that it operates on QSet<FilePath> instead of QList<FilePaths>. This patch constraints the freeze to about 40 ms. Change-Id: I219b3e2abf2b7e5166eec08d83f4cdcb8e4a8098 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
67 lines
2.3 KiB
C++
67 lines
2.3 KiB
C++
// Copyright (C) 2016 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
#pragma once
|
|
|
|
#include "../itestparser.h"
|
|
|
|
#include "qttest_utils.h"
|
|
#include "qttesttreeitem.h"
|
|
|
|
#include <optional>
|
|
|
|
namespace CppEditor { class CppModelManager; }
|
|
|
|
namespace Autotest {
|
|
namespace Internal {
|
|
|
|
class QtTestParseResult : public TestParseResult
|
|
{
|
|
public:
|
|
explicit QtTestParseResult(ITestFramework *framework) : TestParseResult(framework) {}
|
|
void setInherited(bool inherited) { m_inherited = inherited; }
|
|
bool inherited() const { return m_inherited; }
|
|
void setRunsMultipleTestcases(bool multi) { m_multiTest = multi; }
|
|
bool runsMultipleTestcases() const { return m_multiTest; }
|
|
TestTreeItem *createTestTreeItem() const override;
|
|
private:
|
|
bool m_inherited = false;
|
|
bool m_multiTest = false;
|
|
};
|
|
|
|
class QtTestParser : public CppParser
|
|
{
|
|
public:
|
|
explicit QtTestParser(ITestFramework *framework) : CppParser(framework) {}
|
|
|
|
void init(const QSet<Utils::FilePath> &filesToParse, bool fullParse) override;
|
|
void release() override;
|
|
bool processDocument(QPromise<TestParseResultPtr> &promise,
|
|
const Utils::FilePath &fileName) override;
|
|
|
|
private:
|
|
TestCases testCases(const CppEditor::CppModelManager *modelManager,
|
|
const Utils::FilePath &fileName) const;
|
|
QHash<QString, QtTestCodeLocationList> checkForDataTags(const Utils::FilePath &fileName) const;
|
|
struct TestCaseData {
|
|
Utils::FilePath fileName;
|
|
int line = 0;
|
|
int column = 0;
|
|
QMap<QString, QtTestCodeLocationAndType> testFunctions;
|
|
QHash<QString, QtTestCodeLocationList> dataTags;
|
|
bool multipleTestCases = false;
|
|
bool valid = false;
|
|
};
|
|
|
|
std::optional<bool> fillTestCaseData(const QString &testCaseName,
|
|
const CPlusPlus::Document::Ptr &doc,
|
|
TestCaseData &data) const;
|
|
QtTestParseResult *createParseResult(const QString &testCaseName, const TestCaseData &data,
|
|
const QString &projectFile) const;
|
|
QHash<Utils::FilePath, TestCases> m_testCases;
|
|
QMultiHash<Utils::FilePath, Utils::FilePath> m_alternativeFiles;
|
|
};
|
|
|
|
} // namespace Internal
|
|
} // namespace Autotest
|