https://github.com/maloleroy/confer
๐งช A C/C++ unit testing library written in C, with no heap memory allocation! ๐ณ
https://github.com/maloleroy/confer
c cpp testing unit-testing
Last synced: about 2 months ago
JSON representation
๐งช A C/C++ unit testing library written in C, with no heap memory allocation! ๐ณ
- Host: GitHub
- URL: https://github.com/maloleroy/confer
- Owner: maloleroy
- License: mit
- Created: 2022-08-05T00:29:46.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-06-17T20:59:14.000Z (about 1 year ago)
- Last Synced: 2025-06-17T21:40:03.110Z (about 1 year ago)
- Topics: c, cpp, testing, unit-testing
- Language: C
- Homepage: https://maloleroy.github.io/confer/
- Size: 1.58 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Confer
======
Confer is a C and C++ unit testing library written in C.
## Features
Confer comes with a number of tools and feaures out of the box.
- 20+ built-in assertions for most common types
- Custom assertions
- Fast build (...)
- Extra-light library written in C, no dynamic memory allocation (hence no memory leaks)
- A handy tool to manage projects and run tests (not compulsory)
## Installation
The easiest way to install confer is with the install script:
```bash
bash <(curl -sL https://url.viarezo.fr/cf)
```
## Preview
Create a project with `cf create my_project`. Now let's look at the example code:
`src/my_project.c` contains a simple code using a function `add` declared in `include/add.h`
```c
#include
#include
int main(void) {
printf("Hello world!\n1 + 2 = %d\n", add(1, 2));
return 0;
}
```
To build the executable and run it, run `cf run`
```
$ cf run
๐จ src/add.c -> obj/add.o
โ src/my_project.c obj/add.o -> bin/my_project
Hello world!
1 + 2 = 3
```
> Here is the declaration of `add` in `include/add.h`:
> ```c
> int add(int a, int b);
> ```
This function is defined in `src/add.c`
```c
#include
int add(int a, int b) {
return a + b;
}
```
Now, we're getting to the interesting part: **the tests!** The `add` function is tested in `test/test.c`
```c
#include
#include
void test_add(CFTEST) {
assert_int_equal(add(1, 2), 3);
}
int main(void) {
cf_init();
cf_test(test_add);
cf_print_call_tree();
return cf_return_code();
}
```
Here, after calling the initialization function `cfInit`, the main function calls the subtest `test_add`, which has one assertion on the `add` function. The code ends by displaying the results, and returns an error exit code if some tests failed.
To run the tests, run `cf test`
```
๐จ src/add.c -> obj/add.o
โ main
โโโ โ test_add (1 โ)
```
You can nest subtests indefinitely, they will be displayed in a tree-like structure at the end of execution.
## What next?
To know more about the library, we also recommend you visiting [Confer's official documentation on GitHub](https://maloleroy.github.io/confer/)!
## Where can I get help?
Feel free to open issues on the [Github Repo](https://github.com/maloleroy/confer), especially if
you did not find an answer to a question in our documentation.