Files
qt-creator/tests/unit/unittest/modulescanner-test.cpp
Marco Bubke 34c69766dd QmlDesigner: Add version scanning for Qt5
Add some hardwired code for lagacy Qt5 support.

Task-number: QDS-9542
Change-Id: I505685042f53b7e653e76c8d883c8d7bb30605d7
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-04-19 15:58:21 +00:00

74 lines
1.9 KiB
C++

// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "googletest.h"
#include <projectstorage/modulescanner.h>
#include <QDebug>
namespace {
template<typename Matcher>
auto UrlProperty(const Matcher &matcher)
{
return Property(&QmlDesigner::Import::url, matcher);
}
template<typename Matcher>
auto VersionProperty(const Matcher &matcher)
{
return Property(&QmlDesigner::Import::version, matcher);
}
class ModuleScanner : public testing::Test
{
protected:
QmlDesigner::ModuleScanner scanner{[](QStringView moduleName) {
return moduleName.endsWith(u"impl");
},
QmlDesigner::VersionScanning::No};
};
TEST_F(ModuleScanner, ReturnEmptyOptionalForWrongPath)
{
scanner.scan(QStringList{""});
ASSERT_THAT(scanner.modules(), IsEmpty());
}
TEST_F(ModuleScanner, GetQtQuick)
{
scanner.scan(QStringList{QT6_INSTALL_PREFIX});
ASSERT_THAT(scanner.modules(), Contains(UrlProperty("QtQuick")));
}
TEST_F(ModuleScanner, SkipEmptyModules)
{
scanner.scan(QStringList{QT6_INSTALL_PREFIX});
ASSERT_THAT(scanner.modules(), Not(Contains(UrlProperty(IsEmpty()))));
}
TEST_F(ModuleScanner, UseSkipFunction)
{
scanner.scan(QStringList{QT6_INSTALL_PREFIX});
ASSERT_THAT(scanner.modules(), Not(Contains(UrlProperty(EndsWith(QStringView{u"impl"})))));
}
TEST_F(ModuleScanner, Version)
{
QmlDesigner::ModuleScanner scanner{[](QStringView moduleName) {
return moduleName.endsWith(u"impl");
},
QmlDesigner::VersionScanning::Yes};
scanner.scan(QStringList{TESTDATA_DIR "/modulescanner"});
ASSERT_THAT(scanner.modules(), ElementsAre(AllOf(UrlProperty("Example"), VersionProperty("1.3"))));
}
} // namespace