SDL_image: workflows: Run the automated test for Linux+CMake builds

From 7eb9ae30dc46639c278a95b318a83a8d326b9d4f Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Mon, 23 May 2022 18:47:25 +0100
Subject: [PATCH] workflows: Run the automated test for Linux+CMake builds

This exercises the "everything is vendored" use-case.

We can't use dlopen() for the dependencies, because they won't be in
the search path at runtime (#259), so link them statically here.

We also can't build the test on Windows (because MSYS' SDL packaging
doesn't ship libSDL2_test) or on macOS with CMake (because libSDL2_test
isn't found, #260), so skip those for now. They can be added later if
it becomes possible.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 .github/workflows/main.yml | 56 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 87c6bb81..9fdc39cf 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -91,17 +91,61 @@ jobs:
     - name: Configure CMake
       if: "matrix.platform.cmake"
       run: |
-        cmake -B build \
+        set -- \
           -DBUILD_SHARED_LIBS=ON \
           -DCMAKE_BUILD_TYPE=Release \
           -DSDL2IMAGE_SAMPLES=ON \
+          -DSDL2IMAGE_TESTS_INSTALL=ON \
           -DSDL2IMAGE_JXL=ON \
           -DSDL2IMAGE_TIF=ON \
           -DSDL2IMAGE_WEBP=ON \
+          ${NULL+}
+
+        if [ "${{ runner.os }}" = Linux ]; then
+            # mingw-w64-*-SDL2 doesn't have SDL_test, and the macOS CMake
+            # build can't find it (see #260), so we only enable build-time
+            # tests for Linux at the moment.
+            set -- "$@" -DSDL2IMAGE_TESTS=ON
+            # If we dlopen() vendored soft dependencies, the test won't
+            # find them: https://github.com/libsdl-org/SDL_image/issues/259
+            set -- "$@" -DSDL2IMAGE_DEPS_SHARED=OFF
+        fi
+
+        cmake -B build \
+          "$@" \
           ${{ matrix.platform.cmake }}
     - name: Build
       if: "matrix.platform.cmake"
       run: cmake --build build/ --config Release --verbose
+    - name: Run build-time tests
+      if: "runner.os == 'Linux' && matrix.platform.cmake"
+      run: |
+        set -eu
+
+        # Expect to support all formats except AVIF in these builds
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_AVIF=0
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_BMP=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_CUR=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_GIF=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_ICO=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_JPG=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_JXL=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_LBM=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_PCX=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_PNG=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_PNM=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_QOI=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_SVG=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_TGA=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_TIF=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_WEBP=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_XPM=1
+        export SDL_IMAGE_TEST_REQUIRE_LOAD_XV=1
+
+        export SDL_IMAGE_TEST_REQUIRE_SAVE_JPG=1
+        export SDL_IMAGE_TEST_REQUIRE_SAVE_PNG=1
+
+        ctest -VV --test-dir build/test
     - name: Install
       if: "matrix.platform.shell == 'sh' && matrix.platform.cmake"
       run: |
@@ -109,6 +153,16 @@ jobs:
         rm -fr DESTDIR-cmake
         DESTDIR=$(pwd)/DESTDIR-cmake cmake --install build/ --config Release
         find DESTDIR-cmake | LC_ALL=C sort -u
+    - name: Upload artifacts
+      if: "failure() && runner.os == 'Linux' && matrix.platform.cmake"
+      uses: actions/upload-artifact@v3
+      with:
+        name: "${{ matrix.platform.name }} artifacts"
+        path: |
+          build/test/*.bmp
+          build/test/*.jpg
+          build/test/*.png
+        if-no-files-found: ignore
 
     - name: Configure Autotools
       if: "! matrix.platform.cmake"