From aaf7b787d612dc1088ebdf0392d6b3f8e7d545a3 Mon Sep 17 00:00:00 2001 From: UTkarsh Maheshwari Date: Tue, 21 Nov 2017 05:25:48 +0530 Subject: [PATCH] Add the tests infrastructure with Criterion --- CMakeLists.txt | 35 +++++++++++++++++++++++++++++++++++ README.md | 5 +++++ test/key.c | 9 +++++++++ 3 files changed, 49 insertions(+) create mode 100644 test/key.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d23055..601e781 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}) diff --git a/README.md b/README.md index e5147ca..5c0c3bd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/test/key.c b/test/key.c new file mode 100644 index 0000000..178abf0 --- /dev/null +++ b/test/key.c @@ -0,0 +1,9 @@ +#include +#include "datatypes.h" +#include "key.h" + +Test(key, lock_all) { + key_lock_all(); + + cr_expect(!key_unlocked('a'), "Key should be locked when locked"); +}