Mason Wheeler If you used any mocking library in Delphi you would know. None (that I know of) can do argument matching (except writing your own code in the execute delegate that you can specify in most libs). So in this case the mock will be good whenever it is called having the string parameter contain 'hello' regardless the other arguments.
A. Bouchez Hm, I don't see which of your overloads lets you define a partial match for the method parameters. Match all or none have been in DSharp mocks and I think Delphi Mocks also supports it.
Delphi Mocks will have this soon, we have been working on it. The biggest issue we had was the order of parameter passing is not defined in delphi (64bit seems to be consistent, 32bit not).. so it's not as neat as we had hope. - eg: mockCredit.Setup .WillReturn(6) .When .TakesTwoParams(It(0).IsEqualTo(1), It(1).IsEqualTo(true));
Vincent Parrett Personally I am not sure if this Moq inspired API works so well in Delphi because of the poor type inference.
What I like about this way though is that you don't have to pass any dummy values that make the statement look ambiguous. With the way I took though you can write statements like this (if that is ever useful is another story ^^):
When((Args[0] = 1) or (Args[1] = 'Hello'))
Maybe I can make them both work. Implementing the It thing should be easy enough ;p
Also not a pissing contest at all imo, competition and discussing ideas is a good thing.
David Heffernan The order issue is actually in the order of the Args array passed in TInterceptBeforeNotify and TVirtualInterfaceInvokeEvent not being consistent on 32bit.
...context?
ReplyDeleteMason Wheeler If you used any mocking library in Delphi you would know. None (that I know of) can do argument matching (except writing your own code in the execute delegate that you can specify in most libs). So in this case the mock will be good whenever it is called having the string parameter contain 'hello' regardless the other arguments.
ReplyDeleteYes!!!!!!
ReplyDeleteMeh. I always figured mockery is something that belongs in interpersonal conversation, particularly before an audience, not code. ;)
ReplyDeleteStefan Glienke mORMot allows mocking with simple parameter matching since years. See http://synopse.info/files/html/api-1.18/mORMot.html#TINTERFACESTUB_RETURNS
ReplyDeleteBut your syntax is nice.
A. Bouchez Hm, I don't see which of your overloads lets you define a partial match for the method parameters. Match all or none have been in DSharp mocks and I think Delphi Mocks also supports it.
ReplyDeleteDelphi Mocks will have this soon, we have been working on it. The biggest issue we had was the order of parameter passing is not defined in delphi (64bit seems to be consistent, 32bit not).. so it's not as neat as we had hope. - eg:
ReplyDeletemockCredit.Setup
.WillReturn(6)
.When
.TakesTwoParams(It(0).IsEqualTo(1), It(1).IsEqualTo(true));
See the f-param-matches branch on github.
BTW, we had hope to just use It.XXX without the param index but the parameter passing order forced use to provide the index.
ReplyDeleteJust joining in on David Heffernan's pissing contest ;)
ReplyDeleteIt's sitting in a PR awaiting feedback/comments before we merge : https://github.com/VSoftTechnologies/Delphi-Mocks/pull/64
ReplyDeleteVincent Parrett Parameter passing orders are pretty clear. What's not defined is the order of evaluation of arguments. That's never been defined.
ReplyDeleteVincent Parrett Personally I am not sure if this Moq inspired API works so well in Delphi because of the poor type inference.
ReplyDeleteWhat I like about this way though is that you don't have to pass any dummy values that make the statement look ambiguous. With the way I took though you can write statements like this (if that is ever useful is another story ^^):
When((Args[0] = 1) or (Args[1] = 'Hello'))
Maybe I can make them both work. Implementing the It thing should be easy enough ;p
Also not a pissing contest at all imo, competition and discussing ideas is a good thing.
I guess I'll have to take a look a look at your implementation, it's not clear from your example, where does Args[] come from?
ReplyDeleteOurs is not as clean as we had hoped because the delphi language is lacking so many features that moq relies on.
David Heffernan The order issue is actually in the order of the Args array passed in TInterceptBeforeNotify and TVirtualInterfaceInvokeEvent not being consistent on 32bit.
ReplyDeleteActually David Heffernan you are correct it's the order of evaluation that was causing us problems (Jason just reminded me).
ReplyDeleteStefan Glienke Allow me being off-topic, but I've just recently explored the awesomeness of your excellent DSharp :)
ReplyDeleteI'm glad to see that it knows the correct answer but what was the question again? :-)
ReplyDeleteVincent Parrett Args is a const of a record type that has a default array property.
ReplyDelete