Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 02, 2006 assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
I have been toying with D to bring myself up to speed and I found myself writing a lot of unit tests, always a good thing. In those unit tests I found myself writing a lot of blocks like: if (cond) { writefln("some debugging output to make my life easier"); assert(false); } I know many don't like unit tests to have output, but I do. To simplify this, I've created a patch for gdc/dmd to allow this syntax instead: assert(cond, "some optional debugging output to make my life easier"); http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff http://www.puremagic.com/~braddr/d/assert-test.d I've run this through dstress with no regressions. Anyone wanna give it a whirl? Later, Brad |
February 02, 2006 Re: assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
Posted in reply to braddr | braddr@puremagic.com wrote:
> I have been toying with D to bring myself up to speed and I found myself writing
> a lot of unit tests, always a good thing. In those unit tests I found myself
> writing a lot of blocks like:
>
> if (cond)
> {
> writefln("some debugging output to make my life easier");
> assert(false);
> }
>
> I know many don't like unit tests to have output, but I do. To simplify this,
> I've created a patch for gdc/dmd to allow this syntax instead:
>
> assert(cond, "some optional debugging output to make my life easier");
>
> http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff
> http://www.puremagic.com/~braddr/d/assert-test.d
>
> I've run this through dstress with no regressions.
>
> Anyone wanna give it a whirl?
>
> Later,
> Brad
>
>
How can we install/apply the patch?
|
February 02, 2006 Re: assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
Posted in reply to braddr | Does this effect static asserts? Currently, you can do this with them:
static assert ("Some message.", 0);
This is because it is passed an expression, and so "", 0 just evaluates to 0. But it does display the whole thing.
-[Unknown]
> I have been toying with D to bring myself up to speed and I found myself writing
> a lot of unit tests, always a good thing. In those unit tests I found myself
> writing a lot of blocks like:
>
> if (cond)
> {
> writefln("some debugging output to make my life easier");
> assert(false);
> }
>
> I know many don't like unit tests to have output, but I do. To simplify this,
> I've created a patch for gdc/dmd to allow this syntax instead:
>
> assert(cond, "some optional debugging output to make my life easier");
>
> http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff
> http://www.puremagic.com/~braddr/d/assert-test.d
>
> I've run this through dstress with no regressions.
>
> Anyone wanna give it a whirl?
>
> Later,
> Brad
>
>
|
February 02, 2006 Re: assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Unknown W. Brackets | In article <drs52m$mu$1@digitaldaemon.com>, Unknown W. Brackets says... >> I have been toying with D to bring myself up to speed and I found myself writing a lot of unit tests, always a good thing. In those unit tests I found myself writing a lot of blocks like: >> >> if (cond) >> { >> writefln("some debugging output to make my life easier"); >> assert(false); >> } >> >> I know many don't like unit tests to have output, but I do. To simplify this, I've created a patch for gdc/dmd to allow this syntax instead: >> >> assert(cond, "some optional debugging output to make my life easier"); >> >> http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff http://www.puremagic.com/~braddr/d/assert-test.d >> >> I've run this through dstress with no regressions. >> >> Anyone wanna give it a whirl? >> >> Later, >> Brad > >Does this effect static asserts? Currently, you can do this with them: > >static assert ("Some message.", 0); > >This is because it is passed an expression, and so "", 0 just evaluates to 0. But it does display the whole thing. > >-[Unknown] <peeking at the code...> Looks like assert and static assert are handled by completely different blocks of code, completely. so, static assert(...) is unchanged. Later, Brad |
February 02, 2006 Re: assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | In article <drs0sb$2vhj$1@digitaldaemon.com>, Hasan Aljudy says... > >braddr@puremagic.com wrote: >> I have been toying with D to bring myself up to speed and I found myself writing a lot of unit tests, always a good thing. In those unit tests I found myself writing a lot of blocks like: >> >> if (cond) >> { >> writefln("some debugging output to make my life easier"); >> assert(false); >> } >> >> I know many don't like unit tests to have output, but I do. To simplify this, I've created a patch for gdc/dmd to allow this syntax instead: >> >> assert(cond, "some optional debugging output to make my life easier"); >> >> http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff http://www.puremagic.com/~braddr/d/assert-test.d >> >> I've run this through dstress with no regressions. >> >> Anyone wanna give it a whirl? >> >> Later, >> Brad >> >> > >How can we install/apply the patch? Save the .diff to a file, use the standard unix tool 'patch' to apply it to a gcc+gdc source tree from the gcc directory, and rebuild gdc. Later, Brad |
February 02, 2006 Re: assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
Posted in reply to braddr | On Thu, 02 Feb 2006 01:35:20 +0000, braddr wrote:
> I have been toying with D to bring myself up to speed and I found myself writing a lot of unit tests, always a good thing. In those unit tests I found myself writing a lot of blocks like:
>
> if (cond)
> {
> writefln("some debugging output to make my life easier");
> assert(false);
> }
>
> I know many don't like unit tests to have output, but I do. To simplify this, I've created a patch for gdc/dmd to allow this syntax instead:
>
> assert(cond, "some optional debugging output to make my life easier");
>
> http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff http://www.puremagic.com/~braddr/d/assert-test.d
>
> I've run this through dstress with no regressions.
>
> Anyone wanna give it a whirl?
>
> Later,
> Brad
Simply "Thank you". Great thing.
|
February 02, 2006 Re: assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
Posted in reply to braddr | braddr wrote:
> I know many don't like unit tests to have output, but I do. To simplify this,
> I've created a patch for gdc/dmd to allow this syntax instead:
>
> assert(cond, "some optional debugging output to make my life easier");
Excellent, I would be happy to include this in "gdcmac" for instance.
(if there aren't any objections to including "non-offical" D patches
into the compiler, already have a few necessary-for-portability ones)
Too bad that it doesn't get past the:
assert(false, "Walter didn't like it");
--anders
|
February 02, 2006 Re: assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
Posted in reply to braddr | It's been a while since I've programmed something but I used something along the lines of assert(condition && "whatever") or assert(condition && printf("whatever")), whichever worked. In article <drrnko$2onm$1@digitaldaemon.com>, braddr@puremagic.com says... > >I have been toying with D to bring myself up to speed and I found myself writing a lot of unit tests, always a good thing. In those unit tests I found myself writing a lot of blocks like: > >if (cond) >{ >writefln("some debugging output to make my life easier"); >assert(false); >} > >I know many don't like unit tests to have output, but I do. To simplify this, I've created a patch for gdc/dmd to allow this syntax instead: > >assert(cond, "some optional debugging output to make my life easier"); > >http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff http://www.puremagic.com/~braddr/d/assert-test.d > >I've run this through dstress with no regressions. > >Anyone wanna give it a whirl? > >Later, >Brad > > |
May 30, 2006 Re: assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
Posted in reply to braddr | In article <drrnko$2onm$1@digitaldaemon.com>, braddr@puremagic.com says... > >I have been toying with D to bring myself up to speed and I found myself writing a lot of unit tests, always a good thing. In those unit tests I found myself writing a lot of blocks like: > >if (cond) >{ >writefln("some debugging output to make my life easier"); >assert(false); >} > >I know many don't like unit tests to have output, but I do. To simplify this, I've created a patch for gdc/dmd to allow this syntax instead: > >assert(cond, "some optional debugging output to make my life easier"); > >http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff http://www.puremagic.com/~braddr/d/assert-test.d > >I've run this through dstress with no regressions. > >Anyone wanna give it a whirl? > >Later, >Brad I was just about to start bringing this patch up to work with current dmd and gdc but decided I should ask first: Is anyone using it with gdc 0.17? Would anyone use it if I freshened it up? Walter, would you be interested / willing to incorporate the parser part into dmd and support the feature in dmd? I've seen a couple alternatives suggested, but they've all been somewhat hacky, imho. Later, Brad |
May 30, 2006 Re: assert(condition[, message]) patch | ||||
---|---|---|---|---|
| ||||
Posted in reply to braddr | braddr@puremagic.com wrote:
> In article <drrnko$2onm$1@digitaldaemon.com>, braddr@puremagic.com says...
>> I have been toying with D to bring myself up to speed and I found myself writing
>> a lot of unit tests, always a good thing. In those unit tests I found myself
>> writing a lot of blocks like:
>>
>> if (cond)
>> {
>> writefln("some debugging output to make my life easier");
>> assert(false);
>> }
>>
>> I know many don't like unit tests to have output, but I do. To simplify this,
>> I've created a patch for gdc/dmd to allow this syntax instead:
>>
>> assert(cond, "some optional debugging output to make my life easier");
>>
>> http://www.puremagic.com/~braddr/d/assert-optional-message-0.1.diff
>> http://www.puremagic.com/~braddr/d/assert-test.d
>>
>> I've run this through dstress with no regressions.
>>
>> Anyone wanna give it a whirl?
>>
>> Later,
>> Brad
>
> I was just about to start bringing this patch up to work with current dmd and
> gdc but decided I should ask first:
>
> Is anyone using it with gdc 0.17?
> Would anyone use it if I freshened it up?
> Walter, would you be interested / willing to incorporate the parser part into
> dmd and support the feature in dmd?
>
> I've seen a couple alternatives suggested, but they've all been somewhat hacky,
> imho.
>
> Later,
> Brad
>
>
Just my thoughts, I think it's definitely got some merits, although one must consider that the assert( statementToTest ) would give you the line that threw the assert, which makes a message a bit less important. Although, on the other hand, if someone (ie not someone who wrote the code) were to see the assert and check the given line, it probably wouldn't mean too much to them, whereas being able to see a message associated with it would be a bit more useful. I'd definitely give the mod a whirl.
|
Copyright © 1999-2021 by the D Language Foundation