Jens Mueller Wrote: > Hi, > > I'm trying to improve the assertions. I tried the following > auto foo(bool var) { > return tuple(var, "MyMessage"); > } > > void bar(bool var, string text) { > } > > unittest { > bar(foo(true).expand); > //assert(foo(true).expand); // won't compile > } > > void main() {} > > $ dmd -unittest -run file.d > Commenting in the assert it fails with > "Error: expression > tuple(foo(true)._field_field_0,foo(true)._field_field_1) of type (bool, > string) does not have a boolean value" > > assert behaves different when expanding tuples. Any explanations? > If one could do the above without writing the expand then it would > suggest a nice way of enhancing the build-in assert, I think. > If one cannot make it work without the .expand another option may be > to overload the built-in assert to handle tuples. This may be related to > http://d.puremagic.com/issues/show_bug.cgi?id=5547 > Then one writes e.g. > assert(throws!MyException(expression)) > or > assert(pred!("==")(a, b)) > What do you think? > > Jens
Or like this: import std.conv; string cat(T...)(T ts) { string s; foreach(t; ts) s ~= to!string(t) ~ " "; return s; } unittest { ... assert(a==b, cat(a,b)); }