• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H11-May-2019-

tests/H11-May-2019-

.gitignoreH A D11-May-20198

license.mdH A D11-May-2019483

makefileH A D11-May-2019754

readme.mdH A D11-May-20191.8 KiB

readme.md

1# Testoasterror
2Testoasterror is a minimalistic testing library. It is written in C99
3and does not use dynamic memory allocations by default.
4
5# Testing
6Run `make` and `make run`. This will execute the example in the `tests` folder.
7
8# Using
9## TL;DR
10Check out the `tests` folder
11
12## Details
13Include `testoasterror.h` and compile `testoasterror.c` with your testing `main()`.
14
15Declare an array of `bool` to hold the results of each tested expression.
16Its size determines the maximum number of expression checks for the same test.
17If one outreaches that limit, testoasterror will print a "fail overflow" message.
18The limit is 255, the maximum for a `uint8_t`.
19```
20bool results[255];
21```
22
23Also declare an array of function pointers to hold your tests
24```
25void (*funcs[3])(struct testoasterror*) =
26{
27	test1,
28	test2,
29	test3
30}
31```
32
33Then, initialize a testoasterror context, giving:
34 - a pointer to the context to initialize
35 - the expression results buffer
36 - its length
37 - the testing functions array
38 - its length
39```
40struct testoasterror test;
41testoasterror_init(&test, results, 255, funcs, 3);
42```
43
44Run the tests and you're good to go!
45```
46testoasterror_run(&test);
47```
48
49You can now write your tests in other C files, using the same function prototype
50```
51#ifndef C_TESTS
52#define C_TESTS
53
54#include "testoasterror.h"
55
56// a test
57void test1(struct testoasterror* test)
58{
59	// an expression check
60	testoasterror(test, 1 > 0);
61}
62
63#endif
64```
65
66It is, in my opinion, a good idea to include them directly with the `main()`.
67This way, the function pointers will resolve without the need for a header
68(hence the include guards in the C file example above)
69```
70#include "tests.c"
71```
72
73Extra: to abort, call the fail function *and return*
74```
75testoasterror_fail(test);
76```
77
78# Greetings
79nnorm for ninja-starring this repo (how can you be *this* fast?!)
80