/caught

A lightweight & simple C testing library

Primary LanguageCOtherNOASSERTION

Caught

Version Build Status Docs License

A lightweight & simple C testing library

Features

  • No setup - just #include
  • Easy to use syntax
  • Beautiful colored output that just works
  • Easily expand for custom types

Example test

int factorial(n)
{
    return n <= 1 ? 1 : factorial(n - 1) * n;
}

TEST("factorial")
{
    EXPECT_INT(factorial(1), ==, 1);
    EXPECT_INT(factorial(2), ==, 2);
    EXPECT_INT(factorial(3), ==, 6);
    EXPECT_INT(factorial(4), ==, 24);
    EXPECT_INT(factorial(5), ==, 120);
}

Installation

  1. Download the caught.h and caught.c files from the latest release
  2. In your test files, simply #include "caught.h"
  3. Modify your compiler to compile your tests & caught.c
  4. See Usage for how to begin!

Note: your code cannot include a main function as Caught needs to define it.

One file solution If you only want to have one test file, you can put the contents of `caught.c` at the end of `caught.h` and just include that instead, without modifying your compiler to compile `caught.c`.

This works because there cannot be duplicate definitions of main.

From source If you want, you can always download the full source and use that directly.

However, you will need to make sure you include the actual path to caught.h (#include "path/to/caught.h") and update your compiler to compile all of Caught's files.

Usage

Please see the following docs: