Skip to content
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

New type replacement HttpResponse actix #142

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# cargo-mutants changelog

## Unreleased

- Generate `HttpResponse::Ok().finish()` as a mutation of an Actix `HttpResponse`.

## 23.6.0

- Generate `Box::leak(Box::new(...))` as a mutation of functions returning
Expand Down
1 change: 1 addition & 0 deletions book/src/mutants.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ More mutation genres and patterns will be added in future releases.
| `Arc<T>` | `Arc::new(...)` |
| `[T; L]` | `[r; L]` for all replacements of T |
| `&T` | `&...` (all replacements for T) |
| `HttpResponse` | `HttpResponse::Ok().finish` |
| (any other) | `Default::default()` |

`...` in the mutation patterns indicates that the type is recursively mutated.
Expand Down
10 changes: 10 additions & 0 deletions src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ fn type_replacements(type_: &Type, error_exprs: &[Expr]) -> Vec<TokenStream> {
reps.extend(error_exprs.iter().map(|error_expr| {
quote! { Err(#error_expr) }
}));
} else if path_ends_with(path, "HttpResponse") {
reps.push(quote! { HttpResponse::Ok().finish() });
} else if let Some(boxed_type) = match_first_type_arg(path, "Box") {
reps.extend(
type_replacements(boxed_type, error_exprs)
Expand Down Expand Up @@ -801,6 +803,14 @@ mod test {
);
}

#[test]
fn http_response_replacement() {
assert_eq!(
replace(&parse_quote! { -> HttpResponse }, &[]),
&["HttpResponse::Ok().finish()"]
);
}

#[test]
fn option_usize_replacement() {
let reps = return_type_replacements(&parse_quote! { -> Option<usize> }, &[]);
Expand Down