Skip to content

Commit ef0075f

Browse files
committed
Add the tests infrastructure with Criterion
1 parent 79bd68d commit ef0075f

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
44
# Specify project name
55
project (a-vim-story C)
66

7+
# Enable tests
8+
set (tests_enabled 1)
9+
710
# Set version numbers
811
set (PROJECT_VERSION_MAJOR 0)
912
set (PROJECT_VERSION_MINOR 1)
@@ -53,6 +56,38 @@ set (PROJECT_SOURCES
5356
# Add the maps
5457
add_subdirectory (maps)
5558

59+
# Add tests
60+
if (tests_enabled)
61+
62+
# Find the criterion library for tests
63+
find_library (CRITERION_LIB criterion)
64+
65+
set (TESTS
66+
test/key.c
67+
src/interface.c
68+
src/map.c
69+
src/action.c
70+
src/key.c
71+
src/msg.c
72+
src/game.c
73+
src/menu.c
74+
)
75+
76+
add_executable (run_test ${TESTS})
77+
target_link_libraries (run_test ${LIBRARIES} ${CRITERION_LIB})
78+
79+
add_custom_command (
80+
OUTPUT run_test
81+
COMMAND run_test
82+
)
83+
84+
add_custom_target (
85+
check run_test
86+
DEPENDS ${PROJECT_NAME}
87+
COMMENT "Running tests"
88+
)
89+
endif ()
90+
5691
# Add the executable
5792
add_executable (${PROJECT_NAME} ${PROJECT_SOURCES})
5893

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ Inspired by [Vim Adventures](https://vim-adventures.com/) and open sourced.
2121
### Compiling
2222
Assuming you have _libncurses_, _CMake_ and _Make_ installed.
2323

24+
Optionally, you'd require [_Criterion_](https://github.com/Snaipe/Criterion)
25+
for testing. If you don't want that, set `enable_testing` to `0` in
26+
`CMakeLists.txt` in the root directory.
27+
2428
mkdir build && cd build
2529

2630
cmake ..
2731

2832
make
2933
make install # to install (might want to use 'sudo')
34+
make check # to run tests
3035

3136
a-vim-story # to run
3237

test/key.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <criterion/criterion.h>
2+
#include "datatypes.h"
3+
#include "key.h"
4+
5+
Test(key, lock_all) {
6+
key_lock_all();
7+
8+
cr_expect(!key_unlocked('a'), "Key should be locked when locked");
9+
}

0 commit comments

Comments
 (0)