diff --git a/src/log/normal.c b/src/log/normal.c index 3db14d9..565e763 100644 --- a/src/log/normal.c +++ b/src/log/normal.c @@ -167,7 +167,7 @@ void normal_log_assert(struct criterion_assert_stats *stats) { bool sf = criterion_options.short_filename; criterion_pimportant(CRITERION_PREFIX_DASHES, _(msg_assert_fail), - FG_BOLD, sf ? basename(stats->file) : stats->file, RESET, + FG_BOLD, sf ? basename_compat(stats->file) : stats->file, RESET, FG_RED, stats->line, RESET, line); @@ -185,7 +185,7 @@ 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, sf ? basename(stats->file) : stats->file, RESET, + FG_BOLD, sf ? basename_compat(stats->file) : stats->file, RESET, FG_RED, stats->progress, RESET); criterion_pimportant(CRITERION_PREFIX_FAIL, _(msg_test_crash), stats->test->category, diff --git a/src/log/tap.c b/src/log/tap.c index fec23e1..23898f4 100644 --- a/src/log/tap.c +++ b/src/log/tap.c @@ -91,7 +91,7 @@ void tap_log_post_test(struct criterion_test_stats *stats) { #endif bool sf = criterion_options.short_filename; criterion_important(" %s:%u: Assertion failed: %s\n", - sf ? basename(asrt->file) : asrt->file, + sf ? basename_compat(asrt->file) : asrt->file, asrt->line, line); #ifdef VANILLA_WIN32 @@ -110,7 +110,7 @@ void tap_log_test_crash(struct criterion_test_stats *stats) { criterion_important("not ok - %s::%s unexpected signal after %s:%u\n", stats->test->category, stats->test->name, - sf ? basename(stats->file) : stats->file, + sf ? basename_compat(stats->file) : stats->file, stats->progress); } diff --git a/src/posix-compat.c b/src/posix-compat.c index 4cb7a28..376cd27 100644 --- a/src/posix-compat.c +++ b/src/posix-compat.c @@ -387,3 +387,11 @@ void *get_osx_section_end(const char *section) { return get_real_address(section_start) + secsize; } #endif + +const char *basename_compat(const char *str) { + const char *start = str; + for (const char *c = str; *c; ++c) + if ((*c == '/' || *c == '\\') && c[1]) + start = c + 1; + return start; +} diff --git a/src/posix-compat.h b/src/posix-compat.h index 84a5aef..9f938db 100644 --- a/src/posix-compat.h +++ b/src/posix-compat.h @@ -95,4 +95,6 @@ void *get_osx_section_end(const char *section); # define GET_SECTION_END(Name) SECTION_END(Name) # endif +const char *basename_compat(const char *str); + #endif /* !POSIX_COMPAT_H_ */