Skip to content

Commit

Permalink
Include trait names in namespace stack
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Nov 30, 2023
1 parent 247672d commit acaf517
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ src/visit.rs: replace <impl Visit for DiscoveryVisitor<'_>>::visit_trait_item_fn
src/visit.rs: replace == with != in <impl Visit for DiscoveryVisitor<'_>>::visit_trait_item_fn
src/visit.rs: replace <impl Visit for DiscoveryVisitor<'_>>::visit_item_impl with ()
src/visit.rs: replace == with != in <impl Visit for DiscoveryVisitor<'_>>::visit_item_impl
src/visit.rs: replace <impl Visit for DiscoveryVisitor<'_>>::visit_item_trait with ()
src/visit.rs: replace <impl Visit for DiscoveryVisitor<'_>>::visit_item_mod with ()
src/visit.rs: replace <impl Visit for DiscoveryVisitor<'_>>::visit_expr_binary with ()
src/visit.rs: replace function_body_span -> Option<Span> with None
Expand Down
10 changes: 10 additions & 0 deletions src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ impl<'ast> Visit<'ast> for DiscoveryVisitor<'_> {
self.in_namespace(&name, |v| syn::visit::visit_item_impl(v, i));
}

/// Visit `trait Foo { ... }`
fn visit_item_trait(&mut self, i: &'ast syn::ItemTrait) {
let name = i.ident.to_pretty_string();
let _span = trace_span!("trait", line = i.span().start().line, name).entered();
if attrs_excluded(&i.attrs) {
return;
}
self.in_namespace(&name, |v| syn::visit::visit_item_trait(v, i));
}

/// Visit `mod foo { ... }` or `mod foo;`.
fn visit_item_mod(&mut self, node: &'ast syn::ItemMod) {
let mod_name = &node.ident.unraw().to_string();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3793,7 +3793,7 @@ expression: buf
{
"file": "src/traits.rs",
"function": {
"function_name": "is_three",
"function_name": "Something::is_three",
"return_type": "-> bool",
"span": {
"end": {
Expand Down Expand Up @@ -3823,7 +3823,7 @@ expression: buf
{
"file": "src/traits.rs",
"function": {
"function_name": "is_three",
"function_name": "Something::is_three",
"return_type": "-> bool",
"span": {
"end": {
Expand Down Expand Up @@ -3853,7 +3853,7 @@ expression: buf
{
"file": "src/traits.rs",
"function": {
"function_name": "is_three",
"function_name": "Something::is_three",
"return_type": "-> bool",
"span": {
"end": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ src/slices.rs:13:5: replace return_mut_slice -> &mut[usize] with Vec::leak(vec![
src/static_item.rs:1:33: replace == with !=
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 0
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 1
src/traits.rs:5:9: replace is_three -> bool with true
src/traits.rs:5:9: replace is_three -> bool with false
src/traits.rs:5:11: replace == with != in is_three
src/traits.rs:5:9: replace Something::is_three -> bool with true
src/traits.rs:5:9: replace Something::is_three -> bool with false
src/traits.rs:5:11: replace == with != in Something::is_three
```
## testdata/with_child_directories
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/snapshots/cli__list_mutants_json_well_tested.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ expression: "String::from_utf8_lossy(&output.stdout)"
{
"file": "src/traits.rs",
"function": {
"function_name": "is_three",
"function_name": "Something::is_three",
"return_type": "-> bool",
"span": {
"end": {
Expand Down Expand Up @@ -1313,7 +1313,7 @@ expression: "String::from_utf8_lossy(&output.stdout)"
{
"file": "src/traits.rs",
"function": {
"function_name": "is_three",
"function_name": "Something::is_three",
"return_type": "-> bool",
"span": {
"end": {
Expand Down Expand Up @@ -1343,7 +1343,7 @@ expression: "String::from_utf8_lossy(&output.stdout)"
{
"file": "src/traits.rs",
"function": {
"function_name": "is_three",
"function_name": "Something::is_three",
"return_type": "-> bool",
"span": {
"end": {
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/snapshots/cli__list_mutants_well_tested.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ src/slices.rs:13:5: replace return_mut_slice -> &mut[usize] with Vec::leak(vec![
src/static_item.rs:1:33: replace == with !=
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 0
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 1
src/traits.rs:5:9: replace is_three -> bool with true
src/traits.rs:5:9: replace is_three -> bool with false
src/traits.rs:5:11: replace == with != in is_three
src/traits.rs:5:9: replace Something::is_three -> bool with true
src/traits.rs:5:9: replace Something::is_three -> bool with false
src/traits.rs:5:11: replace == with != in Something::is_three

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ src/slices.rs:13:5: replace return_mut_slice -> &mut[usize] with Vec::leak(vec![
src/static_item.rs:1:33: replace == with !=
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 0
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 1
src/traits.rs:5:9: replace is_three -> bool with true
src/traits.rs:5:9: replace is_three -> bool with false
src/traits.rs:5:11: replace == with != in is_three
src/traits.rs:5:9: replace Something::is_three -> bool with true
src/traits.rs:5:9: replace Something::is_three -> bool with false
src/traits.rs:5:11: replace == with != in Something::is_three

6 changes: 3 additions & 3 deletions tests/cli/snapshots/cli__well_tested_tree_check_only.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ src/slices.rs:13:5: replace return_mut_slice -> &mut[usize] with Vec::leak(vec![
src/static_item.rs:1:33: replace == with != ... ok
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 0 ... ok
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 1 ... ok
src/traits.rs:5:9: replace is_three -> bool with true ... ok
src/traits.rs:5:9: replace is_three -> bool with false ... ok
src/traits.rs:5:11: replace == with != in is_three ... ok
src/traits.rs:5:9: replace Something::is_three -> bool with true ... ok
src/traits.rs:5:9: replace Something::is_three -> bool with false ... ok
src/traits.rs:5:11: replace == with != in Something::is_three ... ok
46 mutants tested: 46 succeeded

Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ src/slices.rs:13:5: replace return_mut_slice -> &mut[usize] with Vec::leak(vec![
src/static_item.rs:1:33: replace == with != ... caught
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 0 ... caught
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 1 ... caught
src/traits.rs:5:9: replace is_three -> bool with true ... caught
src/traits.rs:5:9: replace is_three -> bool with false ... caught
src/traits.rs:5:11: replace == with != in is_three ... caught
src/traits.rs:5:9: replace Something::is_three -> bool with true ... caught
src/traits.rs:5:9: replace Something::is_three -> bool with false ... caught
src/traits.rs:5:11: replace == with != in Something::is_three ... caught
46 mutants tested: 46 caught

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ src/slices.rs:13:5: replace return_mut_slice -> &mut[usize] with Vec::leak(vec![
src/static_item.rs:1:33: replace == with !=
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 0
src/struct_with_lifetime.rs:15:9: replace Lex<'buf>::buf_len -> usize with 1
src/traits.rs:5:9: replace is_three -> bool with true
src/traits.rs:5:9: replace is_three -> bool with false
src/traits.rs:5:11: replace == with != in is_three
src/traits.rs:5:9: replace Something::is_three -> bool with true
src/traits.rs:5:9: replace Something::is_three -> bool with false
src/traits.rs:5:11: replace == with != in Something::is_three

0 comments on commit acaf517

Please sign in to comment.