Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 12, 2012 ModuleInfo.unitTest cannot be called twice | ||||
---|---|---|---|---|
| ||||
It seems it's not possible to call ModuleInfo.unitTest more than once.
The following code will not run the unit tests:
foreach (m ; ModuleInfo)
if (m && m.unitTest)
m.unitTest();
But this code will:
foreach (m ; ModuleInfo)
if (m)
if (auto fp = m.unitTest)
fp();
Not that I'm storing the result of "m.unitTest" in a variable in the second example.
Am I doing something wrong here or is this a bug?
--
/Jacob Carlborg
|
December 13, 2012 Re: ModuleInfo.unitTest cannot be called twice | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 2012-12-12 22:00, Jacob Carlborg wrote: > It seems it's not possible to call ModuleInfo.unitTest more than once. > > The following code will not run the unit tests: > > foreach (m ; ModuleInfo) > if (m && m.unitTest) > m.unitTest(); > > But this code will: > > foreach (m ; ModuleInfo) > if (m) > if (auto fp = m.unitTest) > fp(); > > Not that I'm storing the result of "m.unitTest" in a variable in the > second example. > > Am I doing something wrong here or is this a bug? I see what I did wrong. ModuleInfo.unitTest is a method these days, instead of a field like before. Due two how properties work in D it will only call the "unitTest" method and not the returned function pointer. -- /Jacob Carlborg |
December 13, 2012 Re: ModuleInfo.unitTest cannot be called twice | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Am Wed, 12 Dec 2012 22:00:55 +0100
schrieb Jacob Carlborg <doob@me.com>:
> It seems it's not possible to call ModuleInfo.unitTest more than once.
>
> The following code will not run the unit tests:
>
> foreach (m ; ModuleInfo)
> if (m && m.unitTest)
> m.unitTest();
>
> But this code will:
>
> foreach (m ; ModuleInfo)
> if (m)
> if (auto fp = m.unitTest)
> fp();
>
> Not that I'm storing the result of "m.unitTest" in a variable in the second example.
>
> Am I doing something wrong here or is this a bug?
>
I don't remember a reason why calling that function more than once shouldn't work.
But: unitTest is a property returning a function so it might be related
to the optional parentheses / broken properties stuff. Does
"m.unitTest()()" compile?
|
December 13, 2012 Re: ModuleInfo.unitTest cannot be called twice | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johannes Pfau | On 2012-12-13 08:58, Johannes Pfau wrote: > I don't remember a reason why calling that function more than > once shouldn't work. > > But: unitTest is a property returning a function so it might be related > to the optional parentheses / broken properties stuff. Does > "m.unitTest()()" compile? Yeah, that was the problem. I though unitTest was a field. -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation