diff --git a/CMakeLists.txt b/CMakeLists.txt index 2637d4af49..8c34b7905c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,10 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) endif() add_subdirectory(doc) + + if (JKQtPlotter_BUILD_TESTS) + add_subdirectory(tests) + endif() endif() diff --git a/appveyor.yml b/appveyor.yml index 9c4764eff4..02c0a550c4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -163,6 +163,15 @@ for: - cmd: if %USE_CMAKE%==true cmake --build . --config "%CONFIGURATION%" -j%NUMBER_OF_PROCESSORS% -- %CMAKE_BUILDFLAGS% - cmd: cd .. + test_script: + - cmd: if %USE_CMAKE%==true echo == RUNNING UNIT TESTS FOR JKQtPlotter CMAKE BUILD =============================================== + - cmd: cd %APPVEYOR_BUILD_FOLDER% + - cmd: cd build + - cmd: if %USE_CMAKE%==true ctest -C --config "%CONFIGURATION%" --output-on-failure --output-junit test-results.xml + + after_test: + - find "$APPVEYOR_BUILD_FOLDER" -type f -name 'test-results.xml' -print0 | xargs -0 -I '{}' curl -F 'file=@{}' "https://ci.appveyor.com/api/testresults/junit/$APPVEYOR_JOB_ID" + # Linux (Ubuntu2004) - @@ -265,12 +274,23 @@ for: cd examples/cmake_link_example mkdir build cd build - cmake -G "%CMAKE_GENERATOR%" "-DCMAKE_PREFIX_PATH=%QTDIR%;%CIMG_INCLUDE_DIR%;$APPVEYOR_BUILD_FOLDER\install" .. - cmake --build . --config "%CONFIGURATION%" -j%NUMBER_OF_PROCESSORS% -- %CMAKE_BUILDFLAGS% + cmake -G "$CONFIGURATION" "-DCMAKE_PREFIX_PATH=$QTDIR;$CIMG_INCLUDE_DIR;$APPVEYOR_BUILD_FOLDER\install" .. + cmake --build . --config "$CONFIGURATION" -j$(getconf _NPROCESSORS_ONLN) -- $CMAKE_BUILDFLAGS cd .. fi + test_script: + - sh: | + if [ "$USE_CMAKE" = true ] && [ "$TEST_FETCHCONTENT" = false ]; then + echo == RUNNING UNIT TESTS FOR JKQtPlotter CMAKE BUILD =============================================== + cd $APPVEYOR_BUILD_FOLDER + cd build + ctest -C --config "$CONFIGURATION" --output-on-failure --output-junit test-results.xml + fi + after_test: + - find "$APPVEYOR_BUILD_FOLDER" -type f -name 'test-results.xml' -print0 | xargs -0 -I '{}' curl -F 'file=@{}' "https://ci.appveyor.com/api/testresults/junit/$APPVEYOR_JOB_ID" + # MacOS (Monterey) - @@ -306,3 +326,10 @@ for: - sh: cmake -G "$CMAKE_GENERATOR" "-DCMAKE_PREFIX_PATH=$QTDIR" .. - sh: echo --- Build using CMake ------------------------------------------------------------------------------- - sh: cmake --build . --config "$CONFIGURATION" -j$(getconf _NPROCESSORS_ONLN) -- $CMAKE_BUILDFLAGS + + +artifacts: + - path: 'build/CMakeFiles/*.log' + name: logs + - path: 'build/Testing/**/*.xml' + name: test_results \ No newline at end of file diff --git a/cmake/jkqtplotter_cmake_options.cmake b/cmake/jkqtplotter_cmake_options.cmake index 5306feb6f8..c3567e0d3d 100644 --- a/cmake/jkqtplotter_cmake_options.cmake +++ b/cmake/jkqtplotter_cmake_options.cmake @@ -28,6 +28,9 @@ endif() if(NOT DEFINED JKQtPlotter_BUILD_TOOLS) option(JKQtPlotter_BUILD_TOOLS "Build the tools" ON) endif() +if(NOT DEFINED JKQtPlotter_BUILD_TESTS) + option(JKQtPlotter_BUILD_TESTS "Build the unit tests" ON) +endif() if(NOT DEFINED JKQtPlotter_BUILD_FORCE_NO_PRINTER_SUPPORT) option(JKQtPlotter_BUILD_FORCE_NO_PRINTER_SUPPORT "Build the library with printer support switched off, even if it is available" OFF) endif() diff --git a/doc/dox/buildinstructions_cmake.dox b/doc/dox/buildinstructions_cmake.dox index ef78e51e34..78cfef3747 100644 --- a/doc/dox/buildinstructions_cmake.dox +++ b/doc/dox/buildinstructions_cmake.dox @@ -62,6 +62,7 @@ The CMake build system offers several configuration variables that you may set/c - \c JKQtPlotter_BUILD_WITH_TIMING_INFO_OUTPUT : If enabled (\c ON ), additional tiing code is activated (and built into the library), which outputs timming information for several functions of the library into \c qDebug() . This is intended for development putposes only, NOT for productive builds! (default: \c OFF ) - \c JKQtPlotter_BUILD_EXAMPLES : Build examples (default: \c ON ) - \c JKQtPlotter_BUILD_TOOLS : Build tools (default: \c ON ) + - \c JKQtPlotter_BUILD_TESTS : Build unit-tests (default: \c ON ) - \c JKQtPlotter_BUILD_LIB_JKQTMATH : Build sub-library JKQTMath (default: \c ON ) - \c JKQtPlotter_BUILD_LIB_JKQTMATHTEXT : Build sub-library JKQTMathText (default: \c ON ) - DEPRECATED: \c JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER : Build sub-library JKQTFastPlotter (default: \c ON ) ... Note: This option may change to default=OFF in future ... and may be removed thereafter! diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000000..ef340f7928 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.23) + +message( STATUS ) +message( STATUS "............................................................................." ) +message( STATUS ".. BUILDING UNIT TESTS" ) +message( STATUS "............................................................................." ) +if (JKQtPlotter_BUILD_WITH_PRECOMPILED_HEADERS) + message( STATUS ".. - Precompiled Header: ON" ) +else() + message( STATUS ".. - Precompiled Header: OFF") +endif() +message( STATUS "............................................................................." ) + +enable_testing() +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED) + +message( STATUS ".. BUILDING UNIT TESTS FOR JKQTCommon:" ) +add_subdirectory(jkqtcommmon) +