From 0107203a4643c278d6552f108fb9675afbe8f3ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Thu, 28 Sep 2023 10:11:47 +0200 Subject: [PATCH] feat(Storybook): Validator app to check if all pages can be compiled Closes: #12282 --- storybook/CMakeLists.txt | 13 +++++++++ storybook/main.cpp | 3 +-- storybook/validator_main.cpp | 51 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 storybook/validator_main.cpp diff --git a/storybook/CMakeLists.txt b/storybook/CMakeLists.txt index 78d1965e93..6423b2a721 100644 --- a/storybook/CMakeLists.txt +++ b/storybook/CMakeLists.txt @@ -80,6 +80,19 @@ target_link_libraries( add_dependencies(${PROJECT_NAME} StatusQ) +add_executable( + PagesValidator + validator_main.cpp +) + +target_link_libraries( + PagesValidator PUBLIC Qt5::Core Qt5::Gui Qt5::Quick Qt5::QuickControls2) + +target_compile_definitions(PagesValidator PRIVATE + QML_IMPORT_ROOT="${CMAKE_CURRENT_LIST_DIR}" + STATUSQ_MODULE_IMPORT_PATH="${STATUSQ_MODULE_IMPORT_PATH}" + ) + enable_testing() add_executable(SectionsDecoratorModelTest tests/tst_SectionsDecoratorModel.cpp) diff --git a/storybook/main.cpp b/storybook/main.cpp index ebb0c29faa..99491f59b6 100644 --- a/storybook/main.cpp +++ b/storybook/main.cpp @@ -36,8 +36,7 @@ int main(int argc, char *argv[]) QML_IMPORT_ROOT + QStringLiteral("/../ui/imports"), QML_IMPORT_ROOT + QStringLiteral("/src"), QML_IMPORT_ROOT + QStringLiteral("/pages"), - QML_IMPORT_ROOT + QStringLiteral("/stubs"), - QML_IMPORT_ROOT + QStringLiteral("/mocks"), + QML_IMPORT_ROOT + QStringLiteral("/stubs") }; for (const auto& path : additionalImportPaths) diff --git a/storybook/validator_main.cpp b/storybook/validator_main.cpp new file mode 100644 index 0000000000..53d76274f9 --- /dev/null +++ b/storybook/validator_main.cpp @@ -0,0 +1,51 @@ +#include +#include + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + QQmlApplicationEngine engine; + + const QStringList additionalImportPaths { + STATUSQ_MODULE_IMPORT_PATH, + QML_IMPORT_ROOT + QStringLiteral("/../ui/app"), + QML_IMPORT_ROOT + QStringLiteral("/../ui/imports"), + QML_IMPORT_ROOT + QStringLiteral("/src"), + QML_IMPORT_ROOT + QStringLiteral("/stubs") + }; + + for (const auto& path : additionalImportPaths) + engine.addImportPath(path); + + QString pagesPath = QML_IMPORT_ROOT + QStringLiteral("/pages"); + QDir pagesDir(pagesPath); + + const QFileInfoList files = pagesDir.entryInfoList( + { QStringLiteral("*Page.qml") }, QDir::Files, QDir::Name); + + engine.setBaseUrl(QUrl::fromLocalFile(pagesPath + QDir::separator())); + + bool errorsFound = false; + + for (auto& fileInfo : files) { + auto fileName = fileInfo.fileName(); + qDebug() << fileName; + + QQmlComponent component(&engine, fileName); + + if (component.isError()) { + qWarning() << component.errors(); + errorsFound = true; + } + } + + if (errorsFound) + return EXIT_FAILURE; + + qDebug() << "Verification completed successfully."; + return EXIT_SUCCESS; +}