forked from qt-creator/qt-creator
AutoTest: Use Utils::FilePath for files and directories
Still some missing bits as some QString members had different meanings depending on their context. Change-Id: Ib48eab54498974a26bbd5123cbffeefee5f7e79c Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -43,9 +43,10 @@ bool isQuickTestMacro(const QByteArray ¯o)
|
||||
return valid.contains(macro);
|
||||
}
|
||||
|
||||
QHash<QString, QString> proFilesForQmlFiles(ITestFramework *framework, const QStringList &files)
|
||||
QHash<Utils::FilePath, Utils::FilePath> proFilesForQmlFiles(ITestFramework *framework,
|
||||
const Utils::FilePaths &files)
|
||||
{
|
||||
QHash<QString, QString> result;
|
||||
QHash<Utils::FilePath, Utils::FilePath> result;
|
||||
TestTreeItem *rootNode = framework->rootNode();
|
||||
QTC_ASSERT(rootNode, return result);
|
||||
|
||||
@@ -53,16 +54,16 @@ QHash<QString, QString> proFilesForQmlFiles(ITestFramework *framework, const QSt
|
||||
return result;
|
||||
|
||||
rootNode->forFirstLevelChildItems([&result, &files](TestTreeItem *child) {
|
||||
const QString &file = child->filePath();
|
||||
const Utils::FilePath &file = child->filePath();
|
||||
if (!file.isEmpty() && files.contains(file)) {
|
||||
const QString &proFile = child->proFile();
|
||||
const Utils::FilePath &proFile = child->proFile();
|
||||
if (!proFile.isEmpty())
|
||||
result.insert(file, proFile);
|
||||
}
|
||||
child->forFirstLevelChildItems([&result, &files](TestTreeItem *grandChild) {
|
||||
const QString &file = grandChild->filePath();
|
||||
const Utils::FilePath &file = grandChild->filePath();
|
||||
if (!file.isEmpty() && files.contains(file)) {
|
||||
const QString &proFile = grandChild->proFile();
|
||||
const Utils::FilePath &proFile = grandChild->proFile();
|
||||
if (!proFile.isEmpty())
|
||||
result.insert(file, proFile);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QHash>
|
||||
|
||||
namespace Autotest {
|
||||
@@ -35,7 +37,8 @@ namespace Internal {
|
||||
namespace QuickTestUtils {
|
||||
|
||||
bool isQuickTestMacro(const QByteArray ¯o);
|
||||
QHash<QString, QString> proFilesForQmlFiles(ITestFramework *framework, const QStringList &files);
|
||||
QHash<Utils::FilePath, Utils::FilePath> proFilesForQmlFiles(ITestFramework *framework,
|
||||
const Utils::FilePaths &files);
|
||||
|
||||
} // namespace QuickTestUtils
|
||||
} // namespace Internal
|
||||
|
||||
@@ -42,7 +42,7 @@ ITestParser *QuickTestFramework::createTestParser()
|
||||
ITestTreeItem *QuickTestFramework::createRootNode()
|
||||
{
|
||||
return new QuickTestTreeItem(this, QCoreApplication::translate("QuickTestFramework", "Quick Test"),
|
||||
QString(), ITestTreeItem::Root);
|
||||
Utils::FilePath(), ITestTreeItem::Root);
|
||||
}
|
||||
|
||||
const char *QuickTestFramework::name() const
|
||||
|
||||
@@ -91,7 +91,7 @@ static bool includesQtQuickTest(const CPlusPlus::Document::Ptr &doc,
|
||||
}
|
||||
|
||||
static QString quickTestSrcDir(const CppTools::CppModelManager *cppMM,
|
||||
const QString &fileName)
|
||||
const Utils::FilePath &fileName)
|
||||
{
|
||||
const QList<CppTools::ProjectPart::Ptr> parts = cppMM->projectPart(fileName);
|
||||
if (parts.size() > 0) {
|
||||
@@ -122,14 +122,14 @@ QString QuickTestParser::quickTestName(const CPlusPlus::Document::Ptr &doc) cons
|
||||
const QByteArray name = macro.macro().name();
|
||||
if (QuickTestUtils::isQuickTestMacro(name)) {
|
||||
CPlusPlus::Document::Block arg = macro.arguments().at(0);
|
||||
return QLatin1String(getFileContent(doc->fileName())
|
||||
return QLatin1String(getFileContent(Utils::FilePath::fromString(doc->fileName()))
|
||||
.mid(int(arg.bytesBegin()), int(arg.bytesEnd() - arg.bytesBegin())));
|
||||
}
|
||||
}
|
||||
|
||||
// check for using quick_test_main() directly
|
||||
const QString fileName = doc->fileName();
|
||||
const QByteArray &fileContent = getFileContent(fileName);
|
||||
const QByteArray &fileContent = getFileContent(Utils::FilePath::fromString(fileName));
|
||||
CPlusPlus::Document::Ptr document = m_cppSnapshot.preprocessedDocument(fileContent, fileName);
|
||||
if (document.isNull())
|
||||
return QString();
|
||||
@@ -182,7 +182,7 @@ QList<Document::Ptr> QuickTestParser::scanDirectoryForQuickTestQmlFiles(const QS
|
||||
static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr> futureInterface,
|
||||
const Document::Ptr &qmlJSDoc,
|
||||
ITestFramework *framework,
|
||||
const QString &proFile = QString())
|
||||
const Utils::FilePath &proFile = Utils::FilePath())
|
||||
{
|
||||
if (qmlJSDoc.isNull())
|
||||
return false;
|
||||
@@ -203,7 +203,7 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr
|
||||
parseResult->proFile = proFile;
|
||||
parseResult->itemType = TestTreeItem::TestCase;
|
||||
if (!testCaseName.isEmpty()) {
|
||||
parseResult->fileName = testCase.m_locationAndType.m_name;
|
||||
parseResult->fileName = Utils::FilePath::fromString(testCase.m_locationAndType.m_name);
|
||||
parseResult->name = testCaseName;
|
||||
parseResult->line = testCase.m_locationAndType.m_line;
|
||||
parseResult->column = testCase.m_locationAndType.m_column;
|
||||
@@ -214,7 +214,7 @@ static bool checkQmlDocumentForQuickTestCode(QFutureInterface<TestParseResultPtr
|
||||
funcResult->name = function.m_functionName;
|
||||
funcResult->displayName = function.m_functionName;
|
||||
funcResult->itemType = function.m_locationAndType.m_type;
|
||||
funcResult->fileName = function.m_locationAndType.m_name;
|
||||
funcResult->fileName = Utils::FilePath::fromString(function.m_locationAndType.m_name);
|
||||
funcResult->line = function.m_locationAndType.m_line;
|
||||
funcResult->column = function.m_locationAndType.m_column;
|
||||
funcResult->proFile = proFile;
|
||||
@@ -235,11 +235,11 @@ bool QuickTestParser::handleQtQuickTest(QFutureInterface<TestParseResultPtr> fut
|
||||
if (quickTestName(document).isEmpty())
|
||||
return false;
|
||||
|
||||
const QString cppFileName = document->fileName();
|
||||
QList<CppTools::ProjectPart::Ptr> ppList = modelManager->projectPart(cppFileName);
|
||||
QList<CppTools::ProjectPart::Ptr> ppList = modelManager->projectPart(document->fileName());
|
||||
if (ppList.isEmpty()) // happens if shutting down while parsing
|
||||
return false;
|
||||
const QString &proFile = ppList.at(0)->projectFile;
|
||||
const Utils::FilePath cppFileName = Utils::FilePath::fromString(document->fileName());
|
||||
const Utils::FilePath proFile = Utils::FilePath::fromString(ppList.at(0)->projectFile);
|
||||
m_mainCppFiles.insert(cppFileName, proFile);
|
||||
const QString srcDir = quickTestSrcDir(modelManager, cppFileName);
|
||||
if (srcDir.isEmpty())
|
||||
@@ -315,14 +315,14 @@ QuickTestParser::QuickTestParser(ITestFramework *framework)
|
||||
this, &QuickTestParser::handleDirectoryChanged);
|
||||
}
|
||||
|
||||
void QuickTestParser::init(const QStringList &filesToParse, bool fullParse)
|
||||
void QuickTestParser::init(const Utils::FilePaths &filesToParse, bool fullParse)
|
||||
{
|
||||
m_qmlSnapshot = QmlJSTools::Internal::ModelManager::instance()->snapshot();
|
||||
if (!fullParse) {
|
||||
// in a full parse we get the correct entry points by the respective main
|
||||
m_proFilesForQmlFiles = QuickTestUtils::proFilesForQmlFiles(framework(), filesToParse);
|
||||
// get rid of cached main cpp files that are going to get processed anyhow
|
||||
for (const QString &file : filesToParse) {
|
||||
for (const Utils::FilePath &file : filesToParse) {
|
||||
if (m_mainCppFiles.contains(file)) {
|
||||
m_mainCppFiles.remove(file);
|
||||
if (m_mainCppFiles.isEmpty())
|
||||
@@ -344,13 +344,13 @@ void QuickTestParser::release()
|
||||
}
|
||||
|
||||
bool QuickTestParser::processDocument(QFutureInterface<TestParseResultPtr> futureInterface,
|
||||
const QString &fileName)
|
||||
const Utils::FilePath &fileName)
|
||||
{
|
||||
if (fileName.endsWith(".qml")) {
|
||||
const QString &proFile = m_proFilesForQmlFiles.value(fileName);
|
||||
const Utils::FilePath &proFile = m_proFilesForQmlFiles.value(fileName);
|
||||
if (proFile.isEmpty())
|
||||
return false;
|
||||
Document::Ptr qmlJSDoc = m_qmlSnapshot.document(fileName);
|
||||
Document::Ptr qmlJSDoc = m_qmlSnapshot.document(fileName.toString());
|
||||
return checkQmlDocumentForQuickTestCode(futureInterface, qmlJSDoc, framework(), proFile);
|
||||
}
|
||||
if (!m_cppSnapshot.contains(fileName) || !selectedForBuilding(fileName))
|
||||
@@ -361,9 +361,9 @@ bool QuickTestParser::processDocument(QFutureInterface<TestParseResultPtr> futur
|
||||
return handleQtQuickTest(futureInterface, document, framework());
|
||||
}
|
||||
|
||||
QString QuickTestParser::projectFileForMainCppFile(const QString &fileName) const
|
||||
Utils::FilePath QuickTestParser::projectFileForMainCppFile(const Utils::FilePath &fileName) const
|
||||
{
|
||||
return m_mainCppFiles.contains(fileName) ? m_mainCppFiles.value(fileName) : QString();
|
||||
return m_mainCppFiles.contains(fileName) ? m_mainCppFiles.value(fileName) : Utils::FilePath();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -46,11 +46,11 @@ class QuickTestParser : public QObject, public CppParser
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QuickTestParser(ITestFramework *framework);
|
||||
void init(const QStringList &filesToParse, bool fullParse) override;
|
||||
void init(const Utils::FilePaths &filesToParse, bool fullParse) override;
|
||||
void release() override;
|
||||
bool processDocument(QFutureInterface<TestParseResultPtr> futureInterface,
|
||||
const QString &fileName) override;
|
||||
QString projectFileForMainCppFile(const QString &fileName) const;
|
||||
const Utils::FilePath &fileName) override;
|
||||
Utils::FilePath projectFileForMainCppFile(const Utils::FilePath &fileName) const;
|
||||
private:
|
||||
bool handleQtQuickTest(QFutureInterface<TestParseResultPtr> futureInterface,
|
||||
CPlusPlus::Document::Ptr document, ITestFramework *framework);
|
||||
@@ -59,10 +59,10 @@ private:
|
||||
QString quickTestName(const CPlusPlus::Document::Ptr &doc) const;
|
||||
QList<QmlJS::Document::Ptr> scanDirectoryForQuickTestQmlFiles(const QString &srcDir);
|
||||
QmlJS::Snapshot m_qmlSnapshot;
|
||||
QHash<QString, QString> m_proFilesForQmlFiles;
|
||||
QHash<Utils::FilePath, Utils::FilePath> m_proFilesForQmlFiles;
|
||||
QFileSystemWatcher m_directoryWatcher;
|
||||
QMap<QString, QMap<QString, QDateTime> > m_watchedFiles;
|
||||
QMap<QString, QString> m_mainCppFiles;
|
||||
QMap<Utils::FilePath, Utils::FilePath> m_mainCppFiles;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
namespace Autotest {
|
||||
namespace Internal {
|
||||
|
||||
QSet<QString> internalTargets(const QString &proFile);
|
||||
QSet<QString> internalTargets(const Utils::FilePath &proFile);
|
||||
|
||||
TestTreeItem *QuickTestTreeItem::copyWithoutChildren()
|
||||
{
|
||||
@@ -170,7 +170,7 @@ static QList<ITestConfiguration *> testConfigurationsFor(
|
||||
if (!project || rootNode->type() != TestTreeItem::Root)
|
||||
return {};
|
||||
|
||||
QHash<QString, QuickTestConfiguration *> configurationForProFiles;
|
||||
QHash<Utils::FilePath, QuickTestConfiguration *> configurationForProFiles;
|
||||
rootNode->forSelectedChildren([&predicate, &configurationForProFiles](Utils::TreeItem *it) {
|
||||
auto treeItem = static_cast<TestTreeItem *>(it);
|
||||
if (treeItem->type() == TestTreeItem::Root || treeItem->type() == TestTreeItem::GroupNode)
|
||||
@@ -229,12 +229,12 @@ QList<ITestConfiguration *> QuickTestTreeItem::getAllTestConfigurations() const
|
||||
if (!project || type() != Root)
|
||||
return result;
|
||||
|
||||
QHash<QString, Tests> testsForProfile;
|
||||
QHash<Utils::FilePath, Tests> testsForProfile;
|
||||
forFirstLevelChildItems([&testsForProfile](TestTreeItem *child) {
|
||||
// unnamed Quick Tests must be handled separately
|
||||
if (child->name().isEmpty()) {
|
||||
child->forFirstLevelChildItems([&testsForProfile](TestTreeItem *grandChild) {
|
||||
const QString &proFile = grandChild->proFile();
|
||||
const Utils::FilePath &proFile = grandChild->proFile();
|
||||
++(testsForProfile[proFile].testCount);
|
||||
testsForProfile[proFile].internalTargets = internalTargets(grandChild->proFile());
|
||||
});
|
||||
@@ -278,9 +278,8 @@ QList<ITestConfiguration *> QuickTestTreeItem::getFailedTestConfigurations() con
|
||||
QList<ITestConfiguration *> QuickTestTreeItem::getTestConfigurationsForFile(
|
||||
const Utils::FilePath &fileName) const
|
||||
{
|
||||
const QString &file = fileName.toString();
|
||||
return testConfigurationsFor(this, [&file](TestTreeItem *it) {
|
||||
return it->filePath() == file;
|
||||
return testConfigurationsFor(this, [&fileName](TestTreeItem *it) {
|
||||
return it->filePath() == fileName;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -293,7 +292,7 @@ TestTreeItem *QuickTestTreeItem::find(const TestParseResult *result)
|
||||
if (result->name.isEmpty())
|
||||
return unnamedQuickTests();
|
||||
if (result->framework->grouping()) {
|
||||
const QString path = QFileInfo(result->fileName).absolutePath();
|
||||
const Utils::FilePath path = result->fileName.absolutePath();
|
||||
TestTreeItem *group = findFirstLevelChildItem([path](TestTreeItem *group) {
|
||||
return group->filePath() == path;
|
||||
});
|
||||
@@ -376,9 +375,8 @@ bool QuickTestTreeItem::removeOnSweepIfEmpty() const
|
||||
|
||||
TestTreeItem *QuickTestTreeItem::createParentGroupNode() const
|
||||
{
|
||||
const QFileInfo fileInfo(filePath());
|
||||
const QFileInfo base(fileInfo.absolutePath());
|
||||
return new QuickTestTreeItem(framework(), base.baseName(), fileInfo.absolutePath(), TestTreeItem::GroupNode);
|
||||
const QFileInfo base = filePath().absolutePath().toFileInfo();
|
||||
return new QuickTestTreeItem(framework(), base.baseName(), filePath().absolutePath(), TestTreeItem::GroupNode);
|
||||
}
|
||||
|
||||
bool QuickTestTreeItem::isGroupable() const
|
||||
@@ -386,7 +384,7 @@ bool QuickTestTreeItem::isGroupable() const
|
||||
return type() == TestCase && !name().isEmpty() && !filePath().isEmpty();
|
||||
}
|
||||
|
||||
QSet<QString> internalTargets(const QString &proFile)
|
||||
QSet<QString> internalTargets(const Utils::FilePath &proFile)
|
||||
{
|
||||
QSet<QString> result;
|
||||
const auto cppMM = CppTools::CppModelManager::instance();
|
||||
@@ -394,17 +392,17 @@ QSet<QString> internalTargets(const QString &proFile)
|
||||
for (const CppTools::ProjectPart::Ptr &projectPart : projectInfo.projectParts()) {
|
||||
if (projectPart->buildTargetType != ProjectExplorer::BuildTargetType::Executable)
|
||||
continue;
|
||||
if (projectPart->projectFile == proFile)
|
||||
if (projectPart->projectFile == proFile.toString())
|
||||
result.insert(projectPart->buildSystemTarget);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void QuickTestTreeItem::markForRemovalRecursively(const QString &filePath)
|
||||
void QuickTestTreeItem::markForRemovalRecursively(const Utils::FilePath &filePath)
|
||||
{
|
||||
TestTreeItem::markForRemovalRecursively(filePath);
|
||||
auto parser = dynamic_cast<QuickTestParser *>(framework()->testParser());
|
||||
const QString proFile = parser->projectFileForMainCppFile(filePath);
|
||||
const Utils::FilePath proFile = parser->projectFileForMainCppFile(filePath);
|
||||
if (!proFile.isEmpty()) {
|
||||
TestTreeItem *root = framework()->rootNode();
|
||||
root->forAllChildItems([proFile](TestTreeItem *it) {
|
||||
@@ -414,7 +412,7 @@ void QuickTestTreeItem::markForRemovalRecursively(const QString &filePath)
|
||||
}
|
||||
}
|
||||
|
||||
TestTreeItem *QuickTestTreeItem::findChildByFileNameAndType(const QString &filePath,
|
||||
TestTreeItem *QuickTestTreeItem::findChildByFileNameAndType(const Utils::FilePath &filePath,
|
||||
const QString &name,
|
||||
TestTreeItem::Type tType)
|
||||
|
||||
@@ -425,7 +423,8 @@ TestTreeItem *QuickTestTreeItem::findChildByFileNameAndType(const QString &fileP
|
||||
}
|
||||
|
||||
TestTreeItem *QuickTestTreeItem::findChildByNameFileAndLine(const QString &name,
|
||||
const QString &filePath, int line)
|
||||
const Utils::FilePath &filePath,
|
||||
int line)
|
||||
{
|
||||
return findFirstLevelChildItem([name, filePath, line](const TestTreeItem *other) {
|
||||
return other->filePath() == filePath && other->line() == line && other->name() == name;
|
||||
|
||||
@@ -35,7 +35,7 @@ class QuickTestTreeItem : public TestTreeItem
|
||||
public:
|
||||
explicit QuickTestTreeItem(ITestFramework *testFramework,
|
||||
const QString &name = QString(),
|
||||
const QString &filePath = QString(),
|
||||
const Utils::FilePath &filePath = Utils::FilePath(),
|
||||
Type type = Root)
|
||||
: TestTreeItem(testFramework, name, filePath, type)
|
||||
{}
|
||||
@@ -59,11 +59,11 @@ public:
|
||||
bool removeOnSweepIfEmpty() const override;
|
||||
TestTreeItem *createParentGroupNode() const override;
|
||||
bool isGroupable() const override;
|
||||
void markForRemovalRecursively(const QString &filePath) override;
|
||||
void markForRemovalRecursively(const Utils::FilePath &filePath) override;
|
||||
private:
|
||||
TestTreeItem *findChildByFileNameAndType(const QString &filePath, const QString &name,
|
||||
TestTreeItem *findChildByFileNameAndType(const Utils::FilePath &filePath, const QString &name,
|
||||
Type tType);
|
||||
TestTreeItem *findChildByNameFileAndLine(const QString &name, const QString &filePath,
|
||||
TestTreeItem *findChildByNameFileAndLine(const QString &name, const Utils::FilePath &filePath,
|
||||
int line);
|
||||
TestTreeItem *unnamedQuickTests() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user