aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2015-12-04 16:40:16 +0100
committerCamil Staps2015-12-04 16:40:16 +0100
commitfd0c013f914f47b040d937c293fccac5e5224208 (patch)
treec2764c571160f9a27605eb00e9442f44a0704e8c
parentInclude guard (diff)
Timing
-rw-r--r--minctest.c11
-rw-r--r--minctest.h7
2 files changed, 18 insertions, 0 deletions
diff --git a/minctest.c b/minctest.c
index 61a3688..82bb552 100644
--- a/minctest.c
+++ b/minctest.c
@@ -31,6 +31,7 @@ tester* test_initialize(void) {
test->passed = 0;
test->failed = 0;
test->show_pass = true;
+ test_start_timer(test);
return test;
}
@@ -53,15 +54,25 @@ void test_exit(tester* tester) {
exit(all_passed ? 0 : -1);
}
+void test_start_timer(tester* tester) {
+ gettimeofday(&tester->start_last_test, NULL);
+}
+
void test_true(tester* tester, bool check, const char* text) {
+ struct timeval end;
+ gettimeofday(&end, NULL);
+
if (!check || tester->show_pass) {
printf(check ? KGRN : KRED);
printf(check ? "Test passed" : "Test failed");
if (text != NULL)
printf(": %s", text);
+ printf(" [%.3fs]", ((float) end.tv_usec - tester->start_last_test.tv_usec) / 1000);
printf("\n" RESET);
}
*(check ? &tester->passed : &tester->failed) += 1;
+
+ test_start_timer(tester);
}
diff --git a/minctest.h b/minctest.h
index 0438c9c..1aaf19c 100644
--- a/minctest.h
+++ b/minctest.h
@@ -20,11 +20,13 @@
#include <inttypes.h>
#include <stdbool.h>
+#include <sys/time.h>
typedef struct {
uint16_t passed; // Number of passed tests
uint16_t failed; // Number of failed tests
bool show_pass; // Whether or not to print a message when a test passes
+ struct timeval start_last_test;
} tester;
/**
@@ -67,6 +69,11 @@ void test_destroy(tester*);
void test_exit(tester*);
/**
+ * Start the timer for a test
+ */
+void test_start_timer(tester*);
+
+/**
* Test for truth on a bool
*
* Outputs a red message for failure, and a green one for passing if