Added ANSI color support
This commit is contained in:
parent
5951e636cf
commit
b0f4ad6e6d
1 changed files with 34 additions and 8 deletions
|
@ -28,22 +28,35 @@
|
|||
#include "criterion/ordered-set.h"
|
||||
#include "timer.h"
|
||||
|
||||
#define NORMALIZE(Str) (criterion_options.use_ascii ? "" : Str)
|
||||
|
||||
#define FG_BOLD NORMALIZE("\e[0;1m")
|
||||
#define FG_RED NORMALIZE("\e[0;31m")
|
||||
#define FG_GREEN NORMALIZE("\e[0;32m")
|
||||
#define FG_BLUE NORMALIZE("\e[0;34m")
|
||||
#define RESET NORMALIZE("\e[0m")
|
||||
|
||||
void normal_log_pre_init(struct criterion_test *test) {
|
||||
criterion_info("%s::%s: RUNNING\n", test->category, test->name);
|
||||
criterion_info("[%sRUN%s ] %s::%s\n", FG_BLUE, RESET, test->category, test->name);
|
||||
}
|
||||
|
||||
void normal_log_post_test(struct criterion_test_stats *stats) {
|
||||
const char *format = can_measure_time() ? "%s::%s: %s (%3.2fs)\n" : "%s::%s: %s\n";
|
||||
criterion_log(stats->failed ? CRITERION_IMPORTANT : CRITERION_INFO,
|
||||
format,
|
||||
const char *format = can_measure_time() ? "%s::%s: (%3.2fs)\n" : "%s::%s\n";
|
||||
const enum criterion_logging_level level = stats->failed ? CRITERION_IMPORTANT
|
||||
: CRITERION_INFO;
|
||||
const char *color = stats->failed ? FG_RED : FG_GREEN;
|
||||
|
||||
criterion_log(level, "[%s%s%s%s] ", FG_BOLD, color, stats->failed ? "FAIL" : "PASS", RESET);
|
||||
criterion_log(level, format,
|
||||
stats->test->category,
|
||||
stats->test->name,
|
||||
stats->failed ? "FAILURE" : "SUCCESS",
|
||||
stats->elapsed_time);
|
||||
}
|
||||
|
||||
void normal_log_post_all(struct criterion_global_stats *stats) {
|
||||
criterion_important("Synthesis: " SIZE_T_FORMAT " test%s run. " SIZE_T_FORMAT " passed, " SIZE_T_FORMAT " failed (with " SIZE_T_FORMAT " crash%s)\n",
|
||||
criterion_important("[%s====%s] ", FG_BLUE, RESET);
|
||||
criterion_important("%sSynthesis: " SIZE_T_FORMAT " test%s run. " SIZE_T_FORMAT " passed, " SIZE_T_FORMAT " failed (with " SIZE_T_FORMAT " crash%s)\n",
|
||||
FG_BOLD,
|
||||
stats->nb_tests,
|
||||
stats->nb_tests == 1 ? " was" : "s were",
|
||||
stats->tests_passed,
|
||||
|
@ -54,17 +67,30 @@ void normal_log_post_all(struct criterion_global_stats *stats) {
|
|||
|
||||
void normal_log_assert(struct criterion_assert_stats *stats) {
|
||||
if (!stats->passed) {
|
||||
criterion_important("%s:%d: Assertion failed: %s\n",
|
||||
criterion_important("[%s----%s] ", FG_BLUE, RESET);
|
||||
criterion_important("%s%s%s:%s%d%s: Assertion failed: %s\n",
|
||||
FG_BOLD,
|
||||
stats->file,
|
||||
RESET,
|
||||
FG_RED,
|
||||
stats->line,
|
||||
RESET,
|
||||
*stats->message ? stats->message : stats->condition);
|
||||
}
|
||||
}
|
||||
|
||||
void normal_log_test_crash(struct criterion_test_stats *stats) {
|
||||
criterion_important("Unexpected signal after %s:%u!\n%s::%s: FAILURE (CRASH!)\n",
|
||||
criterion_important("[%s----%s] ", FG_BLUE, RESET);
|
||||
criterion_important("%s%s%s:%s%u%s: Unexpected signal caught below this line!\n",
|
||||
FG_BOLD,
|
||||
stats->file,
|
||||
RESET,
|
||||
FG_RED,
|
||||
stats->progress,
|
||||
RESET);
|
||||
criterion_important("[%sFAIL%s] %s::%s: CRASH!\n",
|
||||
FG_RED,
|
||||
RESET,
|
||||
stats->test->category,
|
||||
stats->test->name);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue