how to print the tested-condition in myAsssert -- stringification needed
boywonder
donot.reply at no.reply.com
Fri Aug 30 22:12:00 PDT 2013
I'm using the myAssert() suggested by others in the D forum, with
a few tweaks:
void myAssert(int line = __LINE__, string file = __FILE__,
Args...)(lazy bool condition, lazy Args args) {
string string_version_of_condition = //? how?
if (!condition)
{
writefln("Assertion (%s) failed @ %s:%d in test '%s'",
string_version_of_condition, file, line, currentTestName);
foreach(a; args) {
write(" assert-extra: ");
writeln(a);
}
exit(1);
}
}
}
This is great, but I would also like to print out the stringified
version of the condition, so that the assert shows me the text of
the failed test-condition.
e.g.
myAssert(1 == 0);
// should result in:
Assertion (1 == 0) failed @ test.d:34 in test 'bool test'
How to I initialize string_version_of_condition? In C/C++, I'd
use a macro and token pasting.
More information about the Digitalmars-d-learn
mailing list