Skip to content

zpl-c/tester

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
zpl
discord

A simple, minimalist tester for your minimalist needs
Brought to you by @zpl-zak, @inlife, and contributors

Introduction

Simple to use library to easily cover your code with tests. No dependencies, no obscure or over-engineered pipeline, just a dead-simple framework. You can easily make use of it, it looks pleasant (especially on CI flows), and it won't slow you down anyhow.

Who uses this library?

  • zpl - This is where the library has originated.
  • librg - Making multi-player simpler since 2017. Single-header cross-platform world replication library in pure C99.

Features

  • Easy to use single-header framework
  • No dependencies (except the standard library :)
  • Works with C99 code
  • Integrates well within any CI pipeline
  • Supports the following checks: FAIL, UFAIL, STRFAIL, EQUALS, UEQUALS, STREQUALS, STRCEQUALS, STRCNEQUALS, STRNEQUALS, NEQUALS, LESSER, GREATER, LESSEREQ, GREATEREQ, SKIP
  • Did I mention it takes a minimum time to set up?

How to obtain the library?

  • Either clone the repository or download unit.h.
  • Include unit.h in your test app and cover your code already!

Example Usage

At first, we should define our entry point for the tester app:

#define UNIT_MAX_MODULES 2
#include "unit.h"

/* TEST CATEGORIES */
#include "cases/some_math.h"
#include "cases/cool_stuff.h"

int main() {
    UNIT_CREATE("small");

    UNIT_MODULE(math);
    UNIT_MODULE(cool_stuff);

    return UNIT_RUN();
}

As you can see, this app defines 2 test modules called: math and cool_stuff, respectively.

Let's explore them!

some_math.h

#include <math.h>

MODULE(math, {
    IT("can do cos(0)", {
        EQUALS(cosf(0), 1);
    });

    IT("can do sqrt(9)", {
        EQUALS(sqrtf(9), 3);
    });
});

cool_stuff.h

MODULE(cool_stuff, {
    IT("can predict the future", {
        // Not today ...
        SKIP();
    });
});

As you can see, this is all it takes to cover your code, relatively simple, right? You can also skip tests you plan on running later in the future (or never :)

Have fun!

result

About

🧪 A simple, minimalist tester for your minimalist needs

Topics

Resources

License

Stars

Watchers

Forks