From 545184da662c4a84d08da5591d7516fc64b80e43 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Thu, 13 Jan 2022 19:42:05 +0000 Subject: [PATCH] tlib: report last error on ASSERT failure --- build/VStudio/testing/fsbench.vcxproj | 6 ++++++ ext/tlib/testsuite.c | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/build/VStudio/testing/fsbench.vcxproj b/build/VStudio/testing/fsbench.vcxproj index 699f16fd..03f96ba3 100644 --- a/build/VStudio/testing/fsbench.vcxproj +++ b/build/VStudio/testing/fsbench.vcxproj @@ -146,6 +146,7 @@ Console + ntdll.lib;%(AdditionalDependencies) @@ -161,6 +162,7 @@ Console + ntdll.lib;%(AdditionalDependencies) @@ -176,6 +178,7 @@ Console + ntdll.lib;%(AdditionalDependencies) @@ -195,6 +198,7 @@ Console true true + ntdll.lib;%(AdditionalDependencies) @@ -214,6 +218,7 @@ Console true true + ntdll.lib;%(AdditionalDependencies) @@ -233,6 +238,7 @@ Console true true + ntdll.lib;%(AdditionalDependencies) diff --git a/ext/tlib/testsuite.c b/ext/tlib/testsuite.c index ed0c946d..ad5d1c73 100644 --- a/ext/tlib/testsuite.c +++ b/ext/tlib/testsuite.c @@ -201,16 +201,23 @@ void tlib_run_tests(int argc, char *argv[]) } void tlib__assert(const char *func, const char *file, int line, const char *expr) { + char extra_buf[256] = ""; #if defined(_WIN64) || defined(_WIN32) + long __stdcall RtlGetLastNtStatus(void); + unsigned long __stdcall RtlGetLastWin32Error(void); + snprintf(extra_buf, sizeof extra_buf, + " (err=%lx:%lu)", + RtlGetLastNtStatus(), + RtlGetLastWin32Error()); const char *p = strrchr(file, '\\'); #else const char *p = strrchr(file, '/'); #endif file = 0 != p ? p + 1 : file; if (0 == func) - test_printf("%sASSERT(%s) failed at: %s:%d\n", assert_buf, expr, file, line); + test_printf("%sASSERT(%s) failed at: %s:%d%s\n", assert_buf, expr, file, line, extra_buf); else - test_printf("%sASSERT(%s) failed at %s:%d:%s\n", assert_buf, expr, file, line, func); + test_printf("%sASSERT(%s) failed at %s:%d:%s%s\n", assert_buf, expr, file, line, func, extra_buf); if (0 != test_jmp) longjmp(*test_jmp, 1); }