-
Notifications
You must be signed in to change notification settings - Fork 1
Impl custom golden paths #3
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
base: trunk
Are you sure you want to change the base?
Impl custom golden paths #3
Conversation
Implement a new macro case for each assertion and the _new_goldie macros. This path extends the current _function_path return value. What this achieves is custom named files in the same place golden tests would be previously written to.
@rossmacarthur Could we get this looked at by any chance? I dont mind making changes if it is in-appropriate for what you want in the lib |
Hi @aVikingTrex, thanks for your contribution. I'm not convinced this is the best API for this. If I understand correctly, your use-case is that you want a suffix to the name of the golden file. I can imagine other ways of customizing the paths and I want to make sure that we implement the suffix in a way that allows for other options without too much API churn. Examples:
Additionally, I would prefer if we had as little macro code as possible. The macros are only required in order to get the Idea:
Let me know what you think, or if you have ideas? |
Appreciate the reply @rossmacarthur. When I wrote this I had the very narrow use case of interop between this and the test-case crate. Re-reading #2 and the OP's issue, I do see that configuring in a more customised way would be the way to go. In that issue is two use cases although I wonder if OP's issue is better served as the crate's default rather than an opt-in config. I agree that a better long term solution would be expanding out the goldie struct itself. Personally I can see it being configured via builder, which looks to be what you have in your example. It would be trivially implemented via Bon but this comes at the cost of compile time macros, and it might be too heavy for such a simple use case. I am also happy to hand-write the builder for this. From your examples and what I want out of the crate I could see:
I can see it being used similar to how you have there with the difference being that new_goldie!() would return a GoldieBuilder rather than a Goldie struct: goldie::new_goldie()
.with_suffix("")
.with_prefix("")
.with_golden_dir("", RelativeTo::Test)
.with_separate_module_dirs()
.assert() What do you think about this? |
@rossmacarthur just waiting on you to give your thoughts before I implement |
This PR implements custom names for golden files. The crux of this change is the addition of a new macro case branch per assert for handling the new name.
The provided name is postfixed to the path produced by the current _function_path macro in place of the actual function name.
New tests have also been written for these new cases. This should resolve #2