diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c25f91f..95805e66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,13 @@ option( BUILD_TEXTDOCUMENT "Build the Grantlee textdocument library" TRUE ) option( BUILD_MAIN_PLUGINS "Build the Grantlee Templates plugins" TRUE ) option( BUILD_I18N_PLUGIN "Build the Grantlee Templates i18n plugin" TRUE ) option( BUILD_TESTS "Build the Grantlee tests" TRUE ) +option( INSTALL_TESTS "Build and install the Grantlee tests" FALSE ) option( GRANTLEE_BUILD_WITH_QT6 "Build Grantlee with Qt 6" FALSE) +if (INSTALL_TESTS) + set(BUILD_TESTS TRUE) +endif() + if (BUILD_TESTS) include (CTest) enable_testing() diff --git a/templates/tests/CMakeLists.txt b/templates/tests/CMakeLists.txt index 717869f0..77bf5249 100644 --- a/templates/tests/CMakeLists.txt +++ b/templates/tests/CMakeLists.txt @@ -6,7 +6,11 @@ endif() set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) +if(INSTALL_TESTS) +set( GRANTLEE_PLUGIN_PATH ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR} ) +else() set( GRANTLEE_PLUGIN_PATH "${CMAKE_BINARY_DIR}/" ) +endif() configure_file(grantlee_paths.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/grantlee_paths.h) @@ -83,6 +87,9 @@ macro(grantlee_templates_unit_tests) ) add_test(${_testname} ${_testname}_exec ) target_link_libraries(${_testname}_exec Grantlee5::Templates template_test_builtins) + if (INSTALL_TESTS) + install(TARGETS ${_testname}_exec RUNTIME DESTINATION libexec/grantlee_tests) + endif() if (Qt6Qml_FOUND) target_compile_definitions(${_testname}_exec PRIVATE HAVE_QTQML_LIB) diff --git a/textdocument/tests/CMakeLists.txt b/textdocument/tests/CMakeLists.txt index fca2cee3..0857b601 100644 --- a/textdocument/tests/CMakeLists.txt +++ b/textdocument/tests/CMakeLists.txt @@ -17,12 +17,25 @@ else() endif() target_compile_features(textdocument_test_builtins PUBLIC cxx_auto_type) + +configure_file(testresource.qrc.cmake "${CMAKE_CURRENT_BINARY_DIR}/testresource.qrc") +set (_rcc_file "${CMAKE_CURRENT_BINARY_DIR}/testresource.qrc") + +if (GRANTLEE_BUILD_WITH_QT6) + qt6_add_resources(_testresource_rcc_src ${_rcc_file} OPTIONS -root "/" ) +else() + qt5_add_resources(_testresource_rcc_src ${_rcc_file} OPTIONS -root "/" ) +endif() + macro(GRANTLEE_TEXTDOCUMENT_UNIT_TESTS) foreach(_testname ${ARGN}) - add_executable(${_testname}_exec ${_testname}.cpp) + add_executable(${_testname}_exec ${_testname}.cpp ${_testresource_rcc_src}) add_test(${_testname} ${_testname}_exec ) target_link_libraries(${_testname}_exec Grantlee::TextDocument textdocument_test_builtins) set_property(GLOBAL APPEND PROPERTY TEST_COVERAGE "${CMAKE_CURRENT_BINARY_DIR}/${_testname}_exec" ) + if (INSTALL_TESTS) + install(TARGETS ${_testname}_exec RUNTIME DESTINATION libexec/grantlee_tests) + endif() endforeach(_testname) endmacro(GRANTLEE_TEXTDOCUMENT_UNIT_TESTS) diff --git a/textdocument/tests/plainmarkupbuildertest.cpp b/textdocument/tests/plainmarkupbuildertest.cpp index 9966d650..ca6532fd 100644 --- a/textdocument/tests/plainmarkupbuildertest.cpp +++ b/textdocument/tests/plainmarkupbuildertest.cpp @@ -40,7 +40,7 @@ class TestPlainMarkupOutput : public CoverageObject { Q_OBJECT private Q_SLOTS: - + void initTestCase(); // Test paragraph contents: void testSingleFormat(); void testDoubleFormat(); @@ -70,6 +70,13 @@ private Q_SLOTS: void testNestedList(); }; + + +void TestPlainMarkupOutput::initTestCase() +{ + Q_INIT_RESOURCE(testresource); +} + void TestPlainMarkupOutput::testSingleFormat() { QTextDocument doc; @@ -622,7 +629,7 @@ void TestPlainMarkupOutput::testLongDocument() { QTextDocument doc; - QFile sourceHtml(QFINDTESTDATA("sourcehtml")); + QFile sourceHtml(QStringLiteral(":/templates/sourcehtml")); QVERIFY(sourceHtml.open(QIODevice::ReadOnly)); doc.setHtml(QString::fromLatin1(sourceHtml.readAll().constData())); diff --git a/textdocument/tests/testresource.qrc.cmake b/textdocument/tests/testresource.qrc.cmake new file mode 100644 index 00000000..e1752278 --- /dev/null +++ b/textdocument/tests/testresource.qrc.cmake @@ -0,0 +1,6 @@ + + + @CMAKE_CURRENT_SOURCE_DIR@/sourcehtml + +@QM_FILES@ +