Skip to content

DaemonTsun/t1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

t1

C++ CMake testing library. The C++ header t1.hpp is based on nyorian/vpp's bugged.hpp.

Installation

t1 is a single C++ header library that comes with a t1Config.cmake file. (sudo / admin privileges may be required)

$ cmake <dir to CMakeLists.txt> -B <output dir>
$ cmake --install <output dir>

This installs the t1.hpp header to <local include>/t1/t1.hpp and the t1Config.cmake file to <local share>/t1/cmake/t1Config.cmake.

Should running cmake <dir to CMakeLists.txt> ... fail due to no compiler being set (e.g. on Windows when running outside a developer prompt), pass -Donly_install=1 to the initial cmake command to skip building anything.

Usage

In a CMake project, use find_package(t1) to include the t1 macros. To add all source files in a directory as tests, use the add_test_directory macro. To add a single test C++ source file, use the add_t1_test macro. To register all tests as targets, use the register_tests macro.

find_package(t1)
# this if ensures t1 was found, otherwise no tests will be added
if (NOT DEFINED t1_DIR OR t1_DIR)
    add_test_directory("${CMAKE_SOURCE_DIR}/tests")
    register_tests()
endif()

The test C++ source files include <t1/t1.hpp> and use the macro define_test to define tests. Examples are in the tests directory.

#include <t1/t1.hpp>

define_test(a)
{
    assert_equal(1, 1);
    assert_equal(2, 2);
}

define_default_test_main();

Once the tests are added, tests can be compiled with the make tests target which is generated by register_tests. Individual tests may be run with make run<testname>, all tests can be run with make runtests. make vrun<testname> gives more information about the tests, including the time it took for each individual test to complete. make valgrind<testname> runs valgrind on the given test, with the output being in <bindir>/<testdir>/valgrind.log.

All of the tests will also be added as CTest tests, so using ctest is also an option.

About

C++ CMake testing library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published