aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2022-06-14 18:21:57 +0300
committerLasse Collin <lasse.collin@tukaani.org>2022-06-14 18:21:57 +0300
commit83d2337b72dbf391c6f3b41889eea99e51679105 (patch)
tree11ccaaa834f2540798ef4cb2d24e3643dc99c7cf /tests
parentTests: Add test file good-1-empty-bcj-lzma2.xz. (diff)
downloadxz-83d2337b72dbf391c6f3b41889eea99e51679105.tar.xz
Tests: tuktest.h: Move a printf from a macro to a helper function.
Diffstat (limited to 'tests')
-rw-r--r--tests/tuktest.h26
1 files changed, 18 insertions, 8 deletions
diff --git a/tests/tuktest.h b/tests/tuktest.h
index 962e2514..ea71d080 100644
--- a/tests/tuktest.h
+++ b/tests/tuktest.h
@@ -457,22 +457,32 @@ tuktest_run_test(void (*testfunc)(void), const char *testfunc_str)
}
-// Internal helper that converts an enum tuktest_result value to a string.
-static const char *
-tuktest_result_str(enum tuktest_result result)
+// Internal helper that prints the prefix of the fail/skip/error message line.
+static void
+tuktest_print_result_prefix(enum tuktest_result result,
+ const char *filename, unsigned line)
{
- return result == TUKTEST_PASS ? TUKTEST_STR_PASS
- : (result) == TUKTEST_FAIL ? TUKTEST_STR_FAIL
- : (result) == TUKTEST_SKIP ? TUKTEST_STR_SKIP
+ // This is never called with TUKTEST_PASS but I kept it here anyway.
+ const char *result_str
+ = result == TUKTEST_PASS ? TUKTEST_STR_PASS
+ : result == TUKTEST_FAIL ? TUKTEST_STR_FAIL
+ : result == TUKTEST_SKIP ? TUKTEST_STR_SKIP
: TUKTEST_STR_ERROR;
+
+ const char *short_filename = tuktest_basename(filename);
+
+ if (tuktest_name != NULL)
+ printf("%s %s [%s:%u] ", result_str, tuktest_name,
+ short_filename, line);
+ else
+ printf("%s [%s:%u] ", result_str, short_filename, line);
}
// Internal helper for assert_fail, assert_skip, and assert_error.
#define tuktest_print_and_jump(result, ...) \
do { \
- printf("%s %s [%s:%u] ", tuktest_result_str(result), tuktest_name, \
- tuktest_basename(__FILE__), __LINE__); \
+ tuktest_print_result_prefix(result, __FILE__, __LINE__); \
printf(__VA_ARGS__); \
printf("\n"); \
longjmp(tuktest_jmpenv, result); \