Remove TopContext with all declarations

M Breugelmans mbr.nxi at gmail.com
Tue Jan 27 09:01:35 UTC 2009


On Tue, Jan 27, 2009 at 9:14 AM, David nolden <zwabel at googlemail.com> wrote:
> Am Dienstag 27 Januar 2009 00:23:21 schrieb Milian Wolff:
>> Am Montag 26 Januar 2009 schrieb Milian Wolff:
>> > Hi there!
>> >
>> > I'm working on the PHP plugin and encountered a strange bug/feature I
>> > cannot get fixed.
>>
>> I think I an idea on what could be the issue:
>> > In the completion test (completion/tests/test_completion.cpp) I parse
>> > some PHP-Code and get a TopDUContext. Once the test is done, I call
>> > release(top) which essentially calls
>> > DUChain::self()->removeDocumentChain(top).
>>
>> Essentially, this problem occurred because one of  the earlier tests failed
>> and thus the release(top) was never called...
>>
>> Nothing I can do except making sure all tests pass, right?
>
> C++ gives us a simple tool for this:
>
> struct DUChainReleaser {
> DUChainReleaser(TopDUContext* top) : m_top(top) {
> }
> ~DUChainRelease() {
> release(m_top);
> }
> TopDUContext* m_top;
> };
>
>
> In your test:
>
> top = parse
> lock
> DUChainReleaser autoRelease(top);
> do whatever you want
>

Alternatively you could use the setup-teardown cycle of xUnit,
invented for these kind of issues. The 'init()' method is guaranteed
to be  called before each test method, 'cleanup()' after.  So to fix
this move 'top' to the test fixture as class member, initialize it in
'init()' and do cleanup in 'cleanup()'.


Manuel




More information about the KDevelop-devel mailing list