Added -S switch to display the base name of source files

This commit is contained in:
Snaipe 2015-08-20 07:58:38 +02:00
parent 9db9b5776a
commit b4fc22e7e4
4 changed files with 15 additions and 5 deletions

View file

@ -35,6 +35,7 @@ struct criterion_options {
bool use_ascii;
bool fail_fast;
const char *pattern;
bool short_filename;
};
extern struct criterion_options criterion_options;

View file

@ -164,9 +164,10 @@ void normal_log_assert(struct criterion_assert_stats *stats) {
char *line = strtok_r(dup, "\n", &saveptr);
#endif
bool sf = criterion_options.short_filename;
criterion_pimportant(CRITERION_PREFIX_DASHES,
_(msg_assert_fail),
FG_BOLD, stats->file, RESET,
FG_BOLD, sf ? basename(stats->file) : stats->file, RESET,
FG_RED, stats->line, RESET,
line);
@ -181,9 +182,10 @@ void normal_log_assert(struct criterion_assert_stats *stats) {
}
void normal_log_test_crash(struct criterion_test_stats *stats) {
bool sf = criterion_options.short_filename;
criterion_pimportant(CRITERION_PREFIX_DASHES,
_(msg_test_crash_line),
FG_BOLD, stats->file, RESET,
FG_BOLD, sf ? basename(stats->file) : stats->file, RESET,
FG_RED, stats->progress, RESET);
criterion_pimportant(CRITERION_PREFIX_FAIL, _(msg_test_crash),
stats->test->category,

View file

@ -89,8 +89,9 @@ void tap_log_post_test(struct criterion_test_stats *stats) {
char *saveptr = NULL;
char *line = strtok_r(dup, "\n", &saveptr);
#endif
bool sf = criterion_options.short_filename;
criterion_important(" %s:%u: Assertion failed: %s\n",
asrt->file,
sf ? basename(asrt->file) : asrt->file,
asrt->line,
line);
#ifdef VANILLA_WIN32
@ -105,10 +106,11 @@ void tap_log_post_test(struct criterion_test_stats *stats) {
}
void tap_log_test_crash(struct criterion_test_stats *stats) {
bool sf = criterion_options.short_filename;
criterion_important("not ok - %s::%s unexpected signal after %s:%u\n",
stats->test->category,
stats->test->name,
stats->file,
sf ? basename(stats->file) : stats->file,
stats->progress);
}

View file

@ -57,6 +57,8 @@
" -f or --fail-fast: exit after the first failure\n" \
" --ascii: don't use fancy unicode symbols " \
"or colors in the output\n" \
" -S or --short-filename: only display the base " \
"name of the source file on a failure\n" \
PATTERN_USAGE \
" --tap: enables TAP formatting\n" \
" --always-succeed: always exit with 0\n" \
@ -124,6 +126,7 @@ int main(int argc, char *argv[]) {
{"list", no_argument, 0, 'l'},
{"ascii", no_argument, 0, 'k'},
{"fail-fast", no_argument, 0, 'f'},
{"short-filename", no_argument, 0, 'S'},
#ifdef HAVE_PCRE
{"pattern", required_argument, 0, 'p'},
#endif
@ -146,6 +149,7 @@ int main(int argc, char *argv[]) {
opt->fail_fast = !strcmp("1", getenv("CRITERION_FAIL_FAST") ?: "0");
opt->use_ascii = use_ascii;
opt->logging_threshold = atoi(getenv("CRITERION_VERBOSITY_LEVEL") ?: "2");
opt->short_filename = !strcmp("1", getenv("CRITERION_SHORT_FILENAME") ?: "0");
#ifdef HAVE_PCRE
opt->pattern = getenv("CRITERION_TEST_PATTERN");
#endif
@ -155,13 +159,14 @@ int main(int argc, char *argv[]) {
bool do_list_tests = false;
bool do_print_version = false;
bool do_print_usage = false;
for (int c; (c = getopt_long(argc, argv, "hvlf", opts, NULL)) != -1;) {
for (int c; (c = getopt_long(argc, argv, "hvlfS", opts, NULL)) != -1;) {
switch (c) {
case 'b': criterion_options.logging_threshold = atoi(optarg ?: "1"); break;
case 'y': criterion_options.always_succeed = true; break;
case 'z': criterion_options.no_early_exit = true; break;
case 'k': criterion_options.use_ascii = true; break;
case 'f': criterion_options.fail_fast = true; break;
case 'S': criterion_options.short_filename = true; break;
#ifdef HAVE_PCRE
case 'p': criterion_options.pattern = optarg; break;
#endif