Skip to content
KitsuneSemCaldaPublic

About

Header-only testing framework for C, C++, Objective-C, and Objective-C++, with expressive assertions and test hooks.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

41 Commits

Folders and files

Repository files navigation

Cest

Minimalist C Unit Testing Framework inspired by Jest and Gest.

License Header Only C++ Objective-C

Cest is a lightweight, header-only testing framework for C and related languages. It brings the expressive syntax of modern JavaScript and Go testing tools to C-family languages.


Supported Languages

Language Extension Compiler Full Support
C .c gcc, clang Yes
C++ .cpp g++, clang++ Yes
Objective-C .m clang -x objective-c Yes
Objective-C++ .mm clang++ -x objective-c++ Yes

Language Versions

Language Versions
C C11 or newer
C++ C++11 or newer
ObjC ARC & non-ARC

Quick Start

C

#include "cest.h"

int main() {
    describe("Math Suite", {
        it("sums numbers correctly", {
            expect(1 + 1).toEqual(2);
        });
    });

    return cest_result();
}
gcc -std=c11 -o test test.c
./test

C++

#include "cest.h"
#include <string>

int main() {
    describe("String Suite", {
        it("compares strings", {
            std::string s = "hello";
            expect(s).toEqual("hello");
        });
    });

    return cest_result();
}
g++ -std=c++11 -o test test.cpp
./test

Objective-C

#import "cest.h"

int main() {
    describe("ObjC Suite", {
        it("works with id", {
            id obj = (id)0x1234;
            expect(obj).toBeTruthy();
        });
    });

    return cest_result();
}
clang -x objective-c -o test test.m -lobjc
./test

Advanced Features

Hooks

Setup and teardown code for tests:

void setup() { /* initialize */ }
void teardown() { /* cleanup */ }

beforeAll(setup);
afterAll(teardown);

describe("Database Tests", {
    beforeEach(setup);
    afterEach(teardown);
    
    it("connects", {
        expect(connect_db()).toBeTruthy();
    });
});

Benchmarking

Simple performance measurement:

describe("Performance", {
    bench("string operations", {
        char buffer[100];
        sprintf(buffer, "test %d", 42);
    });
});

Output:

● Performance
  ⚡ string operations: 0.000015s total, 0.000000s avg

CLI Filtering

Run specific tests from command line:

./test "Math"    # Run only tests containing "Math"
./test           # Run all tests

Cest Demo Cest Demo Cest Demo


Features

  • Header-Only: Just include cest.h in your project.
  • Multi-Language: Native support for C, C++, Objective-C, and Objective-C++.
  • No Dependencies: Zero external libraries (not even -lm).
  • Modern Syntax: Uses describe, it, and expect for readable tests.
  • Colorized Output: Instant visual feedback in your terminal.
  • Type-Safe: Uses _Generic (C11) or function overloading (C++) for automatic type handling.
  • Multi-file Support: Compile multiple .c test files and Cest unifies results.
  • Auto Grouping: Use describe_file() to automatically group tests by source file.
  • Hooks Support: beforeAll, afterAll, beforeEach, afterEach for setup/cleanup.
  • Built-in Benchmarking: Simple performance measurement with bench macro.
  • Sanitizer Compatible: Works with ASan, TSan, MSan.
  • Clean Output: Automatic compiler warning suppression.

Available Matchers

Matcher Description
toBe(x) / toEqual(x) Checks value equality or identity.
toBeTruthy() Checks if the value is "truthy".
toBeFalsy() Checks if the value is "falsy" or null.
toBeNull() Checks if a pointer is NULL or nil.
toBeGreaterThan(x) Checks if the value is greater than x.
toBeLessThan(x) Checks if the value is less than x.
toBeInRange(min, max) Checks if the value is within range.
toContain(substring) Checks if a string contains a sub-string.
toStartWith(prefix) Checks if a string starts with prefix.
toEndWith(suffix) Checks if a string ends with suffix.
toBeCloseTo(val, prec) Compares doubles with specific precision.
toEqualArray(arr, len) Compares two memory regions.

Building Examples

make              # Build all examples to build/
make run          # Build and run all examples
make clean        # Clean build directory

Documentation

Detailed documentation is available in multiple languages:


License

This project is licensed under the BSD-3 Clause License.

Test counts and assertion counts

The console summary reports test cases (test / it) separately from assertions (expect). A loop containing 100 expectations inside one test counts as one test and 100 assertions. A test fails if any of its assertions fails; a filtered test is skipped, and an executed test with no assertions passes. The existing cest_stats().passed and .failed fields continue to count assertions for compatibility. Summary test totals remain accurate even when CEST_MAX_TEST_RECORDS limits the stored report records.

About

Header-only testing framework for C, C++, Objective-C, and Objective-C++, with expressive assertions and test hooks.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages