-
Notifications
You must be signed in to change notification settings - Fork 69
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
Sequence: output on failure identifying which calls were missed #241
Comments
Would it be useful if the panic message said something like |
Yeah, I think such a message would be appreciated. That being said, it's rather hard to tell which is the 3rd or 5th — e.g., in my case, some of them are added by helper methods. Capturing names of the functions as part of the mock macro and then including those as well may help, and I think that would be not too much extra from an implementation perspective. Ideally, what would really be nice — and I recognize there are implementation challenges here — would be to print the ordered function names in a list, so I can visually see which were skipped too. |
After doing #246 , I realize that it wouldn't be too hard to print the offending method's name and arguments when a Sequence violation occurs. I'm going to try that next. |
I think that would definitely be a welcome feature! |
Print the method name and argument values during a method sequence violation. Argument values require the "nightly" feature, and the arguments must implement Debug. Fixes #241
Hi!
Today was my first experience with
Sequence
. I set up aSequence
with five operations, and in the process had a mismatch between my test and the module under test -- the implementation invoked two functions twice, rather than each only once as the test expected. The result was:Through traversing the call stack, I found the invocation of a mocked function which caused the panic, and from there with a bit of reasoning I was able to diagnose the root cause. I had a good amount of trouble discerning what went wrong, since it wasn't clear without looking at the implementation what the two values being asserted were, it was hard to tell whether something was being called too many times or too few, and I wasn't sure what had already been called vs. what was skipped.
Ideally, it would be nice to get an error message printed before the panic which told me where we were in the sequence (including which method was just called!), which calls had correctly occurred, and which ones hadn't correctly (or yet) occurred.
Firstly, is there any interest in this? Is there something else I should be seeing or doing here instead?
I'd be up for giving some improvements a shot in the next few days, if that's welcome and warranted. Is there a straightforward way to implement a more thorough readout without too large a change?
Looking at the way that
Sequence
s are implemented, I must admit, it's quite elegant! Unfortunately, there just isn't a lot of context to go off of. I think if we wanted fully detailed panic messages, there would likely need to be a Vec of call metadata or similar stored in the sequence, to allow it to report on context upon validation failure. Probably wrapped in a mutex. Was this intentionally avoided? It looks like there's no heap allocation at all required in the current implementation, which makes me wonder whether there were perf or other goals here.The text was updated successfully, but these errors were encountered: