You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Access to the Filer is trivial to add to CompilationRule. What I can't figure out is how to propagate the generated content back to the test to assert on the generated sources. At the very least it would require a change to Compilation to inject the InMemoryJavaFileManager so it could also be made available to the test but that brings other dependencies with it. Perhaps Compilation should be more stateful than just static helpers?
I'm not doing any actual compilation. I want to only test interactions with a Filer and assert on its outputs.
Happy to implement, just want guidance/approval on the approach.
Yes, that's totally the right way to go. If you are just testing the filer, make a fake filer - getting the one from CompilationRule is a little weird anyway since that's all part of a fake compilation that actually encloses the test. If you're on 1.7+, JavacPathFileManager and Jimfs are definitely preferred to my semi-hacky implementation.
do you have a working example of this ? I don't only want to compile the generated code, I would also like to execute it (load it into memory, even if by reflection).
Follows up #70
Activity
JakeWharton commentedon Dec 17, 2014
I ended up writing my own based on
JavacPathFileManagerand Jimfs. Do with this as you please.gk5885 commentedon Dec 17, 2014
Yes, that's totally the right way to go. If you are just testing the filer, make a fake filer - getting the one from
CompilationRuleis a little weird anyway since that's all part of a fake compilation that actually encloses the test. If you're on 1.7+,JavacPathFileManagerand Jimfs are definitely preferred to my semi-hacky implementation.stephanenicolas commentedon Jun 2, 2015
Hi @JakeWharton and @gk5885 ,
do you have a working example of this ? I don't only want to compile the generated code, I would also like to execute it (load it into memory, even if by reflection).
Follows up #70