Rocket
Rocket copied to clipboard
Route tracing
Adds support for testing which route generated a response. This is an implementation of the ideas I put forward in #1878, with a few minor changes. First, I did not create a macro, since my implementation works just fine with a generic type parameter. Writing a macro is pretty trivial, if it's desired. I also added tests to the hello world example to demonstrate what the actual tests look like.
There are a few improvements that could be made:
- [x] The methods added to
LocalResponse
(routed_by
,caught_by
andwas_caught
) could probably have better names. - [x] The Request object could (in testing mode) track which routes were attempted, and some basic information about the result. This should be pretty trivial to add, although it may require more that just the route's
TypeId
to actually use this to produce meaningful information.
The only regression I see is that Catcher
now has a private member, so other crates cannot directly construct a Catcher
, but I think this is acceptable, since it should probably be constructed with the constructor as before.
It looks like the issue with Windows Debug is a memory or hard drive error.
Indeed, we're running out of disk space. Let's disregard it for now.
I think I've reached an API I'm pretty happy with. Since the type tracking is done internally, this could be extended to support listing the routes attempted in order, but I don't think that's necessary for this PR. I'm also happy enough with the syntax presented here, I don't feel the need to introduce a new assert macro. @SergioBenitez, this PR is ready for a review, whenever you get a chance.
I've rebased on the latest master and push to your fork so that I can review.