File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
44# Specify project name
55project (a-vim-story C)
66
7+ # Enable tests
8+ set (tests_enabled 1)
9+
710# Set version numbers
811set (PROJECT_VERSION_MAJOR 0)
912set (PROJECT_VERSION_MINOR 1)
@@ -53,6 +56,38 @@ set (PROJECT_SOURCES
5356# Add the maps
5457add_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
5792add_executable (${PROJECT_NAME} ${PROJECT_SOURCES} )
5893
Original file line number Diff line number Diff line change @@ -21,12 +21,17 @@ Inspired by [Vim Adventures](https://vim-adventures.com/) and open sourced.
2121### Compiling
2222Assuming 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments