<div class="gmail_quote">On Thu, Sep 1, 2011 at 3:36 PM, Dave Elcock <span dir="ltr"><<a href="mailto:dave.elcock@gmail.com">dave.elcock@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello.<br>
<br>
I've recently discovered Clang and I've come up with the hair-brained<br>
idea of playing/hacking with it to achieve something akin to<br>
HippoMocks (<a href="http://www.hippomocks.com/wiki/" target="_blank">http://www.hippomocks.com/wiki/</a>), essentially using an<br>
abstract class as a template, and generating stubs and implementations<br>
for pure virtual methods on-the-fly.<br>
<br>
I'm imagining writing some sort of extension that could modify vtables<br>
etc, but be inserted into Clang with a command line switch a la LLVM's<br>
transformation passes. I reckon I need to do that before it gets as<br>
far as LLVM itself, just so there is richer type information still<br>
around.<br>
<br>
Before I go wasting any more time, is this just plain bonkers? Is it<br>
going to be possible as an external modification, or am I going to be<br>
stuck with a hacked clang executable/libs?</blockquote><div><br></div><div>I'm not quite sure why you're approaching this problem from the direction you are. Why not generate *source code* for the mocks instead of trying to synthesize generated code for them based on the original code?</div>
<div><br></div><div>For reference, GoogleMock (which you should look at if you haven't) creates mock interfaces very easily. The complexity is exactly bounded by the size of the mocked interface, without regard for the complexity of implementation. There is even a (somewhat hacky) python script to generate the mock source code from an existing class.</div>
<div><br></div><div>I could imagine writing a Clang-based tool that examined an AST to generate the mock instead of using Python. It would be less hacky and handle horrible corner cases of the language better. I'm fairly confident that the existing libraries etc in Clang are sufficient to do this.</div>
<div><br></div><div>That said, I work at Google and we have a lot of experience using GoogleMock. I don't recall ever hearing an engineer using it and complaining that the hacky python script couldn't generate their mock. Most users I talked to didn't even know that the python script existed, because they never really needed it. The mock is so easy to implement, they just did it. :: shrug :: I guess in my experience this is not the hard part about mocks and using them in testing. maybe HippoMocks need this type of functionality more.</div>
<div><br></div><div>Anyways, if you want to talk more about the Clang tool for this, by all means carry on. =D Happy to help there. If you want talk more about mocking frameworks etc, or why this tool would be useful or not, feel free to email me off-list, or mail the GoogleMock list.</div>
</div>