From d59afd284435ef69dc9e2ed392e0a73e750ddff9 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 11:53:07 +0700 Subject: [PATCH] add a new `run-test` input option for running tests using CTest --- README.md | 1 + action.yml | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index e81da89..a6b4d81 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ For more information, see [action.yml](./action.yml) and [GitHub Actions guide]( | `source-dir` | Path | Source directory of the CMake project. Defaults to current directory. | | `build-dir` | Path | Build directory of the CMake project. Defaults to `build` directory in current directory. | | `targets` | Multiple strings | List of build targets. | +| `run-test` | `true` or `false` | If enabled, run testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | | `generator` | String | Build system generator of the CMake project. | | `c-compiler` | String | Preferred executable for compiling C language files. | | `cxx-compiler` | String | Preferred executable for compiling C++ language files. | diff --git a/action.yml b/action.yml index 1461fcd..8a5be0a 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,10 @@ inputs: targets: description: List of build targets required: false + run-test: + description: If enabled, run testing using CTest (true/false) + required: false + default: false generator: description: Build system generator of the CMake project required: false @@ -51,9 +55,13 @@ runs: fi ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'" BUILD_ARGS="--build '$BUILD_DIR'" + TEST_ARGS="" if [ -n '${{ inputs.targets }}' ]; then BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" fi + if [ '${{ inputs.run-test }}' == 'true' ]; then + TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error" + fi if [ -n '${{ inputs.generator }}' ]; then ARGS="$ARGS -G '${{ inputs.generator }}'" fi @@ -74,6 +82,7 @@ runs: fi echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT + echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT - name: Install Ninja if: ${{ inputs.generator == 'Ninja' }} @@ -92,3 +101,8 @@ runs: - name: Build targets shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }} + + - name: Run tests + if: steps.process_inputs.outputs.cmake_test_args != '' + shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} + run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }}