Thanks to visit codestin.com
Credit goes to github.com

Skip to content

KitsuneSemCalda/Cest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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, C17, C23
C++ C++17, C++20, C++23
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++.
  • Modern Language Support: C11/C17/C23, C++17/C++20/C++23, ObjC with ARC.
  • 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 seamlessly 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.

About

A C-based test unit engine like javascript testing tool Jest / golang testing tool Gest

Topics

Resources

License

Stars

4 stars

Watchers

0 watching

Forks

Contributors