> On Thu, 14 Apr 2011 13:16:33 -0400, Andrei Alexandrescu > > <[email protected]> wrote: > > On 4/14/11 12:00 PM, Steven Schveighoffer wrote: > >> On Thu, 14 Apr 2011 12:48:26 -0400, Andrei Alexandrescu > >> > >> <[email protected]> wrote: > >>> On 4/14/11 9:03 AM, Steven Schveighoffer wrote: > >>>> Sometimes, I worry that my unit tests or asserts aren't running. Every > >>>> once in a while, I have to change one to fail to make sure that code > >>>> is > >>>> compiling (this is especially true when I'm doing version statements > >>>> or > >>>> templates). It would be nice if there was a -assertprint mode which > >>>> showed asserts actually running (only for the module compiled with > >>>> that > >>>> switch, of course). > >>> > >>> Could this be achieved within the language? > >> > >> I think you need to do it at the compiler level to make it useful. For > >> example, an assert like: > >> > >> assert(container.length == 5); > >> > >> To print this out properly, I'd want to see that the assert passed, but > >> also what the test was. > > > > What's needed here is a "text of expression" feature similar to C's "#". > > That would help enforce and other artifacts too. I'm thinking along the > > lines of: > > > > void myassert(string expr = __traits(text, condition))(bool condition) { > > > > ... > > > > } > > > > with, of course, a simpler syntax. > > It still isn't exactly right. Assert has some special properties that > cannot be duplicated exactly with library code. Such as true lazy > evaluation and elimination during release mode. > > But yes, it would be nice to be able to get a string of the parameters of > a function (macro?). It would certainly make this more feasible. > > However, all this is ignoring one simple thing -- the hundreds of > thousands of lines of code (mostly from std.datetime ;) ) that already > have asserts. Hooking assert directly automatically gives us a tool for > printf debugging without changing any code.
Actually, std.datetime doesn't use assert much. It mostly uses a version of assertPred which it has as a private function. Also, I've been rewriting the unit tests, and that will result in far fewer actual lines with assert or _assertPred thanks to more looping and whatnot. It does increase the need for printing out the actual results from an assertion though (which _assertPred does on failure). And what you're asking for here is at least related to the requested improvements to assert which resulted in assertPred being scrapped. - Jonathan M Davis
