Skip to content

Commit ae0e532

Browse files
ririsoftjbr
authored andcommitted
enable clippy for tests
Clippy is valuable for tests too.
1 parent bc026d1 commit ae0e532

8 files changed

Lines changed: 21 additions & 25 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
rustc --version
8383
8484
- name: clippy
85-
run: cargo clippy -- -D warnings
85+
run: cargo clippy --tests --examples -- -D warnings
8686

8787
- name: fmt
8888
run: cargo fmt --all -- --check

examples/error_handling.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ async fn main() -> Result<()> {
1010

1111
app.middleware(After(|mut res: Response| async {
1212
if let Some(err) = res.downcast_error::<async_std::io::Error>() {
13-
match err.kind() {
14-
ErrorKind::NotFound => {
15-
let msg = err.to_string().to_owned();
16-
res.set_status(StatusCode::NotFound);
13+
if let ErrorKind::NotFound = err.kind() {
14+
let msg = err.to_string();
15+
res.set_status(StatusCode::NotFound);
1716

18-
// NOTE: You may want to avoid sending error messages in a production server.
19-
res.set_body(format!("Error: {}", msg));
20-
}
21-
_ => (), // Some default behavior if you like.
17+
// NOTE: You may want to avoid sending error messages in a production server.
18+
res.set_body(format!("Error: {}", msg));
2219
}
2320
}
2421
Ok(res)

examples/graphql.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ struct NewUser {
3030
}
3131

3232
impl NewUser {
33-
fn to_internal(self) -> User {
33+
fn into_internal(self) -> User {
3434
User {
3535
id: None,
36-
first_name: self.first_name.to_owned(),
36+
first_name: self.first_name,
3737
}
3838
}
3939
}
@@ -51,7 +51,7 @@ impl QueryRoot {
5151
#[graphql(description = "Get all Users")]
5252
fn users(context: &State) -> Vec<User> {
5353
let users = context.users.read().unwrap();
54-
users.iter().map(|u| u.clone()).collect()
54+
users.iter().cloned().collect()
5555
}
5656
}
5757

@@ -62,7 +62,7 @@ impl MutationRoot {
6262
#[graphql(description = "Add new user")]
6363
fn add_user(context: &State, user: NewUser) -> User {
6464
let mut users = context.users.write().unwrap();
65-
let mut user = user.to_internal();
65+
let mut user = user.into_internal();
6666
user.id = Some((users.len() + 1) as u16);
6767
users.push(user.clone());
6868
user

tests/chunked-encode-large.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::Duration;
66

77
use tide::Body;
88

9-
const TEXT: &'static str = concat![
9+
const TEXT: &str = concat![
1010
"Et provident reprehenderit accusamus dolores et voluptates sed quia. Repellendus odit porro ut et hic molestiae. Sit autem reiciendis animi fugiat deleniti vel iste. Laborum id odio ullam ut impedit dolores. Vel aperiam dolorem voluptatibus dignissimos maxime.",
1111
"Qui cumque autem debitis consequatur aliquam impedit id nostrum. Placeat error temporibus quos sed vel rerum. Fugit perferendis enim voluptatem rerum vitae dolor distinctio. Quia iusto ex enim voluptatum omnis. Nam et aperiam asperiores nesciunt eos magnam quidem et.",
1212
"Beatae et sit iure eum voluptatem accusantium quia optio. Tempora et rerum blanditiis repellendus qui est dolorem. Blanditiis deserunt qui dignissimos ad eligendi. Qui quia sequi et. Ipsa error quia quo ducimus et. Asperiores accusantium eius possimus dolore vitae iusto.",

tests/chunked-encode-small.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::Duration;
66

77
use tide::Body;
88

9-
const TEXT: &'static str = concat![
9+
const TEXT: &str = concat![
1010
"Eveniet delectus voluptatem in placeat modi. Qui nulla sunt aut non voluptas temporibus accusamus rem. Qui soluta nisi qui accusantium excepturi voluptatem. Ab rerum maiores neque ut expedita rem.",
1111
"Et neque praesentium eligendi quaerat consequatur asperiores dolorem. Pariatur tempore quidem animi consequuntur voluptatem quos. Porro quo ipsa quae suscipit. Doloribus est qui facilis ratione. Delectus ex perspiciatis ab alias et quisquam non est.",
1212
"Id dolorum distinctio distinctio quos est facilis commodi velit. Ex repudiandae aliquam eos voluptatum et. Provident qui molestiae molestiae nostrum voluptatum aperiam ut. Quis repellendus quidem mollitia aut recusandae laboriosam.",

tests/log.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod test_utils;
55

66
#[async_std::test]
77
async fn start_server_log() {
8-
let logger = logtest::start();
8+
let mut logger = logtest::start();
99

1010
let port = test_utils::find_port().await;
1111
let app = tide::new();
@@ -16,8 +16,7 @@ async fn start_server_log() {
1616
assert!(res.is_err());
1717

1818
let record = logger
19-
.filter(|rec| rec.args().starts_with("Server listening"))
20-
.next()
19+
.find(|rec| rec.args().starts_with("Server listening"))
2120
.unwrap();
2221
assert_eq!(
2322
record.args(),

tests/params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async fn test_missing_param() {
4343
#[async_std::test]
4444
async fn hello_world_parametrized() {
4545
async fn greet(req: tide::Request<()>) -> Result<Response> {
46-
let name = req.param("name").unwrap_or("nori".to_owned());
46+
let name = req.param("name").unwrap_or_else(|_| "nori".to_owned());
4747
let mut response = tide::Response::new(StatusCode::Ok);
4848
response.set_body(format!("{} says hello", name));
4949
Ok(response)

tests/response.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ async fn test_status() {
88
let mut resp = Response::new(StatusCode::NotFound);
99
resp.set_body("foo");
1010
assert_eq!(resp.status(), StatusCode::NotFound);
11-
let foo = resp.take_body().into_string().await.unwrap();
12-
assert_eq!(foo.as_bytes(), b"foo");
11+
let body = resp.take_body().into_string().await.unwrap();
12+
assert_eq!(body.as_bytes(), b"foo");
1313
}
1414

1515
#[async_std::test]
@@ -21,8 +21,8 @@ async fn byte_vec_content_type() {
2121
resp.set_body(Body::from_reader(Cursor::new("foo"), None));
2222

2323
assert_eq!(resp[headers::CONTENT_TYPE], mime::BYTE_STREAM.to_string());
24-
let foo = resp.take_body().into_bytes().await.unwrap();
25-
assert_eq!(foo, b"foo");
24+
let body = resp.take_body().into_bytes().await.unwrap();
25+
assert_eq!(body, b"foo");
2626
}
2727

2828
#[async_std::test]
@@ -31,8 +31,8 @@ async fn string_content_type() {
3131
resp.set_body("foo");
3232

3333
assert_eq!(resp[headers::CONTENT_TYPE], mime::PLAIN.to_string());
34-
let foo = resp.take_body().into_string().await.unwrap();
35-
assert_eq!(foo, "foo");
34+
let body = resp.take_body().into_string().await.unwrap();
35+
assert_eq!(body, "foo");
3636
}
3737

3838
#[async_std::test]

0 commit comments

Comments
 (0)