From 4aed71e20f125156b80b892813c4b4469148922a Mon Sep 17 00:00:00 2001 From: Denis Rangel Date: Sat, 2 Sep 2023 09:39:17 -0300 Subject: [PATCH 1/2] new type replacement HttpResponse actix --- src/visit.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/visit.rs b/src/visit.rs index e867aec3..64c76793 100644 --- a/src/visit.rs +++ b/src/visit.rs @@ -360,6 +360,8 @@ fn type_replacements(type_: &Type, error_exprs: &[Expr]) -> Vec { 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) @@ -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 }, &[]); From 24c491b54d3c61fe5da214643fd2e92451a3029d Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 13 Sep 2023 21:28:02 -0600 Subject: [PATCH 2/2] News and docs about HttpResponse mutation --- NEWS.md | 4 ++++ book/src/mutants.md | 1 + 2 files changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index daf57fd4..9c3d87f5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/book/src/mutants.md b/book/src/mutants.md index 7fac9d3e..ada5cfce 100644 --- a/book/src/mutants.md +++ b/book/src/mutants.md @@ -32,6 +32,7 @@ More mutation genres and patterns will be added in future releases. | `Arc` | `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.