Skip to content
/ tester Public

🧪 A simple, minimalist tester for your minimalist needs

License

Notifications You must be signed in to change notification settings

zpl-c/tester

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Contributors 3

  •  
  •  
  •