Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/ctest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Cross-Platform Build & Test

on:
push:
branches: [ "main" ]
pull_request:

permissions:
contents: read
checks: write
pull-requests: write

jobs:
build-and-test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
include:
- name: Linux GCC
os: ubuntu-latest
cc: gcc

- name: Linux Clang
os: ubuntu-latest
cc: clang

- name: Windows MSVC
os: windows-latest

steps:
- uses: actions/checkout@v6

- name: Configure CMake (Unix)
if: runner.os != 'Windows'
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON
env:
CC: ${{ matrix.cc }}

- name: Configure CMake (Windows)
if: runner.os == 'Windows'
run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=ON -G "Visual Studio 17 2022"

- name: Build
run: cmake --build build --config Release

- name: Run Tests
working-directory: build
run: ctest -C Release --output-on-failure --output-junit test-results.xml

- name: Publish Test Results
uses: dorny/test-reporter@v2
if: success() || failure()
with:
name: Tests (${{ matrix.name }})
path: build/test-results.xml
reporter: java-junit
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ if(PROJECT_IS_TOP_LEVEL)

# --- Build Examples ---
if(BUILD_EXAMPLES)
enable_testing()

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/CMakeLists.txt")
add_subdirectory(examples)
endif()
Expand Down
10 changes: 10 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ file(GLOB EXAMPLE_SOURCES CONFIGURE_DEPENDS "example*.c")
foreach(SOURCE_FILE ${EXAMPLE_SOURCES})

get_filename_component(TARGET_NAME ${SOURCE_FILE} NAME_WE)

add_executable(${TARGET_NAME} ${SOURCE_FILE})
target_link_libraries(${TARGET_NAME} PRIVATE c_traceback::c_traceback)

if(ENABLE_SANITIZERS AND NOT MSVC)
target_compile_options(${TARGET_NAME} PRIVATE -fsanitize=address,undefined)
target_link_options(${TARGET_NAME} PRIVATE -fsanitize=address,undefined)
endif()

# Test
add_test(
NAME ${TARGET_NAME}
COMMAND ${CMAKE_COMMAND}
-DTEST_PROG=$<TARGET_FILE:${TARGET_NAME}>
-P ${CMAKE_CURRENT_SOURCE_DIR}/check_test.cmake
)

endforeach()
20 changes: 20 additions & 0 deletions examples/check_test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
execute_process(
COMMAND ${TEST_PROG}
OUTPUT_VARIABLE TEST_OUTPUT
ERROR_VARIABLE TEST_OUTPUT
RESULT_VARIABLE TEST_RESULT
)

message("${TEST_OUTPUT}")

# Determine Success
# The output contains "Traceback" (Even if it crashed)
if(TEST_OUTPUT MATCHES "Traceback")
message(STATUS "Traceback detected. Test Passed.")
# The program ran successfully (Exit code 0)
elseif(TEST_RESULT EQUAL 0)
message(STATUS "Clean exit. Test Passed.")
else()
# Fail: It crashed AND didn't print a Traceback
message(FATAL_ERROR "Test Failed: Process crashed (Code: ${TEST_RESULT}) and no 'Traceback' found.")
endif()
16 changes: 0 additions & 16 deletions examples/example_keyboard_interrupt.c

This file was deleted.

22 changes: 0 additions & 22 deletions examples/example_stack_overflow.c

This file was deleted.