A small unit-testing framework for C.
It's for testing C applications conveniently by just compiling an archive (.a) file with your other test files. It also works on Linux and Windows (at least as far as my testing on my Windows 10 and Ubuntu WSL goes).
Clone in the directory you want it on with:
git clone https://github.com/Larmix0/lukip.git
Then you can compile and use the static .a file produced with cd lukip
and make
.
The archive will appear at the same folder of the Makefile.
Inside the lukip directory, compile the project with the tests using:
make tests
then run the tests with this if you're on Linux (Although I believe this also works for Windows):
./bin/lukip
This also works (and is the typical way to do it) if you're on Windows
.\bin\lukip.exe
use make clean
to remove all object/binary/archive files generated.
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include "lukip.h"
int globalNumber = 0;
DECLARE_SETUP(setup_example) {
globalNumber += 2;
printf("Set up called, globalNumber: %d\n", globalNumber);
}
DECLARE_TEARDOWN(teardown_example) {
globalNumber--;
printf("Tear down called, globalNumber: %d\n", globalNumber);
}
TEST_CASE(empty_test) {
// Gives us a warning for having no assertions.
}
TEST_CASE(failed_test) {
ASSERT_BOOL_EQUAL(true, false); // Fail.
ASSERT_INT_EQUAL(7, 7);
ASSERT_INT_EQUAL(4, 3); // Fail.
}
TEST_CASE(successful_test) {
int8_t five = 5;
ASSERT_INT_EQUAL(five, 5);
ASSERT_INT_EQUAL(2, 2);
ASSERT_BOOL_EQUAL(true, true);
}
int main() {
LUKIP_INIT();
MAKE_FIXTURE(setup_example, teardown_example);
TEST(successful_test);
TEST(failed_test); // Fails because of this.
TEST(empty_test);
return 0;
}
If we remove/comment the fourth line of main TEST(failed_test);
then the successful output looks like the following:
- int
- int8
- int32
- int64
- long
- float
- double
- hex
- binary
- uint
- uint8
- uint16
- uint32
- uint64
- ulong
- uhex
- ubinary
- size_t
- float within precision
- char
- bool
- address
- byte array
- string
- is NULL
- Failure
- Failure with a custom formatted message
- Warning
- Warning with a custom formatted message
- is true
- is false
- is condition (another name for is true)
- is custom (same as is true, but with a custom formatted message)
For fun as well as having a small, easy-to-use unit-testing framework in C, instead of having to install other ones. Also because I'm personally about to start making a programming language, which I want to rely exclusively on my own code, including the testing framework.
(It was also a nice learning experience).
I currently don't accept any contributions as this is a personal project. However, if you find any bugs then feel free to alert me by submitting an issue.
- Better and more tests for Lukip's source.