a tiny test framework for C++17
 
 
 
Go to file
Justin Collier 32b3c2c1fc
Merge branch 'patch-0.5.2'
2023-04-04 11:47:58 -07:00
cmake fixed documentation generators 2023-04-04 11:47:38 -07:00
include fixed thread safety 2023-04-04 11:43:58 -07:00
test fixed thread safety 2023-04-04 11:43:58 -07:00
.clang-format reduced and decomplicated. several API changes 2020-12-26 17:17:38 -08:00
.gitignore reduced and decomplicated. several API changes 2020-12-26 17:17:38 -08:00
CHANGELOG.md fixed thread safety 2023-04-04 11:43:58 -07:00
CMakeLists.txt fixed thread safety 2023-04-04 11:43:58 -07:00
LICENSE Initial commit 2020-08-25 17:35:49 -07:00
Makefile fixed thread safety 2023-04-04 11:43:58 -07:00
README.md fixed documentation generators 2023-04-04 11:47:38 -07:00

README.md

cctest 0.5.2 | API Docs | CHANGELOG

About

cctest is a tiny test framework for C++17.

The API has been simplified since 0.4.2. Please check the usage instructions and CHANGELOG.

Usage

Creating a main file (may be seperate or as part of a test source):

#define CCTEST_MAIN
#include <cctest.h>

Creating test files:

#include <cctest.h>
#include <cstring>

TEST("test all the things") {
  static_assert(true, "use static_assert wherever possible!");
  ASSERT(1 == 1); // make a runtime assertion
  auto e = ASSERT_THROWS(std::runtime_error) { // returns thrown error by value
    throw std::runtime_error{"hello"};
  };
  ASSERT(strcmp(e.what(), "hello") == 0);
};

TEST("multiple tests per file are OK") {
  static_assert(true, "runtime assertions are not required");
};

Note: cctest is thread safe, but most tests should be defined at namespace or global scope.

Execution:

${CXX} ${CXXFLAGS} -std=c++17 main.cc test0.cc test1.cc -o test
./test

 > this test passes
 > another passing test
 > sample fail test
     FAIL /path/to/src.cc:50
     what: this is an expected failure

 > tests continue after runtime failure

1 Test Failed

Setup

Standalone Header

Copy include/cctest.h into your project and include it.

note:
There should be no compiler warnings for GCC or Clang with -Wall -Wextra -pedantic. Additionally, #pragma statements are used to filter Clang's -Weverything, so simple inclusion should be fine in most cases.

CMake Install

git clone -b 0.5.2 https://github.com/jpcx/cctest.git
cd cctest

make # mkdir build
     # cmake -Bbuild

# installs header to      ${DESTDIR}${PREFIX}/include/cctest-0.5.2
# installs cmake files to ${DESTDIR}${PREFIX}/lib/cmake/cctest-0.5.2
sudo make install # cmake --install build
find_package(cctest 0.5 REQUIRED)
target_link_libraries([your target] cctest)

CMake FetchContent

include(FetchContent)
FetchContent_Declare(cctest
                     GIT_REPOSITORY https://github.com/jpcx/cctest.git
                     GIT_TAG "0.5.2")
FetchContent_MakeAvailable(cctest)
target_link_libraries([your target] cctest)

CMake add_subdirectory

git clone -b 0.5.2 https://github.com/jpcx/cctest.git # or git submodule add
add_subdirectory([cctest download dir])
target_link_libraries([your target] cctest)

Testing

All API features are self-tested:

cd [cctest source dir]
make test # mkdir build
          # cmake -Bbuild
          # cmake --build build --target test

Contributing

Contribution is welcome! Please make a pull request.