selftest.c (769B)
1 /* selftest.c - ./calc --selftest [--deep] */ 2 #include <stdarg.h> 3 #include <stdio.h> 4 #include <time.h> 5 #include "selftest.h" 6 7 static int checks, fails; 8 static bool verbose; 9 10 void st_check(bool ok, const char *fmt, ...) 11 { 12 checks++; 13 if (ok && !verbose) return; 14 if (!ok) fails++; 15 va_list ap; 16 va_start(ap, fmt); 17 printf("%s ", ok ? " ok " : "FALLA"); 18 vprintf(fmt, ap); 19 printf("\n"); 20 va_end(ap); 21 } 22 23 int selftest_run(bool deep) 24 { 25 clock_t t0 = clock(); 26 verbose = deep; 27 selftest_num(deep ? 20000 : 2000); 28 selftest_calc(); 29 selftest_edit(); 30 selftest_app(); 31 selftest_modes(); 32 printf("%d chequeos, %d fallas (%ld ms)\n", checks, fails, (long)((clock() - t0) * 1000 / CLOCKS_PER_SEC)); 33 return fails ? 1 : 0; 34 }