Skip to content

Larmix0/lukip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lukip

A small unit-testing framework for C.

What the project's about

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).

Building

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.

Testing (for development)

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

cleaning

use make clean to remove all object/binary/archive files generated.

Usage example

This is a simple failed program example:

#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;
}

The output of the failed program looks like the following:

fail case

If we remove/comment the fourth line of main TEST(failed_test); then the successful output looks like the following:

success case

Available assertions and their supported operands

Signed numbers (==, !=, >, >=, <, <=)

  • int
  • int8
  • int32
  • int64
  • long
  • float
  • double
  • hex
  • binary

Unsigned numbers (==, !=, >, >=, <, <=)

  • uint
  • uint8
  • uint16
  • uint32
  • uint64
  • ulong
  • uhex
  • ubinary
  • size_t

Equal or not (==, !=)

  • float within precision
  • char
  • bool
  • address
  • byte array
  • string
  • is NULL

Raise (automatically outputs a result)

  • Failure
  • Failure with a custom formatted message
  • Warning
  • Warning with a custom formatted message

Special

  • is true
  • is false
  • is condition (another name for is true)
  • is custom (same as is true, but with a custom formatted message)

Why I made Lukip

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).

Contributing

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.

Known issues

  • Better and more tests for Lukip's source.

About

A small unit-testing framework in C.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published