mirror of
https://github.com/threeal/cmake-action.git
synced 2025-04-20 02:31:20 +00:00
ci: implement external project for testing (#264)
* ci: use `threeal/cmake-starter` for testing the action * chore: remove unused sample project * ci: test if project built by running it instead * ci: add `test-action-with-additional-options` job
This commit is contained in:
parent
6f06d655fe
commit
6dac5ea68a
84
.github/workflows/test.yaml
vendored
84
.github/workflows/test.yaml
vendored
@ -58,91 +58,124 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [windows, ubuntu, macos]
|
os: [windows, ubuntu, macos]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout Project
|
||||||
|
uses: actions/checkout@v4.1.2
|
||||||
|
with:
|
||||||
|
repository: threeal/cpp-starter
|
||||||
|
|
||||||
|
- name: Checkout Action
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.2
|
||||||
with:
|
with:
|
||||||
path: cmake-action
|
path: cmake-action
|
||||||
sparse-checkout: |
|
sparse-checkout: |
|
||||||
action.yml
|
action.yml
|
||||||
dist
|
dist
|
||||||
test
|
|
||||||
sparse-checkout-cone-mode: false
|
sparse-checkout-cone-mode: false
|
||||||
|
|
||||||
- name: Move Project
|
|
||||||
run: mv cmake-action/test/* .
|
|
||||||
|
|
||||||
- name: Configure and Build Project
|
- name: Configure and Build Project
|
||||||
|
id: cmake-action
|
||||||
uses: ./cmake-action
|
uses: ./cmake-action
|
||||||
|
|
||||||
- name: Test Project
|
- name: Run Project
|
||||||
uses: threeal/ctest-action@v1.0.0
|
run: ${{ steps.cmake-action.outputs.build-dir }}/${{ matrix.os == 'windows' && 'Debug/generate_sequence.exe' || 'generate_sequence' }} 5
|
||||||
with:
|
|
||||||
build-config: Debug
|
|
||||||
tests-regex: hello_world
|
|
||||||
|
|
||||||
test-action-with-specified-dirs:
|
test-action-with-specified-dirs:
|
||||||
name: Test Action With Specified Directories
|
name: Test Action With Specified Directories
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout Project
|
||||||
|
uses: actions/checkout@v4.1.2
|
||||||
|
with:
|
||||||
|
repository: threeal/cpp-starter
|
||||||
|
path: project
|
||||||
|
|
||||||
|
- name: Checkout Action
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.2
|
||||||
with:
|
with:
|
||||||
path: cmake-action
|
path: cmake-action
|
||||||
sparse-checkout: |
|
sparse-checkout: |
|
||||||
action.yml
|
action.yml
|
||||||
dist
|
dist
|
||||||
test
|
|
||||||
sparse-checkout-cone-mode: false
|
sparse-checkout-cone-mode: false
|
||||||
|
|
||||||
- name: Configure and Build Project
|
- name: Configure and Build Project
|
||||||
id: cmake-action
|
id: cmake-action
|
||||||
uses: ./cmake-action
|
uses: ./cmake-action
|
||||||
with:
|
with:
|
||||||
source-dir: cmake-action/test
|
source-dir: project
|
||||||
build-dir: output
|
build-dir: output
|
||||||
|
|
||||||
- name: Test Project
|
- name: Run Project
|
||||||
uses: threeal/ctest-action@v1.0.0
|
run: output/generate_sequence 5
|
||||||
with:
|
|
||||||
test-dir: output
|
|
||||||
tests-regex: hello_world
|
|
||||||
|
|
||||||
test-action-without-run-build:
|
test-action-without-run-build:
|
||||||
name: Test Action Without Run Build
|
name: Test Action Without Run Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout Project
|
||||||
|
uses: actions/checkout@v4.1.2
|
||||||
|
with:
|
||||||
|
repository: threeal/cpp-starter
|
||||||
|
|
||||||
|
- name: Checkout Action
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.2
|
||||||
with:
|
with:
|
||||||
path: cmake-action
|
path: cmake-action
|
||||||
sparse-checkout: |
|
sparse-checkout: |
|
||||||
action.yml
|
action.yml
|
||||||
dist
|
dist
|
||||||
test
|
|
||||||
sparse-checkout-cone-mode: false
|
sparse-checkout-cone-mode: false
|
||||||
|
|
||||||
- name: Modify Project
|
- name: Modify Project
|
||||||
run: echo 'invalid' >> cmake-action/test/hello_world.cpp
|
run: echo 'invalid' >> src/main.cpp
|
||||||
|
|
||||||
- name: Configure Project
|
- name: Configure Project
|
||||||
id: cmake-action
|
|
||||||
uses: ./cmake-action
|
uses: ./cmake-action
|
||||||
with:
|
with:
|
||||||
source-dir: cmake-action/test
|
|
||||||
run-build: false
|
run-build: false
|
||||||
|
|
||||||
|
test-action-with-additional-options:
|
||||||
|
name: Test Action With Additional Options
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Project
|
||||||
|
uses: actions/checkout@v4.1.2
|
||||||
|
with:
|
||||||
|
repository: threeal/cpp-starter
|
||||||
|
|
||||||
|
- name: Checkout Action
|
||||||
|
uses: actions/checkout@v4.1.2
|
||||||
|
with:
|
||||||
|
path: cmake-action
|
||||||
|
sparse-checkout: |
|
||||||
|
action.yml
|
||||||
|
dist
|
||||||
|
sparse-checkout-cone-mode: false
|
||||||
|
|
||||||
|
- name: Configure and Build Project
|
||||||
|
uses: ./cmake-action
|
||||||
|
with:
|
||||||
|
options: BUILD_TESTING=ON
|
||||||
|
|
||||||
|
- name: Test Project
|
||||||
|
uses: threeal/ctest-action@v1.0.0
|
||||||
|
|
||||||
test-action-with-custom-generator:
|
test-action-with-custom-generator:
|
||||||
name: Test Action With Custom Generator
|
name: Test Action With Custom Generator
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout Project
|
||||||
|
uses: actions/checkout@v4.1.2
|
||||||
|
with:
|
||||||
|
repository: threeal/cpp-starter
|
||||||
|
|
||||||
|
- name: Checkout Action
|
||||||
uses: actions/checkout@v4.1.2
|
uses: actions/checkout@v4.1.2
|
||||||
with:
|
with:
|
||||||
path: cmake-action
|
path: cmake-action
|
||||||
sparse-checkout: |
|
sparse-checkout: |
|
||||||
action.yml
|
action.yml
|
||||||
dist
|
dist
|
||||||
test
|
|
||||||
sparse-checkout-cone-mode: false
|
sparse-checkout-cone-mode: false
|
||||||
|
|
||||||
- name: Setup Ninja
|
- name: Setup Ninja
|
||||||
@ -152,7 +185,6 @@ jobs:
|
|||||||
id: cmake-action
|
id: cmake-action
|
||||||
uses: ./cmake-action
|
uses: ./cmake-action
|
||||||
with:
|
with:
|
||||||
source-dir: cmake-action/test
|
|
||||||
generator: Ninja
|
generator: Ninja
|
||||||
run-build: false
|
run-build: false
|
||||||
|
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,5 @@
|
|||||||
!.eslint*
|
!.eslint*
|
||||||
!.git*
|
!.git*
|
||||||
|
|
||||||
build/
|
|
||||||
coverage/
|
coverage/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
|
||||||
project(test)
|
|
||||||
|
|
||||||
option(CHECK_USING_CLANG "Check if the target is compiled using Clang" OFF)
|
|
||||||
option(CHECK_SURPASS_WARNING "Check if the target could surpass a compiler warning" OFF)
|
|
||||||
|
|
||||||
if(CHECK_SURPASS_WARNING)
|
|
||||||
if(MSVC)
|
|
||||||
set(CMAKE_C_FLAGS "/WX /W4 ${CMAKE_C_FLAGS}")
|
|
||||||
set(CMAKE_CXX_FLAGS "/WX /W4 ${CMAKE_CXX_FLAGS}")
|
|
||||||
else()
|
|
||||||
set(CMAKE_C_FLAGS "-Werror -Wunused-variable ${CMAKE_C_FLAGS}")
|
|
||||||
set(CMAKE_CXX_FLAGS "-Werror -Wunused-variable ${CMAKE_CXX_FLAGS}")
|
|
||||||
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})
|
|
||||||
configure_file(test.in ${CMAKE_CURRENT_BINARY_DIR}/test.${LANG})
|
|
||||||
add_executable(test_${LANG} EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/test.${LANG})
|
|
||||||
target_compile_definitions(
|
|
||||||
test_${LANG} PRIVATE
|
|
||||||
$<$<STREQUAL:"${LANG}","c">:IS_C>
|
|
||||||
$<$<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()
|
|
@ -1,6 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::cout << "Hello world!" << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
19
test/test.in
19
test/test.in
@ -1,19 +0,0 @@
|
|||||||
#ifdef IS_C
|
|
||||||
#include <stdio.h>
|
|
||||||
#define PRINT(STR) printf(STR); printf("\n")
|
|
||||||
#else
|
|
||||||
#include <iostream>
|
|
||||||
#define PRINT(STR) std::cout << STR << std::endl
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
#ifdef CHECK_SURPASS_WARNING
|
|
||||||
int unused;
|
|
||||||
#endif
|
|
||||||
#if defined(CHECK_USING_CLANG) && !defined(__clang__)
|
|
||||||
PRINT("compiler is not clang");
|
|
||||||
return 1;
|
|
||||||
#endif
|
|
||||||
PRINT("all ok");
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user