An open API service indexing awesome lists of open source software.

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! ๐ŸŒณ

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.