feat(Storybook): Test library for common testing utils

StatusQ's test/CMakeLists.txt refactored:
- created library target for common test utils
- removed outdated cmake commands like add_definitions
- qml tests renamed from TestStatusQ to QmlTests
- qml test files made visible in QtCreator
- linking simplified
- unneeded cmake files removed from src dir

Closes: #13031
This commit is contained in:
Michał Cieślak 2023-12-18 22:28:04 +01:00 committed by Michał
parent e8b1df696c
commit 6ab6e4a26e
3 changed files with 32 additions and 42 deletions

View File

@ -2,44 +2,47 @@ cmake_minimum_required(VERSION 3.5)
project(TestStatusQ LANGUAGES CXX) project(TestStatusQ LANGUAGES CXX)
enable_testing()
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS QuickTest Qml Quick WebChannel WebEngine REQUIRED) find_package(Qt5 COMPONENTS QuickTest Qml Quick WebEngine REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS QuickTest Qml Quick WebChannel WebEngine REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON) ##############
# Test Library
##############
# no need to copy around qml test files for shadow builds - just set the respective define add_library(StatusQTestLib
add_definitions(-DQUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") src/TestHelpers/MonitorQtOutput.cpp
src/TestHelpers/MonitorQtOutput.h
add_executable(${PROJECT_NAME} main.cpp)
add_test(NAME ${PROJECT_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${PROJECT_NAME} -input "${CMAKE_CURRENT_SOURCE_DIR}")
# TODO: move this to a test helpers library
target_include_directories(${PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
) )
add_subdirectory(src) target_link_libraries(StatusQTestLib PUBLIC Qt5::Core Qt5::Quick)
target_include_directories(StatusQTestLib PUBLIC src)
target_link_libraries(${PROJECT_NAME} PRIVATE enable_testing()
Qt${QT_VERSION_MAJOR}::QuickTest
Qt${QT_VERSION_MAJOR}::Qml
Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::WebChannel
Qt${QT_VERSION_MAJOR}::WebEngine
StatusQ
)
target_compile_definitions(${PROJECT_NAME} PRIVATE ###########
# QML Tests
###########
file(GLOB_RECURSE TEST_QML_FILES "*.qml")
add_executable(QmlTests main.cpp "${TEST_QML_FILES}")
target_compile_definitions(QmlTests PRIVATE
STATUSQ_MODULE_PATH="${STATUSQ_MODULE_PATH}" STATUSQ_MODULE_PATH="${STATUSQ_MODULE_PATH}"
STATUSQ_MODULE_IMPORT_PATH="${STATUSQ_MODULE_IMPORT_PATH}" STATUSQ_MODULE_IMPORT_PATH="${STATUSQ_MODULE_IMPORT_PATH}"
) # no need to copy around qml test files for shadow builds - just set the respective define
QUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
)
target_link_libraries(QmlTests PRIVATE Qt5::QuickTest Qt5::Qml Qt5::Quick
Qt5::WebEngine StatusQ StatusQTestLib
)
add_test(NAME QmlTests WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND QmlTests -input "${CMAKE_CURRENT_SOURCE_DIR}"
)
###########
# C++ Tests
###########
add_executable(RolesRenamingModelTest tst_RolesRenamingModel.cpp) add_executable(RolesRenamingModelTest tst_RolesRenamingModel.cpp)
target_link_libraries(RolesRenamingModelTest PRIVATE Qt5::Qml Qt5::Test StatusQ) target_link_libraries(RolesRenamingModelTest PRIVATE Qt5::Qml Qt5::Test StatusQ)

View File

@ -1,6 +0,0 @@
target_include_directories(${PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
add_subdirectory(TestHelpers)

View File

@ -1,7 +0,0 @@
target_sources(${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/MonitorQtOutput.h
${CMAKE_CURRENT_SOURCE_DIR}/MonitorQtOutput.cpp
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
)