A silly little C++ testing library
This is a testing library that intended to be slapped into projects.
As it stands, Jester is intended for use with GNU's GCC and CMake. Subsequently, it has only been tested/setup for such.
A quick overview of how the expected way to use & include Jester in a project.
You can add Jester's root folder to your CMAKE_MODULE_PATH and use include to add it to the project. This is the intended way.
# For example:
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/vendor/Jester)
include(Jester)Alternatively, can you can use add_subdirectory. This, however, has drawbacks with the exposed settable options as well as requires include(CTest)
# For example:
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/vendor/Jester)
include(CTest)Configurable options for Jester include the following.
# Settable Options.
set(JESTER_INCLUDE ${INCLUDE_FILES}) # Include files/directories
set(JESTER_SOURCES ${SOURCE_FILES}) # List of source files (via GLOB etc)
set(JESTER_LIBRARIES ${LINK_LIBRARIES}) # Libraries
set(JESTER_LINK_OPTIONS ${LINK_OPTIONS}) # Link options
set(JESTER_COMPILE_OPTIONS ${COMPILE_OPTIONS}) # Compiler optionsIt's rather likely you'll have to set both JESTER_INCLUDE and JESTER_SOURCES to make Jester work with your project.
Jester works on a directory-first basis, similar to C++ includes. To add your tests, you add the root directory of your tests. This allows Jester to name the tests based on their relative path.
# Add your test directories.
jester_add_test_directory(${TEST_ROOT_DIRECTORY})Jester does not currently support the testing of individual files directly.
A quick example of how this might be setup for a project.
Example Root
├─> include
│ └─> ...
├─> source
│ └─> ...
├─> test
│ └─> example_folder
│ └─> example.cpp
├──> vendor
│ └─> Jester
└─> CMakeLists.txt
#include <Jester/jester.hpp>
// ASSERT - Fail test if the condition evaluates false.
JEST(Test_Name_For_Assert) {
ASSERT(true); // Success
ASSERT(false); // Failure
}
// EQUAL - Fails test if two values are not equal.
JEST(EQUAL_TEST) {
EQUAL(true, true); // Success
EQUAL(123, 456); // Failure
}
// NEQUAL - Fails test if two values are equal.
JEST(neq_test) {
NEQUAL(128.0f, 256.0f); // Success
NEQUAL(std::string("Object"), std::string("Object")); // Failure
}
// EXPECT_THROW - Expects the expression inside to throw, otherwise will fail test.
JEST(testExpectThrow) {
EXPECT_THROW(throw std::runtime_exception(":)")); // Success
EXPECT_THROW(std::runtime_exception(":)")); // Failure
}# The stuff you might do before-hand.
set(INCLUDE_FILES ${CMAKE_CURRENT_LIST_DIR}/include)
file(GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/source/*.cpp)
#add_executable(${PROJECT_NAME} ${SOURCE_FILES})
#target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_FILES})
# Setting up Jester.
include(Jester)
set(JESTER_INCLUDE ${INCLUDE_FILES})
set(JESTER_SOURCES ${SOURCE_FILES})
# And finally, adding your tests.
jester_add_test_directory(${CMAKE_CURRENT_LIST_DIR}/test)After building this with cmake, there will be a single test target, example_folder_example, which can be tested with ctest :)