https://github.com/clement-muth/criterion-unit-test-c
Some example of criterion unit tests
https://github.com/clement-muth/criterion-unit-test-c
c criterion test-unitaire unit-test
Last synced: 24 days ago
JSON representation
Some example of criterion unit tests
- Host: GitHub
- URL: https://github.com/clement-muth/criterion-unit-test-c
- Owner: Clement-Muth
- Created: 2021-02-21T14:41:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-21T19:22:00.000Z (over 5 years ago)
- Last Synced: 2025-05-18T05:32:53.150Z (about 1 year ago)
- Topics: c, criterion, test-unitaire, unit-test
- Language: Shell
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# criterion_unit_test_c
Some example of criterion unit tests
# Summary
- Installation
- Example
- Rules for Makefile
- Some example of unit test with criterion
# Installation
Use this [file](https://github.com/Clement-Muth/criterion_unit_test_c/blob/master/install_criterion.sh) to install criterion
```bash
chmod 777 install_criterion.sh
./install_criterion.sh
```
# Example
## Rules for Makefile
```Make
tests_run:
gcc $(SRCS) tests/*.c -o unit_tests --coverage -lcriterion -Iincludes/
- ./unit_tests
```
## Some example of unit test with criterion
[Unit test](https://github.com/Clement-Muth/criterion_unit_test_c/blob/master/test_output.c) which test output of a program
```c
#include
#include
static void redirect_all_stdout(void)
{
cr_redirect_stdout();
cr_redirect_stderr();
}
Test(test_output, test_output_string, .init=redirect_all_stdout)
{
write(1, "test output\n", 13);
cr_assert_stdout_eq_str("test output\n");
}
```
[Unit test](https://github.com/Clement-Muth/criterion_unit_test_c/blob/master/test_string_compare.c) which test string output of a function
```c
#include
Test(test_string_compare, test_string)
{
char test[] = "test string";
cr_assert_str_eq(test, "test string");
}
```