Skip to contents

Produces one mutant per occurrence of from in the source file, replacing it with to. A surviving mutant means your tests cannot distinguish the original operator from the replacement — pointing at the missing assertion or input value.

Usage

operator(from, to)

Arguments

from

The operator to replace (e.g. "+", "==", ">").

to

The replacement operator.

Value

A Mutator object.

Details

Use this when you need a specific swap not covered by the preset collections (arithmetic_operators(), comparison_operators(), logical_operators()).

See also

comparison_operators(), arithmetic_operators(), logical_operators() for ready-made preset lists.

vignette("mutators", package = "muttest") for the full operator reference with examples of what each preset catches.

vignette("interpreting-results", package = "muttest") to learn how to read surviving mutants and strengthen the tests they expose.

Examples

operator("+", "-")
#> Mutator: + → -
#> Query: (binary_operator
#>       lhs: (_) @lhs
#>       operator: _ @operator
#>       rhs: (_) @rhs
#>       (#eq? @operator "+")
#>     )
operator("==", "!=")
#> Mutator: == → !=
#> Query: (binary_operator
#>       lhs: (_) @lhs
#>       operator: _ @operator
#>       rhs: (_) @rhs
#>       (#eq? @operator "==")
#>     )
operator(">", ">=")  # probe the strict vs. non-strict boundary
#> Mutator: > → >=
#> Query: (binary_operator
#>       lhs: (_) @lhs
#>       operator: _ @operator
#>       rhs: (_) @rhs
#>       (#eq? @operator ">")
#>     )