Skip to content

Commit

Permalink
Mutate && to || and vice versa, and to == and != (#173)
Browse files Browse the repository at this point in the history
Part of #73
  • Loading branch information
sourcefrog authored Dec 4, 2023
2 parents 0c46315 + d7e9149 commit a077a80
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 25 deletions.
12 changes: 5 additions & 7 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

## Unreleased

- Changed: If no mutants are generated then `cargo mutants` now exits successfully, showing a warning. (Previously it would exit with an error.) This works better with `--in-diff` in CI, where it's normal that some changes may not have any mutants.

## 23.11.2

A big internal refactor to allow mutations smaller than a whole function. Only one pattern is added in this release, mutation of `==` operators, but many more are possible.

- New: Mutate `==` to `!=` and vice versa.

- New: Mutate `&&` to `||` and vice versa, and mutate both of them to `==` and `!=`.

- Changed: If no mutants are generated then `cargo mutants` now exits successfully, showing a warning. (Previously it would exit with an error.) This works better with `--in-diff` in CI, where it's normal that some changes may not have any mutants.

- Changed: Include column numbers in text listings of mutants and output to disambiguate smaller-than-function mutants, for example if there are several operators that can be changed on one line. This also applies to the names used for regex matching, so may break some regexps that match the entire line (sorry). The new option `--line-col=false` turns them both off in `--list` output.

- Changed: Replaced the `function`, `line`, and `return_type` fields in the mutants json message with a `function` submessage (including the name and return type) and a `span` indicating the entire replaced region.
- Changed: In the mutants.json format, replaced the `function`, `line`, and `return_type` fields with a `function` submessage (including the name and return type) and a `span` indicating the entire replaced region, to better handle smaller-than-function mutants. Also, the `function` includes the line-column span of the entire function.

## 23.11.2

Expand All @@ -26,8 +26,6 @@ A big internal refactor to allow mutations smaller than a whole function. Only o

- Added: Accept `--manifest-path` as an alternative to `-d`, for consistency with other cargo commands.

- Changed: The json mutants format now includes a `function` sub-message, which includes the function name and return type, rather than them being direct attributes of the mutant, to better accomodate smaller-than-function mutants. Also, the `function` includes the line-column span of the entire function.

## 23.11.1

- New `--in-diff FILE` option tests only mutants that are in the diff from the
Expand Down
13 changes: 9 additions & 4 deletions book/src/mutants.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ although they can be shown with `--unviable`.
Binary operators are replaced with other binary operators in expressions
like `a == 0`.

| Operator | Replacements | Description |
| -------- | ------------ | ----------- |
| `==` | `!=` | Equality |
| `!=` | `==` | Equality |
| Operator | Replacements |
| -------- | ------------------ |
| `==` | `!=` |
| `!=` | `==` |
| `&&` | `\|\|`, `==`, `!=` |
| `\|\|` | `&&`, `==`, `!=` |

Equality operators are not currently replaced with comparisons like `<` or `<=`
because they are
too prone to generate false positives, for example when unsigned integers are compared to 0.

Logical `&&` and `||` are replaced with `==` and `!=` which function as XNOR and XOR respectively,
although they are fairly often unviable due to needing parenthesis when the original operator does not.
Loading

0 comments on commit a077a80

Please sign in to comment.