Integrated new report system into core
This commit is contained in:
parent
dcfbc13773
commit
da66a5704e
3 changed files with 51 additions and 5 deletions
|
@ -37,6 +37,7 @@
|
|||
#include "wrappers/wrap.h"
|
||||
#include "string/i18n.h"
|
||||
#include "io/event.h"
|
||||
#include "log/output.h"
|
||||
#include "runner_coroutine.h"
|
||||
#include "stats.h"
|
||||
#include "runner.h"
|
||||
|
@ -347,6 +348,8 @@ struct criterion_test_set *criterion_initialize(void) {
|
|||
if (resume_child()) // (windows only) resume from the fork
|
||||
exit(0);
|
||||
|
||||
criterion_init_output();
|
||||
|
||||
return criterion_init();
|
||||
}
|
||||
|
||||
|
@ -451,6 +454,8 @@ static int criterion_run_all_tests_impl(struct criterion_test_set *set) {
|
|||
report(POST_ALL, stats);
|
||||
log(post_all, stats);
|
||||
|
||||
process_all_output(stats);
|
||||
|
||||
cleanup:
|
||||
sfree(g_worker_pipe);
|
||||
sfree(stats);
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "criterion/options.h"
|
||||
#include "criterion/ordered-set.h"
|
||||
#include "core/runner.h"
|
||||
#include "log/output.h"
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <khash.h>
|
||||
#include <kvec.h>
|
||||
#include "criterion/output.h"
|
||||
|
||||
typedef kvec_t(const char *) str_vec;
|
||||
|
||||
KHASH_MAP_INIT_STR(ht_str, criterion_reporter*)
|
||||
KHASH_MAP_INIT_STR(ht_path, const char *)
|
||||
KHASH_MAP_INIT_STR(ht_path, str_vec*)
|
||||
|
||||
static khash_t(ht_str) *reporters;
|
||||
static khash_t(ht_path) *outputs;
|
||||
|
@ -22,13 +25,50 @@ int criterion_register_output_provider(const char *name, criterion_reporter *rep
|
|||
}
|
||||
|
||||
int criterion_add_output(const char *provider, const char *path) {
|
||||
int absent;
|
||||
khint_t k = kh_put(ht_path, outputs, provider, &absent);
|
||||
kh_value(outputs, k) = path;
|
||||
return absent;
|
||||
khint_t k = kh_get(ht_path, outputs, provider);
|
||||
|
||||
if (k == kh_end(outputs)) {
|
||||
int absent;
|
||||
k = kh_put(ht_path, outputs, provider, &absent);
|
||||
if (absent == -1)
|
||||
return -1;
|
||||
|
||||
str_vec *vec = malloc(sizeof (str_vec));
|
||||
kv_init(*vec);
|
||||
kh_value(outputs, k) = vec;
|
||||
}
|
||||
str_vec *vec = kh_value(outputs, k);
|
||||
|
||||
kv_push(const char *, *vec, path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void criterion_free_output(void) {
|
||||
kh_destroy(ht_str, reporters);
|
||||
kh_destroy(ht_path, outputs);
|
||||
}
|
||||
|
||||
void process_all_output(struct criterion_global_stats *stats) {
|
||||
for (khint_t k = kh_begin(reporters); k != kh_end(reporters); ++k) {
|
||||
if (!kh_exist(reporters, k))
|
||||
continue;
|
||||
|
||||
criterion_reporter *report = kh_value(reporters, k);
|
||||
khint_t ko = kh_get(ht_path, outputs, kh_key(reporters, k));
|
||||
if (ko == kh_end(outputs))
|
||||
continue;
|
||||
|
||||
str_vec *vec = kh_value(outputs, ko);
|
||||
for (size_t i = 0; i < kv_size(*vec); ++i) {
|
||||
const char *path = kv_A(*vec, i);
|
||||
|
||||
FILE *f;
|
||||
if (path[0] == '-' && !path[1])
|
||||
f = stderr;
|
||||
else
|
||||
f = fopen(path, "w");
|
||||
|
||||
report(f, stats);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue