Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@film42
Last active March 26, 2016 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save film42/9a8ff13d758f2c5d7d9b to your computer and use it in GitHub Desktop.
Save film42/9a8ff13d758f2c5d7d9b to your computer and use it in GitHub Desktop.
//////////////////////////////////
// Test Runner Code
//////////////////////////////////
#include <stdio.h>
typedef int (test_fn_t)(void);
struct test_t {
char * name;
char * group;
test_fn_t * fn;
};
int __test_count;
struct test_t __test_cache[10000];
static void __attribute__ ((constructor)) __init__tests__() {
__test_count = 0;
}
#define TEST(group_name, test_name) \
int __impl__##group_name##__##test_name##__(); \
void __attribute__ ((constructor)) __##group_name##__##test_name##__() { \
struct test_t new_test; \
new_test.name = #test_name; \
new_test.group = #group_name; \
new_test.fn = &__impl__##group_name##__##test_name##__; \
__test_cache[__test_count] = new_test; \
__test_count++; \
} \
int __impl__##group_name##__##test_name##__()
int main(void) {
int i, failed_count;
struct test_t failed_tests[10000];
failed_count = 0;
for(i = 0; i < __test_count; i++) {
int result = __test_cache[i].fn();
if(result) {
printf(".");
} else {
printf("F");
failed_tests[failed_count] = __test_cache[i];
failed_count++;
}
}
printf("\n\n");
for(i = 0; i < failed_count; i++) {
struct test_t failed = failed_tests[i];
printf("%s %s failed.\n", failed.group, failed.name);
}
printf("\n");
printf("Finished\n");
return 0;
}
/////////////////////////////////////////
// Test definitions
////////////////////////////////////////
TEST(One, some_test_name) {
return 1;
}
TEST(One, some_test_name_2) {
return 0;
}
.F
One some_test_name_2 failed.
Finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment