/***** * test_framework.c * * See test_framework.h. * * $Id: test_framework.c 12570 2007-04-09 16:44:25Z mahoney $ ******/ #include #include "utility.h" #include "test_framework.h" int n_tests_tried = 0; int n_tests_passed = 0; void ok(bool test_result, char* message){ char* format = "%4i %-12s %-48s \n"; n_tests_tried++; if (test_result){ n_tests_passed++; printf(format, n_tests_tried, "ok", message); } else { printf(format, n_tests_tried, "not ok", message); } } void print_test_summary(){ printf("1..%i \n", n_tests_tried); if (n_tests_passed == n_tests_tried){ printf("All tests successful.\n"); } else { printf("Failed %i of %i tests.\n", n_tests_tried - n_tests_passed, n_tests_tried); } } int test_status(){ // return 0 if all tests are successful, 1 otherwise. // (This is consistent with unix process return values; 0 for success.) if (n_tests_passed == n_tests_tried){ return 0; } else { return 1; } }