FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

class example

 
Post new topic   Reply to topic     Forum Index -> DMocks
View previous topic :: View next topic  
Author Message
manni



Joined: 16 Jan 2006
Posts: 25

PostPosted: Wed Mar 12, 2008 4:47 am    Post subject: class example Reply with quote

Hello,

Code:

public class Rect {

    private int x;
    public int getX() {
        return x;
    }
}
   

    unittest {
    auto mock = new Mocker;
    Rect rectMock = mock.mock!(Rect);
    mock.expect(rectMock.getX()).returns(4);
    writefln(rectMock.getX());
    mock.replay;
    mock.verify;

    }

void main() {
    writefln("Main");
}


Under dmd 2.012 (Linux) i get an error:
dmocks/MockObject.d(29): Error: cannot evaluate BodyPart() at compile time
dmocks/MockObject.d(20): Error: cannot evaluate Body() at compile time
attribute argument to mixin must be a string, not (Body())
dmocks/MockObject.d(19): template instance dmocks.MockObject.Mocked!(Rect) error instantiating

Under dmd 2.011 it compiles, but if i start the programm i get an
Segmentation fault (core dumped)

Have you an idea what this can be?

Manfred
Back to top
View user's profile Send private message
dhasenan



Joined: 03 Feb 2005
Posts: 73
Location: New York

PostPosted: Wed Mar 12, 2008 12:20 pm    Post subject: Reply with quote

Yes -- it's me not keeping up to date with the latest few DMD2 releases. I'll look into it later today.
Back to top
View user's profile Send private message AIM Address
dhasenan



Joined: 03 Feb 2005
Posts: 73
Location: New York

PostPosted: Wed Mar 12, 2008 6:54 pm    Post subject: Reply with quote

Curiouser and curiouser. Compiling it with -version=MocksDebug produces...nothing. That should produce some output -- actually it's rather spammy -- but nothing.

Apparently the getX method wasn't even mocked. print, toString, toHash, opCmp, opEquals, fine; but not getX.

__traits(allMembers, Rect) returns [print toString toHash opCmp opEquals].

*sigh* I'll file a bug report and hope this gets fixed within my lifetime.

As for the other problem, it's just D being cranky about what CTFE it accepts. I'll have to do some shotgun debugging. Of course, that's useless for now...
Back to top
View user's profile Send private message AIM Address
dhasenan



Joined: 03 Feb 2005
Posts: 73
Location: New York

PostPosted: Wed Mar 12, 2008 7:13 pm    Post subject: Reply with quote

Okay, as an ugly workaround, you can specify no protection attributes on any method you want to have mocked.

That is, the following works:

Code:

class Rect
{
      private int x;
      int getX() { return x; }
}


That's for 2.010; I'm going to check with 2.011 and then 2.012.

Though replay and verify as the last two steps...fail:
Quote:

Error: MocksSetupException: Last call: if you do not specify the AllowDefaults option, you need to return a value, throw an exception, execute a delegate, or pass through to base function. The call is: Rect.getX() Expected: 1..1 Actual: 0


It should be:

Code:

unittest
{
    auto mock = new Mocker;
    Rect rectMock = mock.mock!(Rect);
    mock.expect(rectMock.getX()).returns(4);
    // any other setup necessary
    mock.replay;

    // NOW we can use the values we just set up
    writefln(rectMock.getX());

    mock.verify;
}
Back to top
View user's profile Send private message AIM Address
dhasenan



Joined: 03 Feb 2005
Posts: 73
Location: New York

PostPosted: Wed Mar 12, 2008 8:38 pm    Post subject: Reply with quote

Wait, you actually managed to compile it with DMD2.011? Without source modification? That's impossible.

It's also impossible, it seems, in DMD2.012. __traits(getVirtualFunctions) returns final functions, and explicitly filtering with __traits(isFinalFunction) makes the template not evaluable at compile time.

I'm giving up on dmocks for now; dmd just isn't in a reasonable state for me to offer it. I can have an entirely bug-free release for one version of the compiler, then for the next version, everything breaks for stupid reasons like this. I wouldn't mind so much if it were things like the const redesigns messing me up, but this is just pointless.
Back to top
View user's profile Send private message AIM Address
manni



Joined: 16 Jan 2006
Posts: 25

PostPosted: Thu Mar 13, 2008 1:40 am    Post subject: Reply with quote

My goal was to write some examples in my d_buch
www.steinmole.de/d/

Under dmd 2.010, and 2.011 run the example.

Great that you fill out a bug report, i think i must learn that too Wink

Thank you for your effort.

Manfred
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DMocks All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group