Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to Filer, assert about generated files #58

Open
JakeWharton opened this issue Dec 4, 2014 · 3 comments
Open

Access to Filer, assert about generated files #58

JakeWharton opened this issue Dec 4, 2014 · 3 comments
Labels

Comments

@JakeWharton
Copy link
Contributor

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.

@JakeWharton
Copy link
Contributor Author

I ended up writing my own based on JavacPathFileManager and Jimfs. Do with this as you please.

@gk5885
Copy link
Contributor

gk5885 commented 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 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.

@stephanenicolas
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants