Skip to content

Commit

Permalink
Add the tests infrastructure with Criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
coditva committed Nov 23, 2017
1 parent e14dd4f commit aaf7b78
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
# Specify project name
project (a-vim-story C)

# Enable tests
set (tests_enabled 1)

# Set version numbers
set (PROJECT_VERSION_MAJOR 0)
set (PROJECT_VERSION_MINOR 1)
Expand Down Expand Up @@ -53,6 +56,38 @@ set (PROJECT_SOURCES
# Add the maps
add_subdirectory (maps)

# Add tests
if (tests_enabled)

# Find the criterion library for tests
find_library (CRITERION_LIB criterion)

set (TESTS
test/key.c
src/interface.c
src/map.c
src/action.c
src/key.c
src/msg.c
src/game.c
src/menu.c
)

add_executable (run_test ${TESTS})
target_link_libraries (run_test ${LIBRARIES} ${CRITERION_LIB})

add_custom_command (
OUTPUT run_test
COMMAND run_test
)

add_custom_target (
check run_test
DEPENDS ${PROJECT_NAME}
COMMENT "Running tests"
)
endif ()

# Add the executable
add_executable (${PROJECT_NAME} ${PROJECT_SOURCES})

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ Inspired by [Vim Adventures](https://vim-adventures.com/) and open sourced.
### Compiling
Assuming you have _libncurses_, _CMake_ and _Make_ installed.

Optionally, you'd require [_Criterion_](https://github.com/Snaipe/Criterion)
for testing. If you don't want that, set `enable_testing` to `0` in
`CMakeLists.txt` in the root directory.

mkdir build && cd build

cmake ..

make
make install # to install (might want to use 'sudo')
make check # to run tests

a-vim-story # to run

Expand Down
9 changes: 9 additions & 0 deletions test/key.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <criterion/criterion.h>
#include "datatypes.h"
#include "key.h"

Test(key, lock_all) {
key_lock_all();

cr_expect(!key_unlocked('a'), "Key should be locked when locked");
}

0 comments on commit aaf7b78

Please sign in to comment.