From c43315c77e383ec262c4e5f834321ac6fd21dec0 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 21 Mar 2024 20:17:22 -0400 Subject: [PATCH] add self test --- .github/workflows/ci.yml | 5 ++++- cmake/test_run.cmake | 8 ++++++++ demos/CMakeLists.txt | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 cmake/test_run.cmake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36d28258..a95677ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,6 +67,9 @@ jobs: - name: CMake build examples run: cmake --build demos/build + - name: Run tests + run: ctest --test-dir demos/build + - name: Create package if: github.event.action == 'published' run: cpack --config build/CPackConfig.cmake @@ -122,7 +125,7 @@ jobs: with: version: "2.0" - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Configure run: cmake -Bbuild --toolchain cmake/dos.cmake diff --git a/cmake/test_run.cmake b/cmake/test_run.cmake new file mode 100644 index 00000000..151276c5 --- /dev/null +++ b/cmake/test_run.cmake @@ -0,0 +1,8 @@ +if(NOT EXISTS "${in}") + message(FATAL_ERROR "Input file ${in} does not exist") +endif() + +execute_process(COMMAND "${exe}" +#INPUT_FILE "${in}" +COMMAND_ERROR_IS_FATAL ANY +) diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index 667aeeae..96da39b2 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -7,6 +7,8 @@ endif() project(PDcursesDemos LANGUAGES C) +enable_testing() + find_package(PDCurses CONFIG REQUIRED) foreach(f IN ITEMS testcurs ozdemo xmas firework ptest rain worm) @@ -17,5 +19,19 @@ endforeach() add_executable(tuidemo tui.c tuidemo.c) target_link_libraries(tuidemo PRIVATE CURSES::CURSES) -# --- auto-ignore build directory file(GENERATE OUTPUT .gitignore CONTENT "*") + +set(CI $ENV{CI}) + +file(GENERATE OUTPUT q.txt CONTENT "q") + +foreach(t IN ITEMS rain ptest) + +add_test(NAME ${t} +COMMAND ${CMAKE_COMMAND} -Dexe=$ -Din=${CMAKE_CURRENT_BINARY_DIR}/q.txt +-P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/test_run.cmake) + +set_property(TEST ${t} PROPERTY DISABLED $,${CI}>) +set_property(TEST ${t} PROPERTY TIMEOUT 7) + +endforeach()