Comment #0 by lucia.mcojocaru — 2016-11-27T14:11:04Z
The code below was meant to be a unittest in druntime/src/lifetime.d:
+unittest
+{
+ import core.exception : UnicodeException;
+
+ try
+ {
+ string ret;
+ int i = -1;
+ ret ~= i;
+ }
+ catch(UnicodeException e)
+ {
+ assert(e.msg == "Invalid UTF-8 sequence");
+ }
+}
The code in the try block throws a UnicodeException, but the catch block fails to catch it. Thus the tests fail.
However, the test passes if a template is defined for assertThrown and used instead of the inline code:
static void assertThrown(T : Throwable = Exception, E)(lazy E expr, string msg)
+ {
+ try
+ expr;
+ catch (T e) {
+ assert(e.msg == msg);
+ return;
+ }
+ }
assertThrown!UnicodeException(f(), "Invalid UTF-8 sequence");
This assertThrown template is defined in 2 other places in druntime with slight variations:
src/core/time.d:version(unittest) void _assertThrown(T : Throwable = Exception, E)
src/rt/minfo.d: static void assertThrown(T : Throwable, E)(lazy E expr, string msg)
Comment #1 by robert.schadek — 2024-12-07T13:37:08Z