Merge pull request #34 from threeal/add-run-test-input

Add `run-test` Action Input
This commit is contained in:
Alfi Maulana 2023-01-22 13:53:50 +07:00 committed by GitHub
commit 5450d03d85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 14 deletions

View File

@ -32,9 +32,8 @@ jobs:
with:
source-dir: test
build-dir: output
- name: Run the build result
run: output/hello_world
run-test: true
test-args: -R hello_world
- name: Check if the default build directory does not exist
run: test ! -d build && test ! -d test/build
@ -53,14 +52,11 @@ jobs:
with:
source-dir: test
targets: test_c test_cpp
run-test: true
c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }}
cxx-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }}
args: -D CHECK_SURPASS_WARNING=ON
- name: Run the build results
run: |
${{ matrix.compiler == 'msvc' && 'test\build\Debug\test_c.exe' || 'test/build/test_c' }}
${{ matrix.compiler == 'msvc' && 'test\build\Debug\test_cpp.exe' || 'test/build/test_cpp' }}
test-args: -R test ${{ matrix.compiler == 'msvc' && '-C Debug' || '' }}
specified-compiler-usage:
runs-on: ${{ matrix.os }}-latest
@ -76,13 +72,12 @@ jobs:
with:
source-dir: test
targets: test_c test_cpp
run-test: true
generator: Ninja
c-compiler: clang
cxx-compiler: clang++
args: -D CHECK_USING_CLANG=ON
- name: Run the build results
run: test/build/test_c && test/build/test_cpp
test-args: -R test
specified-generator-usage:
runs-on: ${{ matrix.os }}-latest
@ -97,7 +92,6 @@ jobs:
uses: ./
with:
source-dir: test
run-test: true
generator: Ninja
- name: Run the build result
run: test/build/hello_world
test-args: -R hello_world

View File

@ -17,12 +17,14 @@ 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. |
| `c-flags` | Multiple strings | Additional flags passed when compiling C language files. |
| `cxx-flags` | Multiple strings | Additional flags passed when compiling C++ language files. |
| `args` | Multiple strings | Additional arguments passed during the CMake configuration. |
| `test-args` | Multiple strings | Additional arguments passed during the CTest run. |
> Note: Multiple strings mean that the input could be specified with more than one value. Separate each value with a space or a new line.

View File

@ -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
@ -32,6 +36,9 @@ inputs:
args:
description: Additional arguments passed during the CMake configuration
required: false
test-args:
description: Additional arguments passed during the CTest run
required: false
runs:
using: composite
steps:
@ -51,9 +58,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
@ -72,8 +83,12 @@ runs:
if [ -n '${{ inputs.args }}' ]; then
ARGS="$ARGS ${{ inputs.args }}"
fi
if [ -n '${{ inputs.test-args }}' ]; then
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
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 +107,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 }}

View File

@ -14,7 +14,9 @@ if(CHECK_SURPASS_WARNING)
endif()
endif()
enable_testing()
add_executable(hello_world hello_world.cpp)
add_test(NAME hello_world COMMAND $<TARGET_FILE:hello_world>)
list(APPEND LANGS c cpp)
foreach(LANG ${LANGS})
@ -26,4 +28,5 @@ foreach(LANG ${LANGS})
$<$<BOOL:${CHECK_USING_CLANG}>:CHECK_USING_CLANG>
$<$<BOOL:${CHECK_SURPASS_WARNING}>:CHECK_SURPASS_WARNING>
)
add_test(NAME test_${LANG} COMMAND $<TARGET_FILE:test_${LANG}>)
endforeach()