1. Alexander Gallego
  2. ctest

Overview

HTTPS SSH

ctest Description:

Is a set of macros to help you unit test your C programs. It is simple and modeled after minunit.h

Open bugs and Issues:

None

Example:

#include<stdio.h>
#include "ctest.h"

static char * test_foo() {
       cassert(7==7,"error, foo != 7");
       return NULL;
}
static char * test_bar() {
       cassert(4 == 5, "error, bar != 5");
       return NULL;
}
static char * test_foo_bar() {
       cassert(1 == 0, "ouch false!!!");
       return NULL;
}
static char * test_true() {
       cassert(1 == 1, "Passing test with flying colors");
       return NULL;
}
void all_tests() {
     crun(test_foo_bar);
     crun(test_foo);
     crun(test_bar);
     crun(test_true);
}
int main(int argc, char **argv) {
    all_tests();
    csummary();
    return 0;
}

Output:

$ ./a.out

FAILED: test_example.c.test_foo_bar.14: ouch false!!!
FAILED: test_example.c.test_bar.9:      error, bar != 5

====Summary====
2 Tests PASSED
2 Tests FAILED
4 TOTAL TESTS

Using the example in this repo:

  :::fantom
  gcc -Wall test_example.c