Change glib test framework to minunit

This commit is contained in:
Ruben Laguna
2015-06-23 19:17:24 +02:00
parent 7acc23761a
commit 844bdf6d3c
6 changed files with 63 additions and 19 deletions

30
tests/add.c Normal file
View File

@@ -0,0 +1,30 @@
#include "minunit.h"
#include "add.h"
#include <stdlib.h> /* exit() */
#include <stdio.h> /* perror(), printf(), fprintf() */
int tests_run=0;
char * add_test() {
mu_assert("add(1,2) must produce 3", add(1,2) == 4);
return 0;
}
char * all_tests() {
mu_run_test(add_test);
return 0;
}
int main(int argc, char *argv[])
{
char *result = all_tests();
if (result) {
printf("FAILURE\n");
exit(1);
}
printf("ALL TESTS PASSED");
return 0;
}

8
tests/minunit.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef MINUNIT_H
#define MINUNIT_H
extern int tests_run;
#define mu_assert(message,test) do { if (!(test)) return message; } while (0)
#define mu_run_test(test) do { char *result = test(); tests_run++; if (result) return result; } while (0)
#endif /* MINUNIT_H */