diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index d4be00a..8236370 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,20 +1,18 @@ name: CMake on: + workflow_run: + workflows: [tests] + types: [completed] + workflow_dispatch: push: paths: - - 'src/**' - - 'CMakeModules/**' - - CMakeLists.txt - 'protocols/**' - branches: [ "main" ] + branches: [main] pull_request: paths: - - 'src/**' - - 'CMakeModules/**' - - CMakeLists.txt - 'protocols/**' - branches: [ "main" ] + branches: [main] env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..81f166d --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,52 @@ +name: Unit tests + +on: + push: + paths: + - 'src/**' + - 'CMakeModules/**' + - CMakeLists.txt + branches: [main] + workflow_dispatch: + pull_request: + paths: + - 'src/**' + - 'CMakeModules/**' + - CMakeLists.txt + branches: [main] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + testing: + strategy: + matrix: + os: [ubuntu-24.04] + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + with: + submodules: true + + - name: Install dependencies + if: matrix.os == 'ubuntu-24.04' + run: sudo apt-get update && sudo apt-get -y install libgl-dev libglew-dev freeglut3-dev libsdl2-dev liblz4-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libglm-dev libglfw3-dev libmpv-dev mpv libmpv2 libfftw3-dev + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTING=On + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + + - name: Run tests + # Run the unit tests available + run: ${{github.workspace}}/build/output/tests diff --git a/.gitmodules b/.gitmodules index 54a51c2..f469535 100644 --- a/.gitmodules +++ b/.gitmodules @@ -26,3 +26,7 @@ path = src/External/argparse url = https://github.com/p-ranav/argparse.git branch = master +[submodule "src/External/Catch2"] + path = src/External/Catch2 + url = https://github.com/catchorg/Catch2.git + branch = devel \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d999b35..ded0f29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,9 @@ add_subdirectory(src/External/glslang-WallpaperEngine glslang) add_subdirectory(src/External/SPIRV-Cross-WallpaperEngine spirv-cross) add_subdirectory(src/External/kissfft kissfft) add_subdirectory(src/External/argparse argparse) - +if(BUILD_TESTING) + add_subdirectory(src/External/Catch2) +endif() # try to enable wayland builds when possible pkg_check_modules(WAYLAND_SUPPORT wayland-cursor wayland-protocols egl wayland-egl) @@ -247,6 +249,13 @@ include_directories( ${CMAKE_SOURCE_DIR} ${X11_INCLUDES}) +if(BUILD_TESTING) + add_executable( + tests + src/WallpaperEngine/Testing/Cases/Example.cpp + ) +endif() + add_executable( linux-wallpaperengine src/main.cpp @@ -535,6 +544,30 @@ target_link_libraries (linux-wallpaperengine PUBLIC libcef_dll_wrapper argparse) +if (BUILD_TESTING) + target_link_libraries (tests PRIVATE + Catch2::Catch2WithMain PUBLIC + ${OPENGL_LIBRARIES} + ${GLEW_LIBRARIES} + ${GLUT_LIBRARIES} + ${ZLIB_LIBRARIES} + ${LZ4_LIBRARY} + ${SDL2_LIBRARIES} + ${FFMPEG_LIBRARIES} + ${MPV_LIBRARY} + ${PULSEAUDIO_LIBRARY} + ${WAYLAND_LIBRARIES} + ${X11_LIBRARIES} + kissfft + glslang + spirv-cross-core + spirv-cross-glsl + glfw + libcef_lib + libcef_dll_wrapper + argparse) +endif() + COPY_FILES(linux-wallpaperengine "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" "${TARGET_OUTPUT_DIRECTORY}") COPY_FILES(linux-wallpaperengine "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${TARGET_OUTPUT_DIRECTORY}") # remove the vulkan lib as chromium includes a broken libvulkan.so.1 with it diff --git a/src/External/Catch2 b/src/External/Catch2 new file mode 160000 index 0000000..74fcff6 --- /dev/null +++ b/src/External/Catch2 @@ -0,0 +1 @@ +Subproject commit 74fcff6e5b190fb833a231b7f7c1829e3c3ac54d diff --git a/src/WallpaperEngine/Testing/Cases/Example.cpp b/src/WallpaperEngine/Testing/Cases/Example.cpp new file mode 100644 index 0000000..9687cf9 --- /dev/null +++ b/src/WallpaperEngine/Testing/Cases/Example.cpp @@ -0,0 +1,5 @@ +#include + +TEST_CASE ("Example test") { + REQUIRE (true); +} \ No newline at end of file