| Title: | Mutation Testing |
|---|---|
| Description: | Measure quality of your tests. 'muttest' introduces small changes (mutations) to your code and runs your tests to check if they catch the changes. If they do, your tests are good. If not, your assertions are not specific enough. 'muttest' gives you percent score of how often your tests catch the changes. |
| Authors: | Jakub Sobolewski [aut, cre] |
| Maintainer: | Jakub Sobolewski <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-05-14 13:16:42 UTC |
| Source: | https://github.com/jakubsob/muttest |
Returns a ready-made list of operator() mutators covering common
arithmetic swaps: +/-, *//, ^/*, %%/*, %/%//.
arithmetic_operators()arithmetic_operators()
Use on any file that performs calculations. A surviving mutant from this
preset typically means an assertion checks a property of the result (sign,
order) rather than a specific value — replacing expect_gte() with
expect_equal() and a computed expected value usually kills it.
A list of operator() mutators.
vignette("mutators", package = "muttest") for the full operator table
and a worked example showing the direction-insensitive assertion pattern.
vignette("interpreting-results", package = "muttest") for how to
diagnose survivors and fix the underlying test weakness.
arithmetic_operators() ## Not run: plan <- muttest_plan( source_files = "R/stats.R", mutators = arithmetic_operators() ) muttest(plan, "tests/testthat") ## End(Not run)arithmetic_operators() ## Not run: plan <- muttest_plan( source_files = "R/stats.R", mutators = arithmetic_operators() ) muttest(plan, "tests/testthat") ## End(Not run)
Replaces a boolean constant (TRUE, FALSE, T, or F) with another one.
boolean_literal(from, to)boolean_literal(from, to)
from |
The literal to be replaced. One of |
to |
The literal to replace with. |
boolean_literal("TRUE", "FALSE") boolean_literal("FALSE", "TRUE") boolean_literal("T", "F") boolean_literal("F", "T")boolean_literal("TRUE", "FALSE") boolean_literal("FALSE", "TRUE") boolean_literal("T", "F") boolean_literal("F", "T")
Returns a ready-made list of boolean_literal() mutators covering all
canonical flips: TRUE/FALSE and T/F.
boolean_literals()boolean_literals()
Use on any file that passes or returns boolean flags. A surviving mutant from
this preset typically means a test checks a side effect of the flag (e.g.
the branch taken) rather than the flag value itself — adding
expect_true()/expect_false() on the return value kills it.
A list of boolean_literal() mutators.
vignette("mutators", package = "muttest") for the full mutator table.
vignette("interpreting-results", package = "muttest") for how to
diagnose survivors and fix the underlying test weakness.
boolean_literals() ## Not run: plan <- muttest_plan( source_files = "R/flags.R", mutators = boolean_literals() ) muttest(plan, "tests/testthat") ## End(Not run)boolean_literals() ## Not run: plan <- muttest_plan( source_files = "R/flags.R", mutators = boolean_literals() ) muttest(plan, "tests/testthat") ## End(Not run)
Replaces a function name in a call expression with another name.
Useful for swapping semantically related functions such as any/all,
min/max, or sum/prod.
call_name(from, to)call_name(from, to)
from |
The function name to replace. |
to |
The function name to replace with. |
call_name("any", "all") call_name("min", "max") call_name("sum", "prod")call_name("any", "all") call_name("min", "max") call_name("sum", "prod")
Returns a ready-made list of operator() mutators covering direction swaps
(</>, <=/>=, ==/!=) and boundary shifts (</<=, >/>=).
comparison_operators()comparison_operators()
Use on any file with threshold logic, range checks, or filter conditions. A surviving mutant from this preset means the exact boundary value implied by the operator was never passed to the function — adding a test at that boundary value kills it.
A list of operator() mutators.
vignette("mutators", package = "muttest") for the full operator table
and a worked example showing the missing boundary value pattern.
vignette("interpreting-results", package = "muttest") for how to
diagnose survivors and fix the underlying test weakness.
comparison_operators() ## Not run: plan <- muttest_plan( source_files = "R/shipping.R", mutators = comparison_operators() ) muttest(plan, "tests/testthat") ## End(Not run)comparison_operators() ## Not run: plan <- muttest_plan( source_files = "R/shipping.R", mutators = comparison_operators() ) muttest(plan, "tests/testthat") ## End(Not run)
Returns a ready-made list of negate_condition() and
remove_condition_negation() mutators covering both directions of condition
logic: wrapping a plain condition in !(...) and stripping ! from an
already-negated condition.
condition_mutations()condition_mutations()
Use on any file with non-trivial if/while conditions. Surviving mutants
mean the branch outcome was never tested with inputs that cross the boundary —
adding a test where the condition flips from TRUE to FALSE kills them.
A list of mutators.
vignette("mutators", package = "muttest") for the full mutator table.
vignette("interpreting-results", package = "muttest") for how to
diagnose survivors and fix the underlying test weakness.
condition_mutations() ## Not run: plan <- muttest_plan( source_files = "R/validation.R", mutators = condition_mutations() ) muttest(plan, "tests/testthat") ## End(Not run)condition_mutations() ## Not run: plan <- muttest_plan( source_files = "R/validation.R", mutators = condition_mutations() ) muttest(plan, "tests/testthat") ## End(Not run)
Extend this class to implement a custom copy strategy.
execute()
Copy project files according to the strategy
CopyStrategy$execute(original_dir)
original_dirThe original directory to copy from
planThe current test plan
The path to the temporary directory
clone()
The objects of this class are cloneable with this method.
CopyStrategy$clone(deep = FALSE)
deepWhether to make a deep clone.
Other CopyStrategy:
PackageCopyStrategy,
default_copy_strategy()
Create a default project copy strategy
default_copy_strategy(...)default_copy_strategy(...)
... |
Arguments passed to the |
A ?CopyStrategy object
Other CopyStrategy:
CopyStrategy,
PackageCopyStrategy
Create a default reporter
default_reporter(...)default_reporter(...)
... |
Arguments passed to the |
Other MutationReporter:
MutationReporter,
ProgressMutationReporter
Create a default run strategy
default_test_strategy(...)default_test_strategy(...)
... |
Arguments passed to the |
A ?TestStrategy object
Other TestStrategy:
FileTestStrategy,
FullTestStrategy,
TestStrategy
Produces one mutant per deletable statement, removing each x <- expr
assignment or standalone f(...) call from the source. Surviving mutants
reveal untested side effects or dead assignments.
delete_statement()delete_statement()
Function definitions (x <- function(...) { ... }) are left untouched to
avoid producing structurally broken mutants.
A Mutator object.
delete_statement()delete_statement()
This strategy tells if a mutant is caught by a test matching the source file name.
For example, if the source file name is foo.R, and there are test files named test-foo.R or test-bar.R,
only test-foo.R will be run.
This strategy should give faster results than ?FullTestStrategy, especially for big codebases,
but the score might be less accurate.
muttest::TestStrategy -> FileTestStrategy
new()
Initialize the FileTestStrategy
FileTestStrategy$new(
load_helpers = TRUE,
load_package = c("source", "none", "installed")
)load_helpersWhether to load test helpers
load_packageThe package loading strategy
execute()
Execute the test strategy
FileTestStrategy$execute(path, plan, reporter)
pathThe path to the test directory
planThe current mutation plan. See muttest_plan().
reporterThe reporter to use for test results
The test results
clone()
The objects of this class are cloneable with this method.
FileTestStrategy$clone(deep = FALSE)
deepWhether to make a deep clone.
Other TestStrategy:
FullTestStrategy,
TestStrategy,
default_test_strategy()
This test strategy tells if a mutant is caught by any test.
To get faster results, especially for big codebases, use ?FileTestStrategy instead.
muttest::TestStrategy -> FullTestStrategy
new()
Initialize
FullTestStrategy$new(
load_helpers = TRUE,
load_package = c("source", "none", "installed")
)load_helpersWhether to load test helpers
load_packageThe package loading strategy
execute()
Execute the test strategy
FullTestStrategy$execute(path, plan, reporter)
pathThe path to the test directory
planThe current mutation plan. See muttest_plan().
reporterThe reporter to use for test results
The test results
clone()
The objects of this class are cloneable with this method.
FullTestStrategy$clone(deep = FALSE)
deepWhether to make a deep clone.
Other TestStrategy:
FileTestStrategy,
TestStrategy,
default_test_strategy()
Replaces every simple subscript index in x[i] or x[[i]] with
x[i - 1L] / x[[i - 1L]]. Targets identifier and numeric literal indices;
complex expressions (e.g. x[a + b]) are left untouched.
index_decrement()index_decrement()
A Mutator object.
index_decrement()index_decrement()
Replaces every simple subscript index in x[i] or x[[i]] with
x[i + 1L] / x[[i + 1L]]. Targets identifier and numeric literal indices;
complex expressions (e.g. x[a + b]) are left untouched.
index_increment()index_increment()
Catches off-by-one errors where tests never verify the exact element retrieved from a vector or list.
A Mutator object.
index_increment()index_increment()
Returns a ready-made list of index_increment() and index_decrement()
mutators that shift every simple subscript index by 1.
index_mutations()index_mutations()
Use on any file that extracts elements from vectors or lists by position. Surviving mutants reveal off-by-one errors where tests only verify that something was extracted, not which element — asserting the exact value of the extracted element kills them.
A list of mutators.
vignette("mutators", package = "muttest") for the full mutator table.
vignette("interpreting-results", package = "muttest") for how to
diagnose survivors and fix the underlying test weakness.
index_mutations() ## Not run: plan <- muttest_plan( source_files = "R/selectors.R", mutators = index_mutations() ) muttest(plan, "tests/testthat") ## End(Not run)index_mutations() ## Not run: plan <- muttest_plan( source_files = "R/selectors.R", mutators = index_mutations() ) muttest(plan, "tests/testthat") ## End(Not run)
Returns a ready-made list of operator() mutators covering short-circuit
(&&/||) and vectorised (&/|) logical operator swaps.
logical_operators()logical_operators()
Use on any file with compound conditions (if (a && b)). A surviving mutant
from this preset typically means test inputs are symmetric — both flags
TRUE or both FALSE. Adding a test with one flag TRUE and the other
FALSE exposes the difference between && and || and kills the mutant.
A list of operator() mutators.
vignette("mutators", package = "muttest") for the full operator table
and a worked example showing the symmetric-input pattern.
vignette("interpreting-results", package = "muttest") for how to
diagnose survivors and fix the underlying test weakness.
logical_operators() ## Not run: plan <- muttest_plan( source_files = "R/access.R", mutators = logical_operators() ) muttest(plan, "tests/testthat") ## End(Not run)logical_operators() ## Not run: plan <- muttest_plan( source_files = "R/access.R", mutators = logical_operators() ) muttest(plan, "tests/testthat") ## End(Not run)
The job of a mutation reporter is to aggregate and display the results of mutation tests. It tracks each mutation attempt, reporting on whether the tests killed the mutation or the mutation survived.
test_reporterReporter to use for the testthat::test_dir function
outOutput destination for reporter messages
widthWidth of the console in characters
unicodeWhether Unicode output is supported
crayonWhether colored output is supported
rstudioWhether running in RStudio
hyperlinksWhether terminal hyperlinks are supported
current_filePath of the file currently being mutated
current_mutatorMutator currently being applied
planComplete mutation plan for the test run
resultsList of mutation test results, indexed by file path
current_scoreCurrent score of the mutation tests
error_messagesList of error messages from failed mutant runs
new()
Initialize a new reporter
MutationReporter$new(test_reporter = "silent", file = stdout())
test_reporterReporter to use for the testthat::test_dir function
fileOutput destination (default: stdout)
start_reporter()
Start reporter
MutationReporter$start_reporter(plan = NULL)
planThe complete mutation plan
temp_dirPath to the temporary directory for testing
start_file()
Start testing a file
MutationReporter$start_file(filename)
filenamePath to the file being mutated
start_mutator()
Start testing with a specific mutator
MutationReporter$start_mutator(mutator)
mutatorThe mutator being applied
add_result()
Add a mutation test result
MutationReporter$add_result( plan, killed, survived, errors, error = NULL, original_code = NULL, mutated_code = NULL )
planCurrent testing plan. See muttest_plan().
killedWhether the mutation was killed by tests
survivedNumber of survived mutations
errorsNumber of errors encountered
errorOptional error condition from a failed run
original_codeOriginal source lines before mutation
mutated_codeMutated source lines
update()
Update status (no-op in base class)
MutationReporter$update(force = FALSE)
forceIgnored
end_mutator()
End testing with current mutator
MutationReporter$end_mutator()
end_file()
End testing current file
MutationReporter$end_file()
end_reporter()
End reporter and show summary
MutationReporter$end_reporter()
get_score()
Get the current score
MutationReporter$get_score()
cat_tight()
Print a message to the output
MutationReporter$cat_tight(...)
...Message to print
cat_line()
Print a message to the output
MutationReporter$cat_line(...)
...Message to print
rule()
Print a message to the output with a rule
MutationReporter$rule(...)
...Message to print
clone()
The objects of this class are cloneable with this method.
MutationReporter$clone(deep = FALSE)
deepWhether to make a deep clone.
Other MutationReporter:
ProgressMutationReporter,
default_reporter()
Mutator
Mutator
Represents a single code mutation — a pattern to find and a replacement to
apply. Every mutator function (operator(), boolean_literal(), etc.)
returns an instance of this class.
fromThe token or operator to replace.
toThe replacement token or operator.
queryTree-sitter query used to locate candidate nodes.
match_fnOptional function(node_text) returning logical;
overrides the default node_text == from equality check.
replacement_fnOptional function(node_text) returning a string;
overrides the static to value as the replacement text.
mutate_fnOptional function(code) that fully replaces the
default mutation logic when set.
new()
Create a new Mutator.
Mutator$new( from, to, query, match_fn = NULL, replacement_fn = NULL, mutate_fn = NULL )
fromToken to replace.
toReplacement token.
queryTree-sitter query string.
match_fnOptional custom match function.
replacement_fnOptional custom replacement function.
mutate_fnOptional function(code) that fully overrides the
default mutation logic.
mutate()
Apply this mutator to a character vector of source lines.
Mutator$mutate(code)
codeCharacter vector of source lines.
A list of mutated code variants (one per match), or NULL if
the pattern was not found.
print()
Print a short summary of the mutator.
Mutator$print()
clone()
The objects of this class are cloneable with this method.
Mutator$clone(deep = FALSE)
deepWhether to make a deep clone.
Run a mutation test
muttest( plan, path = "tests/testthat", reporter = default_reporter(), test_strategy = default_test_strategy(), copy_strategy = default_copy_strategy(), workers = 1, timeout = 600 * 1000 )muttest( plan, path = "tests/testthat", reporter = default_reporter(), test_strategy = default_test_strategy(), copy_strategy = default_copy_strategy(), workers = 1, timeout = 600 * 1000 )
plan |
A mutation testing plan. See |
path |
Path to the test directory. |
reporter |
Reporter to use for mutation testing results. See |
test_strategy |
Strategy for running tests. See |
copy_strategy |
Strategy for copying the project. See |
workers |
Number of parallel workers. When greater than 1, mutants are tested
concurrently using |
timeout |
Per-mutant timeout in milliseconds. If a mutant's test run exceeds this
limit the daemon is interrupted and the result is recorded as an error.
Use |
An object of class muttest_result containing the overall mutation score.
Each mutant requires rerunning the tests. For large project it might be not feasible to test all mutants in one go. This function allows you to create a plan for selected source files and mutators.
muttest_plan(mutators, source_files = fs::dir_ls("R", regexp = ".[rR]$"))muttest_plan(mutators, source_files = fs::dir_ls("R", regexp = ".[rR]$"))
mutators |
A list of mutators to use. See |
source_files |
A vector of file paths to the source files. |
The plan is in a data frame format, where each row represents a mutant.
You can subset the plan before passing it to the muttest() function.
A data frame with the test plan. The data frame has the following columns:
filename: The name of the source file.
original_code: The original code of the source file.
mutated_code: The mutated code of the source file.
mutator: The mutator that was applied.
Replaces NA, NULL, or a typed NA constant (NA_real_, NA_integer_,
NA_complex_, NA_character_) with another value.
na_literal(from, to)na_literal(from, to)
from |
The literal to replace. One of |
to |
The replacement literal. |
In tree-sitter-r, NA and all typed NA variants share the same na node
type, while NULL has its own null node type. match_fn distinguishes
between them by comparing the literal text.
A Mutator object.
na_literal("NULL", "NA") na_literal("NA", "NULL") na_literal("NA", "NA_real_") na_literal("NA_real_", "NA")na_literal("NULL", "NA") na_literal("NA", "NULL") na_literal("NA", "NA_real_") na_literal("NA_real_", "NA")
Returns a ready-made list of na_literal() mutators covering common swaps
between NA, NULL, and the typed NA variants (NA_real_, NA_integer_,
NA_character_).
na_literals()na_literals()
Use on any file that handles missing values or nullable results. A surviving
mutant typically means tests never distinguish NA from NULL, or never
check which typed NA is returned — adding expect_true(is.na(x)) and
expect_equal(class(x), "numeric") style assertions kills it.
A list of na_literal() mutators.
vignette("mutators", package = "muttest") for the full mutator table.
vignette("interpreting-results", package = "muttest") for how to
diagnose survivors and fix the underlying test weakness.
na_literals() ## Not run: plan <- muttest_plan( source_files = "R/missing.R", mutators = na_literals() ) muttest(plan, "tests/testthat") ## End(Not run)na_literals() ## Not run: plan <- muttest_plan( source_files = "R/missing.R", mutators = na_literals() ) muttest(plan, "tests/testthat") ## End(Not run)
Wraps the condition expression of each matching statement in !(...).
For example, if (x > 0) becomes if (!(x > 0)).
negate_condition(statements = c("if", "while"))negate_condition(statements = c("if", "while"))
statements |
Character vector of statement types to target.
Must be a subset of |
A Mutator object.
negate_condition() negate_condition(statements = "if")negate_condition() negate_condition(statements = "if")
Replaces every numeric literal n with n - by.
Handles both integer (e.g. 5L) and floating-point (e.g. 3.14) literals.
numeric_decrement(by = 1)numeric_decrement(by = 1)
by |
The amount to subtract. Defaults to |
A Mutator object.
numeric_decrement() numeric_decrement(by = 2)numeric_decrement() numeric_decrement(by = 2)
Replaces every numeric literal n with n + by.
Handles both integer (e.g. 5L) and floating-point (e.g. 3.14) literals.
numeric_increment(by = 1)numeric_increment(by = 1)
by |
The amount to add. Defaults to |
A Mutator object.
numeric_increment() numeric_increment(by = 2)numeric_increment() numeric_increment(by = 2)
Returns a ready-made list of numeric_increment() and numeric_decrement()
mutators that shift every numeric literal by 1.
numeric_literals()numeric_literals()
Use on any file with numeric constants used as thresholds, counts, or offsets. A surviving mutant means tests never verify the exact value of the constant — asserting the precise numeric result rather than a property (e.g. sign) kills it.
A list of mutators.
vignette("mutators", package = "muttest") for the full mutator table.
vignette("interpreting-results", package = "muttest") for how to
diagnose survivors and fix the underlying test weakness.
numeric_literals() ## Not run: plan <- muttest_plan( source_files = "R/thresholds.R", mutators = numeric_literals() ) muttest(plan, "tests/testthat") ## End(Not run)numeric_literals() ## Not run: plan <- muttest_plan( source_files = "R/thresholds.R", mutators = numeric_literals() ) muttest(plan, "tests/testthat") ## End(Not run)
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.
operator(from, to)operator(from, to)
from |
The operator to replace (e.g. |
to |
The replacement operator. |
Use this when you need a specific swap not covered by the preset collections
(arithmetic_operators(), comparison_operators(), logical_operators()).
A Mutator object.
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.
operator("+", "-") operator("==", "!=") operator(">", ">=") # probe the strict vs. non-strict boundaryoperator("+", "-") operator("==", "!=") operator(">", ">=") # probe the strict vs. non-strict boundary
It copies all files and directories from the original directory to a temporary directory.
muttest::CopyStrategy -> PackageCopyStrategy
execute()
Copy project files, excluding hidden and temp directories
PackageCopyStrategy$execute(original_dir, plan)
original_dirThe original directory to copy from
planThe current test plan
The path to the temporary directory
clone()
The objects of this class are cloneable with this method.
PackageCopyStrategy$clone(deep = FALSE)
deepWhether to make a deep clone.
Other CopyStrategy:
CopyStrategy,
default_copy_strategy()
A reporter that displays a progress indicator for mutation tests. It provides real-time feedback on which mutants are being tested and whether they were killed by tests.
muttest::MutationReporter -> ProgressMutationReporter
start_timeTime when testing started (for duration calculation)
min_timeMinimum test duration to display timing information
col_configList of column configuration for report formatting
survived_detailControls how survived mutants are reported (summary, none)
survived_mutantsList to store details of survived mutants for summary reporting
format_column()
Format a column with specified padding and width
ProgressMutationReporter$format_column(text, col_name, colorize = NULL)
textText to format
col_nameColumn name to use configuration from
colorizeOptional function to color the text
fmt_h()
Format the header of the report
ProgressMutationReporter$fmt_h()
fmt_r()
Format a row of the report
ProgressMutationReporter$fmt_r(status, k, s, e, t, score, mutator, file)
statusStatus symbol (e.g., tick or cross)
kNumber of killed mutations
sNumber of survived mutations
eNumber of errors
tTotal number of mutations
scoreScore percentage
mutatorThe mutator used
fileThe file being tested
Formatted row string
new()
Initialize a new progress reporter
ProgressMutationReporter$new(
test_reporter = "silent",
min_time = 1,
file = stdout(),
survived_detail = c("summary", "none")
)test_reporterReporter to use for testthat::test_dir
min_timeMinimum time to show elapsed time (default: 1s)
fileOutput destination (default: stdout)
survived_detailControls how survived mutants are reported.
One of "summary" (default) or "none".
start_reporter()
Start reporter
ProgressMutationReporter$start_reporter(plan = NULL)
planThe complete mutation plan
add_result()
Add a mutation test result
ProgressMutationReporter$add_result( plan, killed, survived, errors, error = NULL, original_code = NULL, mutated_code = NULL )
planCurrent testing plan. See muttest_plan().
killedWhether the mutation was killed by tests
survivedNumber of survived mutations
errorsNumber of errors encountered
errorOptional error condition from a failed run
original_codeOriginal source lines before mutation
mutated_codeMutated source lines
update()
Update status spinner (for long-running operations)
ProgressMutationReporter$update(force = FALSE)
forceForce update even if interval hasn't elapsed
end_file()
End testing current file
ProgressMutationReporter$end_file()
cr()
Carriage return if dynamic, newline otherwise
ProgressMutationReporter$cr()
end_reporter()
End reporter with detailed summary
ProgressMutationReporter$end_reporter()
print()
Print the mutation test result with survived diffs
ProgressMutationReporter$print()
clone()
The objects of this class are cloneable with this method.
ProgressMutationReporter$clone(deep = FALSE)
deepWhether to make a deep clone.
Other MutationReporter:
MutationReporter,
default_reporter()
The inverse of negate_condition(). Strips the leading ! from any
already-negated condition, so if (!done) becomes if (done) and
while (!ready) becomes while (ready).
remove_condition_negation(statements = c("if", "while"))remove_condition_negation(statements = c("if", "while"))
statements |
Character vector of statement types to target.
Must be a subset of |
Unlike remove_negation(), this mutator is scoped exclusively to
conditions, leaving negations in other positions (assignments, return
values, etc.) untouched.
A Mutator object.
remove_condition_negation() remove_condition_negation(statements = "while")remove_condition_negation() remove_condition_negation(statements = "while")
Removes the ! unary operator from an expression.
For example, !is.na(x) becomes is.na(x) and !(a > b) becomes (a > b).
remove_negation()remove_negation()
A Mutator object.
remove_negation()remove_negation()
Replaces the argument of every return(expr) with a fixed value (default
"NULL"). Tests that only check that a function returns something without
asserting the value will not kill these mutants.
replace_return_value(replacement = "NULL")replace_return_value(replacement = "NULL")
replacement |
Raw R source text to substitute as the return value.
Defaults to |
Only explicit return() calls are targeted. Implicit returns (the last
expression of a function body) are not affected.
A Mutator object.
replace_return_value() replace_return_value("NA")replace_return_value() replace_return_value("NA")
Replaces any non-empty string literal in the source code with "".
The empty string itself is not mutated (use string_fill() for that).
string_empty()string_empty()
A Mutator object.
string_empty()string_empty()
Replaces "" with a fill string (default "mutant") so that code paths
that depend on an empty string can be detected.
string_fill(fill = "mutant")string_fill(fill = "mutant")
fill |
The replacement string. Defaults to |
A Mutator object.
string_fill() string_fill(fill = "PLACEHOLDER")string_fill() string_fill(fill = "PLACEHOLDER")
Returns a ready-made list of string_empty() and string_fill() mutators
covering both directions: collapsing non-empty strings to "" and filling
empty strings with a placeholder.
string_literals()string_literals()
Use on any file where string values are passed to downstream logic or returned to callers. Surviving mutants reveal tests that only check type or length — asserting the exact string content kills them.
A list of mutators.
vignette("mutators", package = "muttest") for the full mutator table.
vignette("interpreting-results", package = "muttest") for how to
diagnose survivors and fix the underlying test weakness.
string_literals() ## Not run: plan <- muttest_plan( source_files = "R/labels.R", mutators = string_literals() ) muttest(plan, "tests/testthat") ## End(Not run)string_literals() ## Not run: plan <- muttest_plan( source_files = "R/labels.R", mutators = string_literals() ) muttest(plan, "tests/testthat") ## End(Not run)
Extend this class to implement a custom test strategy.
execute()
Execute the test strategy
TestStrategy$execute(path, plan, reporter)
pathThe path to the test directory
planThe current mutation plan. See muttest_plan().
reporterThe reporter to use for test results
The test result
clone()
The objects of this class are cloneable with this method.
TestStrategy$clone(deep = FALSE)
deepWhether to make a deep clone.
Other TestStrategy:
FileTestStrategy,
FullTestStrategy,
default_test_strategy()