Skip to content

Commit

Permalink
add self test
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Mar 22, 2024
1 parent 70e5852 commit 266f5ae
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 8 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ on:
types: [published]

env:
CTEST_NO_TESTS_ACTION: "error"
CTEST_PARALLEL_LEVEL: 0
CMAKE_BUILD_PARALLEL_LEVEL: 4
CTEST_NO_TESTS_ACTION: error
CTEST_PARALLEL_LEVEL: 0

jobs:

Expand Down Expand Up @@ -62,10 +62,13 @@ jobs:
run: cmake --install build

- name: CMake configure examples
run: cmake -B demos/build -S demos -DCMAKE_PREFIX_PATH:PATH=${{ runner.temp }}
run: cmake -B builddemos -S demos -DCMAKE_PREFIX_PATH:PATH=${{ runner.temp }}

- name: CMake build examples
run: cmake --build demos/build
run: cmake --build builddemos

- name: CTest
run: ctest --test-dir builddemos --output-on-failure

- name: Create package
if: github.event.action == 'published'
Expand Down Expand Up @@ -122,10 +125,19 @@ jobs:
with:
version: "2.0"

- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Configure
run: cmake -Bbuild --toolchain cmake/dos.cmake
run: cmake -Bbuild --toolchain cmake/dos.cmake --install-prefix=${{ runner.temp }}

- name: Build
run: cmake --build build

- name: CMake install (for examples)
run: cmake --install build

- name: CMake configure examples
run: cmake -B builddemos -S demos -DCMAKE_PREFIX_PATH=${{ runner.temp }} --toolchain ../cmake/dos.cmake

- name: CMake build examples
run: cmake --build builddemos
12 changes: 10 additions & 2 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ endif()

project(PDcursesDemos LANGUAGES C)

enable_testing()

find_package(PDCurses CONFIG REQUIRED)

foreach(f IN ITEMS testcurs ozdemo xmas firework ptest rain worm)
foreach(f IN ITEMS testcurs ozdemo xmas firework ptest rain worm test_init)
add_executable(${f} ${f}.c)
target_link_libraries(${f} PRIVATE CURSES::CURSES)
endforeach()

add_executable(tuidemo tui.c tuidemo.c)
target_link_libraries(tuidemo PRIVATE CURSES::CURSES)

# --- auto-ignore build directory
file(GENERATE OUTPUT .gitignore CONTENT "*")

add_test(NAME Init COMMAND test_init)
set_tests_properties(Init PROPERTIES
SKIP_REGULAR_EXPRESSION "Can't open display|no DISPLAY variable set"
)

# Note: using STDIN INPUT_FILE for CTest doesn't work as Curses wants an actual keypress, not pipe.
36 changes: 36 additions & 0 deletions demos/test_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// test the very basics are working
// no refresh() or getch() as this requires a terminal and wouldn't work on CI
// without additional measures.

#include <stdio.h>
#include <stdlib.h>

#include <curses.h>

int main(void){
WINDOW* w = initscr();
if(w == NULL){
fprintf(stderr, "Error initialising ncurses.\n");
return 77;
}

int i = noecho();
if(i == ERR){
fprintf(stderr, "Error turning off echo.\n");
return 77;
}

i = printw("Hello, PDCurses!");
if(i == ERR){
fprintf(stderr, "Error printing to screen.\n");
return 77;
}

i = endwin();
if(i == ERR){
fprintf(stderr, "Error ending ncurses.\n");
return 77;
}

return EXIT_SUCCESS;
}

0 comments on commit 266f5ae

Please sign in to comment.