A simple, minimalist tester for your minimalist needs
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.
- 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.
- 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?
- Either clone the repository or download unit.h.
- Include
unit.h
in your test app and cover your code already!
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!
#include <math.h>
MODULE(math, {
IT("can do cos(0)", {
EQUALS(cosf(0), 1);
});
IT("can do sqrt(9)", {
EQUALS(sqrtf(9), 3);
});
});
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!