Skip to content
g-berthiaumePublic

About

A simple and ergonomic C unit tests framework.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

   ╔════════════╗
   ║ Preuve     ║  A simple and ergonomic unit tests framework.
   ╚════════════╝

   

  • C11 and up.
  • Single header library.
  • Works on Linux, Windows and MacOS.
  • Works with GCC, Clang and MSVC.
  • No warnings; even with -Wall -Wextra -Wpedantic -Wconversion or /W4.
  • No dynamic memory allocation; everything is statically allocated.
  • Support unicode tests name (even on Windows).
  • Debugger aware; A failing test will trigger a breakpoint.
  • Define your tests anywhere in your project.

   

A simple example:

#define PREUVE_IMPLEMENTATION //< To be defined once in your project.
#include "preuve.h"

TEST("strtol is 🔥", "it should parse negative numbers")
{
    errno = 0;
    long num = strtol("-123", NULL, 10);
    VERIFY_EQUAL(num, -123);
    VERIFY_EQUAL(errno, 0);
}

// v Skip this test for now
SKIP_TEST("strtol is 🔥", "it should parse explicit plus sign") 
{
    errno = 0;
    char *end;
    long num = strtol("+42", &end, 10);
    VERIFY_EQUAL(num, 42);
    VERIFY_EQUAL(errno, 0);
    VERIFY_EQUAL(*end, '\0');
}

What you will see on your terminal:

Result

A simple example of test failing:

#define PREUVE_IMPLEMENTATION
#include "preuve.h"

TEST("string", "it should print the greatest hockey team of all time")
{
    char *result = "Carolina Hurricanes";
    char  expected[] = "Montréal Canadiens";
    VERIFY_EQUAL_CSTR(result, expected);
}

What you will see on your terminal:

Result

How to use

Simply download and include preuve.h in your project. Voilà!
No autoconf. No apt install. No dependency.

You can see full examples (including the build system) in the examples folder.

Preprocessor options:

  • Define PREUVE_API_WITH_PREFIX if you want PREUVE_ to prefix the API. See examples.
  • Define PREUVE_NO_MAIN if you want to define the main yourself. See examples.

 

API Reference

// Tests
TEST(TEST_SUITE_NAME, TEST_CASE_NAME)
SKIP_TEST(TEST_SUITE_NAME, TEST_CASE_NAME)

// Verify
VERIFY(COND)
VERIFY_TRUE(COND)
VERIFY_FALSE(COND)

VERIFY_NULL(PTR)
VERIFY_EQUAL(LEFT, RIGHT)
VERIFY_EQUAL_CSTR(LEFT, RIGHT)
VERIFY_EQUAL_ARRAY(LEFT_LEN, LEFT, RIGHT_LEN, RIGHT)

VERIFY_NOT_NULL(PTR)
VERIFY_NOT_EQUAL(LEFT, RIGHT)
VERIFY_NOT_EQUAL_CSTR(LEFT, RIGHT)
VERIFY_NOT_EQUAL_ARRAY(LEFT_LEN, LEFT, RIGHT_LEN, RIGHT)

Contributing

Please don't send me GenAI slop.
Otherwise, suggestions, requests, and bug reports are welcome.

Check if you're up-to-date

curl -s https://raw.githubusercontent.com/g-berthiaume/preuve.h/refs/heads/main/preuve.h | grep "#define PREUVE_VERSION"

License

See License.

About

A simple and ergonomic C unit tests framework.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages