Skip to content

Commit 1400626

Browse files
committed
Fix formatting
1 parent 00da4df commit 1400626

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

core/codegen/src/attribute/catch/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn _catch(
8383
name: stringify!(#user_catcher_fn_name),
8484
code: #status_code,
8585
handler: monomorphized_function,
86-
route_type: #_Box::new(self),
86+
catcher_type: #_Box::new(self),
8787
}
8888
}
8989

core/lib/src/local/asynchronous/client.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22

33
use parking_lot::RwLock;
44

5-
use crate::{Rocket, Phase, Orbit, Ignite, Error};
5+
use crate::{Rocket, Phase, Orbit, Ignite, Error, Build};
66
use crate::local::asynchronous::{LocalRequest, LocalResponse};
77
use crate::http::{Method, uri::Origin, private::cookie};
88

@@ -76,6 +76,21 @@ impl Client {
7676
})
7777
}
7878

79+
// WARNING: This is unstable! Do not use this method outside of Rocket!
80+
// This is used by the `Client` doctests.
81+
#[doc(hidden)]
82+
pub fn _test_with<M, T, F>(mods: M, f: F) -> T
83+
where F: FnOnce(&Self, LocalRequest<'_>, LocalResponse<'_>) -> T + Send,
84+
M: FnOnce(Rocket<Build>) -> Rocket<Build>
85+
{
86+
crate::async_test(async {
87+
let client = Client::debug(mods(crate::build())).await.unwrap();
88+
let request = client.get("/");
89+
let response = request.clone().dispatch().await;
90+
f(&client, request, response)
91+
})
92+
}
93+
7994
#[inline(always)]
8095
pub(crate) fn _rocket(&self) -> &Rocket<Orbit> {
8196
&self.rocket

core/lib/src/local/blocking/client.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22
use std::cell::RefCell;
33

4-
use crate::{Rocket, Phase, Orbit, Ignite, Error};
4+
use crate::{Rocket, Phase, Orbit, Ignite, Error, Build};
55
use crate::local::{asynchronous, blocking::{LocalRequest, LocalResponse}};
66
use crate::http::{Method, uri::Origin};
77

@@ -54,6 +54,19 @@ impl Client {
5454
f(&client, request, response)
5555
}
5656

57+
// WARNING: This is unstable! Do not use this method outside of Rocket!
58+
// This is used by the `Client` doctests.
59+
#[doc(hidden)]
60+
pub fn _test_with<M, T, F>(mods: M, f: F) -> T
61+
where F: FnOnce(&Self, LocalRequest<'_>, LocalResponse<'_>) -> T + Send,
62+
M: FnOnce(Rocket<Build>) -> Rocket<Build>
63+
{
64+
let client = Client::debug(mods(crate::build())).unwrap();
65+
let request = client.get("/");
66+
let response = request.clone().dispatch();
67+
f(&client, request, response)
68+
}
69+
5770
#[inline(always)]
5871
pub(crate) fn inner(&self) -> &asynchronous::Client {
5972
self.inner.as_ref().expect("internal invariant broken: self.inner is Some")

core/lib/src/local/response.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ macro_rules! pub_response_impl {
186186
/// # Example
187187
///
188188
/// ```rust
189-
/// # use rocket::get;
189+
/// # use rocket::{get, routes};
190190
/// #[get("/")]
191191
/// fn index() -> &'static str { "Hello World" }
192192
#[doc = $doc_prelude]
193-
/// # Client::_test(|_, _, response| {
193+
/// # Client::_test_with(|r| r.mount("/", routes![index]), |_, _, response| {
194194
/// let response: LocalResponse = response;
195-
/// assert!(response.routed_by::<index>())
195+
/// assert!(response.routed_by::<index>());
196196
/// # });
197197
/// ```
198198
///
@@ -214,13 +214,13 @@ macro_rules! pub_response_impl {
214214
/// # Example
215215
///
216216
/// ```rust
217-
/// # use rocket::get;
217+
/// # use rocket::{catch, catchers};
218218
/// #[catch(404)]
219219
/// fn default_404() -> &'static str { "Hello World" }
220220
#[doc = $doc_prelude]
221-
/// # Client::_test(|_, _, response| {
221+
/// # Client::_test_with(|r| r.register("/", catchers![default_404]), |_, _, response| {
222222
/// let response: LocalResponse = response;
223-
/// assert!(response.caught_by::<default_404>())
223+
/// assert!(response.caught_by::<default_404>());
224224
/// # });
225225
/// ```
226226
///

examples/hello/src/tests.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ fn hello() {
3030

3131
let uri = format!("/?{}{}{}", q("lang", lang), q("emoji", emoji), q("name", name));
3232
let response = client.get(uri).dispatch();
33-
assert!(response.routed_by::<super::hello>(), "Response was not generated by the `hello` route");
33+
assert!(
34+
response.routed_by::<super::hello>(),
35+
"Response was not generated by the `hello` route"
36+
);
3437
assert_eq!(response.into_string().unwrap(), expected);
3538

3639
let uri = format!("/?{}{}{}", q("emoji", emoji), q("name", name), q("lang", lang));
3740
let response = client.get(uri).dispatch();
38-
assert!(response.routed_by::<super::hello>(), "Response was not generated by the `hello` route");
41+
assert!(
42+
response.routed_by::<super::hello>(),
43+
"Response was not generated by the `hello` route"
44+
);
3945
assert_eq!(response.into_string().unwrap(), expected);
4046
}
4147
}
@@ -44,7 +50,10 @@ fn hello() {
4450
fn hello_world() {
4551
let client = Client::tracked(super::rocket()).unwrap();
4652
let response = client.get("/hello/world").dispatch();
47-
assert!(response.routed_by::<super::world>(), "Response was not generated by the `world` route");
53+
assert!(
54+
response.routed_by::<super::world>(),
55+
"Response was not generated by the `world` route"
56+
);
4857
assert_eq!(response.into_string(), Some("Hello, world!".into()));
4958
}
5059

@@ -64,13 +73,19 @@ fn wave() {
6473
let real_name = RawStr::new(name).percent_decode_lossy();
6574
let expected = format!("👋 Hello, {} year old named {}!", age, real_name);
6675
let response = client.get(uri).dispatch();
67-
assert!(response.routed_by::<super::wave>(), "Response was not generated by the `wave` route");
76+
assert!(
77+
response.routed_by::<super::wave>(),
78+
"Response was not generated by the `wave` route"
79+
);
6880
assert_eq!(response.into_string().unwrap(), expected);
6981

7082
for bad_age in &["1000", "-1", "bird", "?"] {
7183
let bad_uri = format!("/wave/{}/{}", name, bad_age);
7284
let response = client.get(bad_uri).dispatch();
73-
assert!(response.caught_by::<rocket::catcher::DefaultCatcher>(), "Response was not generated by the default catcher");
85+
assert!(
86+
response.caught_by::<rocket::catcher::DefaultCatcher>(),
87+
"Response was not generated by the default catcher"
88+
);
7489
assert_eq!(response.status(), Status::NotFound);
7590
}
7691
}

0 commit comments

Comments
 (0)