On Sat, May 14, 2016 at 03:32:45PM +0200, Andrej Mitrovic via Digitalmars-d wrote: [...] > Add a new compiler switch (or better yet use a built-in version > switch) which makes all assertions chatty. > > So for a unittest like this: > > ---- > auto sum (a, b) => a + b; > > /// > unittest { assert(sum(2, 2) == 4); } > ---- > > Running it with something like this: > > ---- > $ dmd -unittest -version=printasserts -run test.d > ---- > > Would produce: > > ---- > > test.d(4): assert(4 == 4); was successful > ---- > > We could nitpick about the actual output, but the general idea is to > avoid having to modify all the unittests by hand and instead use a > compiler switch for chatty assertions.
I like this idea. But wouldn't it be too verbose? I.e., there may be a lot of non-unittest-related assertions inside other functions and such. We could say only top-level asserts in a unittest block become chatty, but that excludes unittests calling unittest-only helper functions to do the checks. > And actually if we used a -version switch then I think we could > implement this entirely in Druntime. That is unless I remember > incorrectly how assertions are emitted, I haven't looked at the code > in a while. How would the assert implementation in druntime access the expression being tested? I.e., in a way that it can be printed out in human-readable form. T -- Gone Chopin. Bach in a minuet.