Custom asset handler messes unit test summary report
Basile B.
b2.temp at gmx.com
Mon Feb 24 02:08:06 UTC 2020
On Monday, 24 February 2020 at 00:50:38 UTC, ric maicle wrote:
> [dmd 2.090.1 linux 64-bit]
>
> The following code does not report the correct unit test
> summary.
> The report says 1 unit test passed.
>
> ~~~~~
> shared static this() {
> import core.exception;
> assertHandler(&cah);
> }
>
> void
> cah(string file, ulong line, string msg) nothrow {
> import core.stdc.stdio: printf;
> printf("==============================\n");
> printf("Assert error: %s %d: %s\n", file.ptr, line,
> msg.ptr);
> printf("==============================\n");
> }
>
> unittest {
> assert(false);
> }
> ~~~~~
Looks like you have to throw an Error at the end of your custom
handler, e.g:
---
void
cah(string file, ulong line, string msg) nothrow {
import core.stdc.stdio: printf;
import core.exception : AssertError;
printf("==============================\n");
printf("Assert error: %s %d: %s\n", file.ptr, line, msg.ptr);
printf("==============================\n");
throw new AssertError("");
}
---
For a betterC program you can use an HLT:
---
void
cah(string file, ulong line, string msg) nothrow {
import core.stdc.stdio: printf, fflush, stdout;
printf("==============================\n");
printf("Assert error: %s %d: %s\n", file.ptr, line, msg.ptr);
printf("==============================\n");
fflush(stdout);
asm nothrow { hlt; }
}
---
More information about the Digitalmars-d-learn
mailing list