dunit r247
Nick Sabalausky
a at a.a
Thu Mar 19 17:26:44 PDT 2009
"Christopher Wright" <dhasenan at gmail.com> wrote in message
news:gpuibc$1nrv$1 at digitalmars.com...
> bearophile wrote:
>> What's the advantage of:
>> expect(foo(5), equals(3) | greaterThan(5));
>> Compared to:
>> expect(foo(5) == 3 | foo(5) > 5);
>
> What error message should that give?
>
> The former gives:
> Expected: equal to 3 or greater than 5
> But was: <whatever value foo(5) returned>
>
> The latter gives:
> Assertion error
>
The nice thing about D is how often it lets you, as I prefer to word it,
"Eat your cake and then still have it."
Attached is the assert-alternative that I use (D1/Tango). It's used like
this:
---------------------
module nonFatalAssertTest.main;
import semitwist.util.nonFatalAssert;
void main()
{
FatalizeAsserts();
// Main program code here
}
unittest
{
int foo = 2;
// *REALLY* need a way for a template to automatically get
// the file/line of instantiation.
// Improvement to mixin syntax would also be nice
// Also, my editor doesn't know that backticks indicate a string,
// so it's still properly highlighted as code :)
mixin(NonFatalAssert!(__LINE__, __FILE__, `foo == 3 || foo > 5`, "foo is
bad"));
mixin(NonFatalAssert!(__LINE__, __FILE__, `2 + 2 == 4`, "Basic
arithmetic"));
mixin(NonFatalAssert!(__LINE__, __FILE__, `false`));
}
---------------------
Output of that is:
---------------------
nonFatalAssertTest\main.d(16): Assert Failure (foo == 3 || foo > 5): foo is
bad
nonFatalAssertTest\main.d(18): Assert Failure (false)
tango.core.Exception.AssertException at semitwist\util\nonFatalAssert.d(62): 2
Assert Failures
---------------------
Granted, this doesn't currently output foo's actual value, but it probably
wouldn't be too hard to modify it to do so via std.algorithm-style trickery.
begin 666 nonFatalAssert.d
M+R\@4V5M:51W:7-T($QI8G)A<GD-"B\O(%=R:71T96X@:6X@=&AE($0@<')O
M9W)A;6UI;F<@;&%N9W5A9V4N#0H-"B\J*B -"D%U=&AO<CH-"B0H5T5"('=W
M=RYS96UI='=I<W0N8V]M+"!.:6-K(%-A8F%L875S:WDI#0H-"D-O;G-I9&5R
M('1H:7,@=&\@8F4@=6YD97(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0L(&-H87);72!M
M<V<](B(I#0I[#0H)8F]O;"!?3F]N1F%T86Q!<W-E<G0H8F]O;"!R97-U;'0I
M#0H)>PT*"0EI9B at A<F5S=6QT*0T*"0E[#0H)"0EN;VY&871A;$%S<V5R=$-O
M=6YT*RL[#0H)"0E3=&1O=70N9F]R;6%T;&XH(GM]*'M]*3H at 07-S97)T($9A
M:6QU<F4@*'M]*7M](BP-"@D)"2 @(" @(" @(" @(" @("!F:6QE+"!L:6YE
M+"!C;VYD+ T*"0D)"0D)(" @(&US9ST](B(@/R B(B Z("(Z("(@?B!M<V<I
M.PT*"0E]#0H)"0T*"0ER971U<FX@<F5S=6QT.PT*"7T-"GT-"G!R:79A=&4@
M=6EN="!N;VY&871A;$%S<V5R=$-O=6YT/3 [#0IU:6YT(&=E=$YO;D9A=&%L
M07-S97)T0V]U;G0H*0T*>PT*"7)E='5R;B!N;VY&871A;$%S<V5R=$-O=6YT
M.PT*?0T*=F]I9"!R97-E=$YO;D9A=&%L07-S97)T0V]U;G0H*0T*>PT*"6YO
M;D9A=&%L07-S97)T0V]U;G0@/2 P.PT*?0T*#0IV;VED($9A=&%L:7IE07-S
M97)T<R at I#0I[#0H):68H9V5T3F]N1F%T86Q!<W-E<G1#;W5N="@I(#X@,"D-
M"@E[#0H)"5-T9&]U="YF;'5S:"@I.PT*"0EA<W-E<G0H9F%L<V4L#0H)"0ET
M;R$H8VAA<EM=*2AG971.;VY&871A;$%S<V5R=$-O=6YT*"DI('X-"@D)"2(@
M07-S97)T($9A:6QU<F4B('X-"@D)"2AG971.;VY&871A;$%S<V5R=$-O=6YT
B*"D@/3T@,2 _("(B(#H@(G,B*0T*"0DI.PT*"7T-"GT-"@``
`
end
More information about the Digitalmars-d-announce
mailing list