[Issue 1425] Feature Request: call stack reflection
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 24 17:35:30 PDT 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1425
tortoise_74 at yahoo.co.uk changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|blocker |enhancement
------- Comment #1 from tortoise_74 at yahoo.co.uk 2007-08-24 19:35 -------
For the case of using __FILE__ & __LINE__ there is a workaround as follows:
void assertEqual (T) (T actual, T expected, char[] file, uint line) {
if (actual != expected) {
writeln("Equality assertion failed.");
writefln(" actual: '%s'", actual);
writefln(" expected: '%s'", expected);
_d_assert(file, line); //or other assert wrapper
}
}
template MAssertEqual (alias actual, alias expected) {
const AssertEqual =
`assertEqual!(` ~typeof(actual).stringof ~`)(`
~actual.stringof~
`, `
~expected.stringof~
`, cast(char[])(__FILE__), __LINE__);`
;
}
unittest {
int var5 = 1;
int var6 = 2;
mixin(MAssertEqual!(var5, var6)); // -> assertEqual(var5, var6, __FILE__,
__LINE__);
}
--
More information about the Digitalmars-d-bugs
mailing list