https://github.com/ishbguy/leptunit
A light weight C unit test library.
https://github.com/ishbguy/leptunit
light-weight unit-testing
Last synced: about 1 month ago
JSON representation
A light weight C unit test library.
- Host: GitHub
- URL: https://github.com/ishbguy/leptunit
- Owner: ishbguy
- Created: 2017-11-11T04:56:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-03T15:46:42.000Z (over 8 years ago)
- Last Synced: 2026-05-03T21:37:17.448Z (about 1 month ago)
- Topics: light-weight, unit-testing
- Language: C
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LeptUnit
[](https://travis-ci.org/ishbguy/leptunit) [](https://codecov.io/gh/ishbguy/leptunit)
LeptUnit is a light weight C unit test library which is inspired by [miloyip](https://github.com/miloyip)'s [json-tutorial](https://github.com/miloyip/json-tutorial).
## Features
+ Basic type test, such as: int, double, str, ptr
+ Simple usage
+ No dependency
+ ANSI C
## Installation
### Without build tool, only make
In Linux with gcc, make:
```
$ cd /path/to/leptunit
$ make
```
This make will generate `libleptunit.so` and `test-leptunit`, `libleptunit.so` is the dynamic shared library, `test-leptunit` is a simple test for leptunit. If you just want to generate one of it you can do like this:
```
$ cd /path/to/leptunit
$ make lib
```
or
```
$ cd /path/to/leptunit
$ make test
```
### With cmake build tool
```
$ mkdir build
$ cd build
$ cmake ..
```
**Don't run `cmake` in the repo root directory for it will generate a new Makefile to over-write the repo's default Makefile!**
## Configuration
After generate the dynamic shared library, you can copy it to the standard library directory in Linux, or:
```
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/could/ld/find
```
## Usage
Write test.c:
```C
#include "/path/to/leptunit.h"
LEPTUNIT_TEST_CASE(test_case)
{
/*
* Test bool
*/
EXPECT_TRUE(1);
EXPECT_FLASE(0);
/*
* Test equal
*/
EXPECT_EQ_INT(1, 1);
EXPECT_EQ_DOUBLE(1.0, 1.0);
EXPECT_EQ_DOUBLE_PREC(1.0, 1.0, 0.000001);
EXPECT_EQ_STR("leptunit", "leptunit");
EXPECT_EQ_NSTR("leptunit", "leptunit", strlen("leptunit"));
EXPECT_EQ_PTR("leptunit", "leptunit");
EXPECT_EQ_NULL(NULL);
/*
* Test not equal
*/
EXPECT_NE_INT(1, 2);
EXPECT_NE_DOUBLE(1.0, 2.0);
EXPECT_NE_DOUBLE_PREC(1.0, 2.0, 0.000001);
EXPECT_NE_STR("leptunit", "leptunit.h");
EXPECT_NE_NSTR("leptunit", "hello world", strlen("leptunit"));
EXPECT_NE_PTR("leptunit", "hello world");
EXPECT_NE_NULL("leptunit");
}
int main(int argc, char *argv[])
{
leptunit_suit_t *suit = leptunit_new() ;
leptunit_add(suit, test_case);
leptunit_run(suit);
leptunit_summary(suit);
leptunit_free(&suit);
return 0;
}
```
Then compile it like this:
```
$ gcc -lm -lleptunit -L/path/to/leptunit/dynamic/lib -o test test.c
$ ./test
```
If you use `EXPECT_EQ_DOUBLE`, `EXPECT_NE_DOUBLE`, `EXPECT_EQ_DOUBLE_PREC` and `EXPECT_NE_DOUBLE_PREC`, you must compile you test with -lm option.
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
## Authors
+ [ishbguy](https://github.com/ishbguy)
## License
For public used.