Arid rules
A mutant your tests miss asks for a test. Some ask for one nobody should write: a removed log line, a list’s starting size. mutastic skips those on its own, as arid, and each skip names its rule and links to its section here. This page has a section for each rule: what it skips, why, what it can hide, when to bring it back, and the setting that does, ready to copy. Why mutastic skips any of them, and what it costs, is in Arid mutants.
Every rule is on by default:
| Rule | What it skips |
|---|---|
Trivial accessorsmutastic:trivial-accessorsJava | A getter or setter that only reads or writes one of its class’s fields. |
Debug representationsmutastic:debug-representationsJava, Rust | toString() and hashCode(), the lambdas they define and the helpers only they call; in Rust, a Debug or a Hash impl. |
Outputmutastic:outputJava, Rust, Swift | Code that only writes output: a log line, or text printed to the console, and a value worked out for nothing else. |
Messagesmutastic:messagesJava, Rust, Swift | The text of an exception’s or an error’s message, or of a failed check’s. |
Failed assertsmutastic:failed-assertsJava | The throw of an assert that fails. |
Capacitymutastic:capacityJava, Rust, Swift | The room a collection or a buffer starts with or makes, and how full a hash table gets before it grows, while it stays above zero. |
Wait timesmutastic:wait-timesJava, Rust | How long a sleep waits, where the time goes only into the sleep. A timeout’s, a deadline’s or a backoff’s stays counted. |
Waitsmutastic:waitsJava, Rust | A sleep removed: Thread.sleep or TimeUnit.sleep in Java, thread::sleep or an awaited sleep in Rust. |
Null checksmutastic:null-checksJava, Rust | A call that only checks a value is there, its result unused, removed: Objects.requireNonNull(x) or x.getClass() in Java, x.unwrap() or x.expect(…) in Rust. |
Array sizesmutastic:array-sizesJava | The size of a new array, written as a number. |
Split limitsmutastic:split-limitsJava | The limit of a String.split. |
Thread namesmutastic:thread-namesJava, Rust | A thread’s or a pool’s name, which only people and their tools read: a thread dump, a profiler, a log pattern. |
Thread prioritiesmutastic:thread-prioritiesJava | A thread’s priority from 1 to 10: a hint, which Linux ignores by default and a virtual thread always does. |
Keep alivemutastic:keep-aliveJava, Rust | How long a pool’s idle threads live before they stop, while it stays above zero. |
Stack sizesmutastic:stack-sizesJava, Rust | The size of a thread’s stack, while it stays above zero. |
Gatherer sizesmutastic:gatherer-sizesJava | How many calls Gatherers.mapConcurrent runs at once, while it stays above zero. |
C resultsmutastic:c-resultsRust, Swift | A check that a C call succeeded, where failing only stops the program: the comparison of the call’s result, or of a name the statement just before sets to it, with a constant. No test can make the C library fail there. |
The Rust edition has fewer rules because it never changes what’s inside a macro’s arguments. Log
lines, println! and format! text, the messages of assert!, panic! and expect, and
debug_assert! never produce a mutant there, so there’s nothing to skip and no rule is needed.
The table lists each rule as the edition ships it, and grows as rules are added; each section says
what the Rust edition does with that code.
The Swift edition has four rules: output, messages, capacity and C results. Its sections say
what it skips and show what mutastic explain says of each, on the samples/arid package in
mutastic for Swift’s repository. MUTASTIC_ARID=audit
runs the skipped mutants there too. Every other section says what the Swift edition does with that
code: it has no rule for it, so each mutant it makes there counts.
A skipped mutant is still made and keeps its id; it isn’t in the score, and the summary counts it
(3 skipped (3 arid)). To see what a rule hides in your code, run the mutants it skips with
MUTASTIC_ARID=audit (Java). To bring a rule back, cover the code that needs it with a mutate:
rule in mutastic.yaml, or @DoMutate on it, naming the rule, as each section shows. Without
arid:, either brings back every arid skip in the code it covers, whichever rule made it.
Each example below is a class in samples/arid, with a test that checks the behaviour the skip
could hide. Running the skipped mutants against those tests is how each What it can hide was
found:
MUTASTIC_ARID=audit mutastic run samples/arid --operators=allTrivial accessors
Section titled “Trivial accessors”Java prints arid: trivial getter of <field> or arid: trivial setter of <field>
The Rust edition has no such rule: see below.
The Swift edition has no such rule: see below.
Every mutant of a getter that only returns one of its class’s fields, or a setter that only stores
its argument in one, named for that field: getName, isActive, setName, a record-style name().
public String getName() { return name; }
public void setName(String name) { this.name = name; }Why: a test of a field read back is a test of the language. A getter named for the wrong field is a lint’s to find. An accessor with any logic in it, a copy, a check, lazy set-up, isn’t trivial, and its mutants count.
When to bring it back: the accessors are an API others call, and you test them through it.
rules: - mutate: com.example.arid.Customer arid: [mutastic:trivial-accessors] reason: a JSON library fills customers in through their setters@DoMutate(value = "a JSON library fills customers in through their setters", arid = "mutastic:trivial-accessors")public class Customer {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: trivial setter of name ┌─ src/main/java/com/example/arid/Customer.java:12 │ 11 │ public void setName(String name) { 12 │ this.name = name; │ ^^^^^^^^^^^^^^^^^ body removed 13 │ } │ = change setName() does nothing (not shown in the source) = operator mutastic/replace-body · https://docs.mutastic.io/java/operators/returns/#replace-body
reproduce mutastic run --only=mb008a64d samples/arid
= arid mutastic:trivial-accessors: A getter or setter that only reads or writes one of its class's fields. docs: https://docs.mutastic.io/reference/arid/#trivial-accessors to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Customer#setName arid: [mutastic:trivial-accessors] reason: <why a test should check it>In the Rust edition: a getter whose body only hands back a field (self.name, &self.name,
self.name.clone()) gets no whole-body mutant; nothing counts it, and no rule brings it back. Its
other mutants count.
In the Swift edition: no such rule. A stored property has no accessor of its own, and every mutant of a computed property counts.
Changed in: 0.1.0, the first release. 1.3.0: its id; mutate: and @DoMutate bring it back, by
its id.
Debug representations
Section titled “Debug representations”Java prints arid: toString() is a debug representation, arid: hashCode() may return any value consistent with equals(), arid: a lambda in <method>() or arid: <helper>() only serves <method>()
Rust prints arid: Debug::fmt is a debug representation or arid: Hash::hash may give any value consistent with Eq
The Swift edition has no such rule: see below.
Every mutant of toString() and hashCode(), of the lambdas they define, and of a private or
package-private helper that only they call.
@Override public String toString() { return "£" + pence / 100 + "." + String.format("%02d", pence % 100); }Why: toString() is usually for people debugging, and a test of it pins a format nobody
promised. hashCode() may return any value that agrees with equals(), so most changes to it are
still correct.
When to bring it back: the text is what someone reads, and your tests check it.
rules: - mutate: com.example.arid.Money#toString arid: [mutastic:debug-representations] reason: shown to customers on their receipts@DoMutate(value = "shown to customers on their receipts", arid = "mutastic:debug-representations")@Overridepublic String toString() {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: toString() is a debug representation ┌─ src/main/java/com/example/arid/Money.java:13 │ 12 │ public String toString() { 13 │ return "£" + pence / 100 + "." + String.format("%02d", pence % 100); │ ^ / changed to * 14 │ } │ = mutant - return "£" + pence / 100 + "." + String.format("%02d", pence % 100); + return "£" + pence * 100 + "." + String.format("%02d", pence % 100); = operator mutastic/math · https://docs.mutastic.io/java/operators/arithmetic/#math
reproduce mutastic run --only=ma68347d0 samples/arid
= arid mutastic:debug-representations: `toString()` and `hashCode()`, the lambdas they define and the helpers only they call; in Rust, a `Debug` or a `Hash` impl. docs: https://docs.mutastic.io/reference/arid/#debug-representations to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Money#toString arid: [mutastic:debug-representations] reason: <why a test should check it>In the Rust edition: every mutant of a Debug impl’s fmt and of a Hash impl’s hash,
its whole body replaced included. A Display impl counts: what it writes is often what people
read.
In the Swift edition: no such rule: a description or a hash(into:) counts like any other
code.
Changed in: 0.1.0, the first release. 1.3.0: its id; mutate: and @DoMutate bring it back, by
its id; in the Rust edition, a Debug or Hash impl’s mutants are made and skipped, and a
Display impl’s whole body counts.
Output
Section titled “Output”Java prints arid: only writes output, arid: only feeds a log line, arid: only decides whether output is written, arid: only calls <call> (<reason>), arid: only feeds <call> (<reason>), arid: only calls a method that only writes output or arid: only feeds a method that only writes output
Rust prints arid: only writes output, arid: only feeds a log line, arid: only decides whether output is written, arid: only calls <call> (<reason>), arid: only calls a function that only writes output or arid: only feeds a function that only writes output
Swift prints arid: only writes output, arid: only calls a function that only writes output or arid: only feeds a function that only writes output
A removed call to a logger, or a print to the console, System.out or System.err, a stack
trace’s e.printStackTrace() included; every other mutant of such a call; a string that only goes
into one, its format string included; a value worked out only for one, arid: only feeds a log line: log.info("took {} ms", now - start), or the same through a local that nothing else reads;
and a log level’s check around nothing but output, if (log.isDebugEnabled()) { log.debug(…); },
as arid: only decides whether output is written. A flag read for the same is too: a boolean
field, if (verbose), or a Kotlin property, if (Debug.verbose) println(s), when its getter only
gives the field and can’t be overridden. A getter that does more keeps the check counted. The
loggers are SLF4J, its fluent builder included (log.atInfo().log(…)), Logback, Log4j 2 and its
builder, Log4j 1, java.util.logging, System.Logger, Commons Logging, JBoss Logging,
kotlin-logging, Flogger and tinylog.
A call to a method of the code’s own that only writes output is too, arid: only calls a method that only writes output: logRequest(r), whose body is log.info("got {}", r), and Kotlin’s
log(s) { if (Debug.verbose) println(s) }; so is a value worked out only for such a call, arid: only feeds a method that only writes output. It’s decided by the method’s bytecode, never by its
name. The method returns nothing, and does nothing but write output as above, or call another
such method, with values worked out only for that; it stores no field, calls no other method of
the code’s, throws nothing, and has no loop, switch or try. The call can run no other method:
it’s static, private or super., the method or its class is final, or no class of the module
overrides it; a call through an interface counts. And what it’s given has no side effect: a
logSaved(next++) or a logSaved(fee(id)) counts.
public static void print(long total) { System.out.println("total: " + total); }Why: removing a log line changes what a person reads, not what the code does. A test that reads log text breaks the next time someone rewords it, and says nothing about the code.
When to bring it back: the output is what the code is for, and your tests read it.
rules: - mutate: com.example.arid.Totals arid: [mutastic:output] reason: the total is what the command prints, and scripts read it@DoMutate(value = "the total is what the command prints, and scripts read it", arid = "mutastic:output")public final class Totals {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only writes output ┌─ src/main/java/com/example/arid/Totals.java:8 │ 7 │ public static void print(long total) { 8 │ System.out.println("total: " + total); │ ^^^^^^^ call removed 9 │ } │ = mutant - System.out.println("total: " + total); = operator mutastic/remove-void-call · https://docs.mutastic.io/java/operators/calls/#remove-void-call
reproduce mutastic run --only=m3d96ab6c samples/arid
= arid mutastic:output: Code that only writes output: a log line, or text printed to the console, and a value worked out for nothing else. docs: https://docs.mutastic.io/reference/arid/#output to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Totals#print arid: [mutastic:output] reason: <why a test should check it>And of a call to a method that only writes output, said(total) in Totals.sum:
SKIPPED arid: only calls a method that only writes output ┌─ src/main/java/com/example/arid/Totals.java:17 │ 16 │ } 17 │ said(total); │ ^^^^ call removed 18 │ return total; │ = mutant - said(total); = operator mutastic/remove-void-call · https://docs.mutastic.io/java/operators/calls/#remove-void-call
reproduce mutastic run --only=mbb474626 samples/arid
= arid mutastic:output: Code that only writes output: a log line, or text printed to the console, and a value worked out for nothing else. docs: https://docs.mutastic.io/reference/arid/#output to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Totals#sum arid: [mutastic:output] reason: <why a test should check it>In the Rust edition: a removed output macro used as a statement (println!, eprintln!,
dbg!, and the log and tracing macros such as info!) is made and skipped with the same
reason, and a mutate: rule takes it back. A write! goes to a writer the code chose, which a test
may read, so it counts. Nothing inside a macro’s arguments gets a mutant, and a value a let
works out only for output macros to read, let took = a - b; info!("{took}");, is skipped as
arid: only feeds a log line, by syntax: every read of the name in the function is an output
macro’s argument, and no other binding has that name. An output: rule in mutastic.yaml names
a function or a macro of your own that only writes output, - output: crate::audit::record with a
reason:, and a statement that calls it is skipped under this rule too, as arid: only calls audit::record (…): see Your own output calls.
A statement that calls a function of the crate’s own whose body only writes output is skipped too,
arid: only calls a function that only writes output, and a change to a value it’s given, arid: only feeds a function that only writes output. It’s decided by the source: the function returns
(), isn’t async, unsafe or const, isn’t a trait’s method or in a trait’s impl, and each
statement of its body is an output macro, a let of a plain value, an if on one around only
those, or a call of another such function. It’s called by a path, or on self as an inherent
method, every function of the crate by that name qualifies and none is brought in by a use, and
each value it’s given has no side effect.
In the Swift edition: a call that only writes output, print, dump, NSLog, os_log or a
logger’s log method, is skipped as arid: only writes output: removing the call, and every change
to the code in its arguments. So is a call of the package’s own function whose body only writes
output, logSaved(id) where logSaved only prints, as arid: only calls a function that only writes output, and a change to what it’s given, as arid: only feeds a function that only writes output. That function gives back nothing, can’t throw, wait or be overridden, every function by its
name does only that, and the values it’s given have no side effect.
SKIPPED arid: only writes output ┌─ Sources/Arid/Orders.swift:6 │ 5 │ public func save(_ id: Int) -> Int { 6 │ print("saved order \(id + 1)") │ ^ + changed to - 7 │ return id │ = mutant - print("saved order \(id + 1)") + print("saved order \(id - 1)") = operator mutastic/math · https://docs.mutastic.io/swift/operators/arithmetic/#math
reproduce mutastic run --only=me02145d8 samples/arid
About this mutant ─────────────────────────────────────────────── = change print("saved order \(id + 1)") → print("saved order \(id - 1)") the code the switch puts in place of the original when this mutant is live = operator mutastic/math: `+` becomes `-` = arid mutastic:output: A call that only writes output, and the code in its arguments: `print`, `dump`, `NSLog`, `os_log`, or a logger's log method. docs: https://docs.mutastic.io/reference/arid/#output to run it, add to mutastic.yaml: rules: - mutate: Orders.save arid: [mutastic:output] reason: <why a test should check it> = id me02145d8: `m` and the first 8 hex digits of its fingerprint, e02145d8b31d66a7, a SHA-256 of the file, function, operator, site and change no line number goes in, so the id stays the same when code above it moves = site `print("saved order \(id + 1)")` in Orders.save, line 6, column 29: the function's site 1, counting from 1 in source order = last run none yet: `run` or `next` records oneChanged in: 0.1.0, the first release. 1.0.0: a string that only goes into output. 1.3.0: its id;
mutate: and @DoMutate bring it back, by its id; a format string followed by a value worked out
in the call (log.info("took {} ms", now - start)) is skipped as well; follows a value worked out
for a log call, in both editions; a print to a stream the code is given counts, more loggers’
calls are output, and so is a log level’s check around nothing else. 1.5.0: printStackTrace(), a
flag’s check around nothing but output, a Kotlin property’s included, and kotlinc’s println of a
string template; a call to a method of the code’s own that only writes output, in both editions.
Messages
Section titled “Messages”Java prints arid: only an exception's message or arid: only a failed check's message
Rust prints arid: only an error's message or arid: only a failed check's message
Swift prints arid: only a failed check's message
A string that’s only an exception’s message, or only the message of a failed check
(Objects.requireNonNull(x, "…"), Guava’s Preconditions). Mutants of strings come with
--operators=stronger.
if (amount < 0) { throw new IllegalArgumentException("amount must not be negative"); }Why: a test should check that the code refuses a bad value, and which exception it throws. Its words are for the person reading them, and a test that pins them breaks whenever they’re improved.
When to bring it back: the message is what users see, or what callers parse, and your tests check it.
rules: - mutate: com.example.arid.Amounts#parse arid: [mutastic:messages] reason: the message is shown on the form, word for word@DoMutate(value = "the message is shown on the form, word for word", arid = "mutastic:messages")public static long parse(String text) {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only an exception's message ┌─ src/main/java/com/example/arid/Amounts.java:10 │ 9 │ if (amount < 0) { 10 │ throw new IllegalArgumentException("amount must not be negative"); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "amount must not be negative" changed to "" 11 │ } │ = mutant - throw new IllegalArgumentException("amount must not be negative"); + throw new IllegalArgumentException(""); = operator mutastic/string-constant · https://docs.mutastic.io/java/operators/library/#string-constant
reproduce mutastic run --only=m1c99562f samples/arid
= arid mutastic:messages: The text of an exception's or an error's message, or of a failed check's. docs: https://docs.mutastic.io/reference/arid/#messages to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Amounts#parse arid: [mutastic:messages] reason: <why a test should check it>In the Rust edition: text given to Err, context, with_context or wrap_err (arid: only an error's message), or to expect (arid: only a failed check's message), straight or
through .into() or String::from. Anything inside a macro such as format! or panic! gets no
mutant; nothing counts it, and no rule brings it back.
In the Swift edition: the message of assert, precondition, assertionFailure,
preconditionFailure or fatalError, as arid: only a failed check's message. The check’s
condition counts.
SKIPPED arid: only a failed check's message ┌─ Sources/Arid/Totals.swift:7 │ 6 │ let sum = amounts.reduce(0, +) 7 │ precondition(sum >= 0, "a total of \(sum - 1)") │ ^ - changed to + 8 │ return sum │ = mutant - precondition(sum >= 0, "a total of \(sum - 1)") + precondition(sum >= 0, "a total of \(sum + 1)") = operator mutastic/math · https://docs.mutastic.io/swift/operators/arithmetic/#math
reproduce mutastic run --only=mf2d21a62 samples/arid
About this mutant ─────────────────────────────────────────────── = change precondition(sum >= 0, "a total of \(sum - 1)") → precondition(sum >= 0, "a total of \(sum + 1)") the code the switch puts in place of the original when this mutant is live = operator mutastic/math: `-` becomes `+` = arid mutastic:messages: The message of `assert`, `precondition`, `assertionFailure`, `preconditionFailure` or `fatalError`, which only a failed check reads. docs: https://docs.mutastic.io/reference/arid/#messages to run it, add to mutastic.yaml: rules: - mutate: Totals.total arid: [mutastic:messages] reason: <why a test should check it> = id mf2d21a62: `m` and the first 8 hex digits of its fingerprint, f2d21a628e25e5d5, a SHA-256 of the file, function, operator, site and change no line number goes in, so the id stays the same when code above it moves = site `precondition(sum >= 0, "a total of \(sum - 1)")` in Totals.total, line 7, column 46: the function's site 1, counting from 1 in source order = last run none yet: `run` or `next` records oneChanged in: 1.0.0, with mutastic/string-constant. 1.3.0: its id; mutate: and @DoMutate
bring it back, by its id. The Rust edition’s rule.
Failed asserts
Section titled “Failed asserts”Java prints arid: only says an assert failed
The Rust edition has no such rule: see below.
The Swift edition has no such rule: see below.
The throw of an assert that fails, removed. Comes with --operators=extended, which removes
throws.
public static long settle(long balance) { assert balance >= 0 : "negative balance"; return balance; }Why: an assert checks the code’s own assumptions while it’s tested, and is off in production
unless the JVM is started with -ea. A test that fails an assert tests the assert, not the code.
When to bring it back: your tests check the code’s invariants by expecting its asserts to fail.
rules: - mutate: com.example.arid.Ledger#settle arid: [mutastic:failed-asserts] reason: the tests check that a negative balance is refused@DoMutate(value = "the tests check that a negative balance is refused", arid = "mutastic:failed-asserts")public static long settle(long balance) {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only says an assert failed ┌─ src/main/java/com/example/arid/Ledger.java:8 │ 7 │ public static long settle(long balance) { 8 │ assert balance >= 0 : "negative balance"; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ throw removed 9 │ return balance; │ = change the throw of AssertionError is removed, so the code carries on (not shown in the source) = operator mutastic/remove-throw · https://docs.mutastic.io/java/operators/returns/#remove-throw
reproduce mutastic run --only=m9e76abb7 samples/arid
= arid mutastic:failed-asserts: The `throw` of an `assert` that fails. docs: https://docs.mutastic.io/reference/arid/#failed-asserts to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Ledger#settle arid: [mutastic:failed-asserts] reason: <why a test should check it>In the Rust edition: assert! and debug_assert! are macros, and nothing inside a macro gets a
mutant, so there’s nothing to skip.
In the Swift edition: no such rule: an assert’s or a precondition’s condition counts, and
only its message is skipped, under Messages.
Changed in: 1.0.0, with mutastic/remove-throw. 1.3.0: its id; mutate: and @DoMutate bring
it back, by its id.
Capacity
Section titled “Capacity”Java prints arid: only sizes a collection's first allocation or arid: only sets when a hash table grows
Rust prints arid: only sizes a collection's first allocation
Swift prints arid: only sizes a collection's first allocation
A number, or arithmetic, that goes only into the starting size of one of the JDK’s collections or
buffers: the int constructor of ArrayList, HashMap, HashSet, StringBuilder and the like,
their ensureCapacity, HashMap.newHashMap and its kin, or Guava’s sized factories such as
Lists.newArrayListWithExpectedSize. A hash table’s load factor, new HashMap<>(n, 0.75f), is
skipped too while it stays above zero, as arid: only sets when a hash table grows.
var pairs = new ArrayList<Integer>(values.size() * 2);Why: a collection grows as it needs to, so its starting size changes how often it grows, which is speed and memory, not what it holds.
When to bring it back: rarely: when a benchmark, not a unit test, checks the allocation.
rules: - mutate: com.example.arid.Pairs#doubled arid: [mutastic:capacity] reason: the allocation is checked by a benchmark that runs with the tests@DoMutate(value = "the allocation is checked by a benchmark that runs with the tests", arid = "mutastic:capacity")public static List<Integer> doubled(List<Integer> values) {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only sizes a collection's first allocation ┌─ src/main/java/com/example/arid/Pairs.java:11 │ 10 │ public static List<Integer> doubled(List<Integer> values) { 11 │ var pairs = new ArrayList<Integer>(values.size() * 2); │ ^ * changed to / 12 │ for (int value : values) { │ = mutant - var pairs = new ArrayList<Integer>(values.size() * 2); + var pairs = new ArrayList<Integer>(values.size() / 2); = operator mutastic/math · https://docs.mutastic.io/java/operators/arithmetic/#math
reproduce mutastic run --only=m06b94eb4 samples/arid
= arid mutastic:capacity: The room a collection or a buffer starts with or makes, and how full a hash table gets before it grows, while it stays above zero. docs: https://docs.mutastic.io/reference/arid/#capacity to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Pairs#doubled arid: [mutastic:capacity] reason: <why a test should check it>In the Rust edition: a number, or arithmetic, in with_capacity, the first argument of
with_capacity_and_hasher, reserve or reserve_exact.
In the Swift edition: the argument of reserveCapacity(_:), a minimumCapacity: or
Data(capacity:)’s, and the arithmetic in it. Removing a reserveCapacity call counts.
SKIPPED arid: only sizes a collection's first allocation ┌─ Sources/Arid/Names.swift:7 │ 6 │ var out: [String] = [] 7 │ out.reserveCapacity(names.count * 2) │ ^ * changed to / 8 │ for name in names { │ = mutant - out.reserveCapacity(names.count * 2) + out.reserveCapacity(names.count / 2) = operator mutastic/math · https://docs.mutastic.io/swift/operators/arithmetic/#math
reproduce mutastic run --only=m705900ae samples/arid
About this mutant ─────────────────────────────────────────────── = change out.reserveCapacity(names.count * 2) → out.reserveCapacity(names.count / 2) the code the switch puts in place of the original when this mutant is live = operator mutastic/math: `*` becomes `/` = arid mutastic:capacity: The room a collection or a buffer starts with or makes, and the arithmetic that works it out: `reserveCapacity(_:)`'s argument, a `minimumCapacity:` or `Data(capacity:)`'s. Removing the call itself is counted. docs: https://docs.mutastic.io/reference/arid/#capacity to run it, add to mutastic.yaml: rules: - mutate: Names.doubled arid: [mutastic:capacity] reason: <why a test should check it> = id m705900ae: `m` and the first 8 hex digits of its fingerprint, 705900aec0f983d0, a SHA-256 of the file, function, operator, site and change no line number goes in, so the id stays the same when code above it moves = site `out.reserveCapacity(names.count * 2)` in Names.doubled, line 7, column 37: the function's site 1, counting from 1 in source order = last run none yet: `run` or `next` records oneChanged in: 0.4.0. 1.3.0: its id; mutate: and @DoMutate bring it back, by its id; a number
in the arithmetic, the JDK’s and Guava’s sized factories, and a load factor are skipped, and a
number made negative counts; the Rust edition’s rule.
Wait times
Section titled “Wait times”Java prints arid: only sets how long to wait
Rust prints arid: only sets how long to wait
The Swift edition has no such rule: see below.
A number, or arithmetic, that goes only into how long Thread.sleep or TimeUnit.sleep waits,
straight in or through Duration.ofSeconds and the like, or TimeUnit.toMillis. A time limit
isn’t one: a timeout given to Future.get, a join with a time limit, or a time stored for a later
retry decides what the code does next, and counts. So does a number made negative for
Thread.sleep(long), which throws for it.
for (var message : messages) { reader.accept(message); Thread.sleep(pauseTenths * 100L); }Why: how long a sleep waits changes when the code gets somewhere, not where it goes, and a test that depends on the length of a wait is slow and flaky.
When to bring it back: the length of the pause is part of what the code promises, and your tests measure it, or use a clock they control.
rules: - mutate: com.example.arid.Pacer#send arid: [mutastic:wait-times] reason: the reader needs a tenth of a second between messages@DoMutate(value = "the reader needs a tenth of a second between messages", arid = "mutastic:wait-times")public static int send(List<String> messages, Consumer<String> reader, int pauseTenths)Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only sets how long to wait ┌─ src/main/java/com/example/arid/Pacer.java:14 │ 13 │ reader.accept(message); 14 │ Thread.sleep(pauseTenths * 100L); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one value kept 15 │ } │ = change pauseTenths * 100 becomes pauseTenths (not shown in the source) = operator mutastic/keep-operand · https://docs.mutastic.io/java/operators/arithmetic/#keep-operand
reproduce mutastic run --only=m5fa09958 samples/arid
= arid mutastic:wait-times: How long a sleep waits, where the time goes only into the sleep. A timeout's, a deadline's or a backoff's stays counted. docs: https://docs.mutastic.io/reference/arid/#wait-times to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Pacer#send arid: [mutastic:wait-times] reason: <why a test should check it>In the Rust edition: a number, or arithmetic, that goes into a sleep, straight or through
Duration::from_secs, from_millis, from_micros, from_nanos or Duration::new. A Duration
given to anything else, a timeout, counts.
In the Swift edition: no such rule.
Changed in: 0.4.0. 1.3.0: its id; mutate: and @DoMutate bring it back, by its id; only a
sleep’s time, followed through arithmetic and conversions, and a join’s time limit counts; the
Rust edition’s rule.
Java prints arid: only waits
Rust prints arid: only waits
The Swift edition has no such rule: see below.
A removed Thread.sleep or TimeUnit.sleep. A removed join isn’t one, with a time limit or
without: without it, the code can read what the other thread does before it’s done, and that’s a
race worth a test.
while (!ready.getAsBoolean()) { Thread.sleep(pauseMillis); tries++; }Why: without a sleep the code does the same work, sooner, and a test that would notice is a test of the clock: slow, and flaky on a busy machine.
When to bring it back: the pause is part of what the code promises, and your tests measure it, or use a clock they control.
rules: - mutate: com.example.arid.Backoff#poll arid: [mutastic:waits] reason: the service it polls limits how often it's asked@DoMutate(value = "the service it polls limits how often it's asked", arid = "mutastic:waits")public static int poll(BooleanSupplier ready, long pauseMillis) throws InterruptedException {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only waits ┌─ src/main/java/com/example/arid/Backoff.java:12 │ 11 │ while (!ready.getAsBoolean()) { 12 │ Thread.sleep(pauseMillis); │ ^^^^^ call removed 13 │ tries++; │ = mutant - Thread.sleep(pauseMillis); = operator mutastic/remove-void-call · https://docs.mutastic.io/java/operators/calls/#remove-void-call
reproduce mutastic run --only=m4474cbf8 samples/arid
= arid mutastic:waits: A sleep removed: `Thread.sleep` or `TimeUnit.sleep` in Java, `thread::sleep` or an awaited `sleep` in Rust. docs: https://docs.mutastic.io/reference/arid/#waits to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Backoff#poll arid: [mutastic:waits] reason: <why a test should check it>In the Rust edition: a removed thread::sleep(d);, or an awaited sleep(d).await; such as
tokio’s. A removed handle.join().unwrap(); counts.
In the Swift edition: no such rule.
Changed in: 0.4.0. 1.3.0: its id; mutate: and @DoMutate bring it back, by its id; a removed
join with a time limit counts, as one with none always did; the Rust edition’s rule.
Null checks
Section titled “Null checks”Java prints arid: only checks the value isn't null
Rust prints arid: only checks the value is there
The Swift edition has no such rule: see below.
A removed call whose only job is to check a value is there, its result unused:
Objects.requireNonNull(x), or x.getClass(), which javac writes for the same check.
public void add(String order) { Objects.requireNonNull(order); orders.add(order); }Why: without the check, code given null fails a little later, or goes on with it, and the
check is usually there to fail early on a null no caller passes.
When to bring it back: refusing null is part of what the code promises, and your tests pass
it null.
rules: - mutate: com.example.arid.Orders#add arid: [mutastic:null-checks] reason: callers rely on add refusing null straight away@DoMutate(value = "callers rely on add refusing null straight away", arid = "mutastic:null-checks")public void add(String order) {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only checks the value isn't null ┌─ src/main/java/com/example/arid/Orders.java:12 │ 11 │ public void add(String order) { 12 │ Objects.requireNonNull(order); │ ^^^^^^^^^^^^^^ call removed 13 │ orders.add(order); │ = mutant - Objects.requireNonNull(order); = operator mutastic/remove-discarded-call · https://docs.mutastic.io/java/operators/calls/#remove-discarded-call
reproduce mutastic run --only=m3b47b4da samples/arid
= arid mutastic:null-checks: A call that only checks a value is there, its result unused, removed: `Objects.requireNonNull(x)` or `x.getClass()` in Java, `x.unwrap()` or `x.expect(…)` in Rust. docs: https://docs.mutastic.io/reference/arid/#null-checks to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Orders#add arid: [mutastic:null-checks] reason: <why a test should check it>In the Rust edition: a removed x.unwrap(); or x.expect(…); on a value the code is given,
where only the check is thrown away, is skipped as arid: only checks the value is there, and a
mutate: rule takes it back. A check on what a call returns, handle.join().unwrap();, is removed
with its call, and counts.
In the Swift edition: no such rule.
Changed in: 1.0.0, with mutastic/remove-discarded-call. 1.3.0: its id; mutate: can name
it; the Rust edition’s rule.
Array sizes
Section titled “Array sizes”Java prints arid: only sizes an array
The Rust edition has no such rule: see below.
The Swift edition has no such rule: see below.
A number that only sizes a new array. Mutants of numbers come with --operators=stronger.
int[] counts = new int[7];Why: most arrays are sized for the work, a buffer of 8192 bytes, and a different size changes
how much is read at once, not what is read.
When to bring it back: the array’s length is part of what the code returns.
rules: - mutate: com.example.arid.Week#perDay arid: [mutastic:array-sizes] reason: callers read one count for each day of the week@DoMutate(value = "callers read one count for each day of the week", arid = "mutastic:array-sizes")public static int[] perDay(int[] days) {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only sizes an array ┌─ src/main/java/com/example/arid/Week.java:8 │ 7 │ public static int[] perDay(int[] days) { 8 │ int[] counts = new int[7]; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^ 7 changed to 8 9 │ for (int day : days) { │ = mutant - int[] counts = new int[7]; + int[] counts = new int[8]; = operator mutastic/constant-value · https://docs.mutastic.io/java/operators/arithmetic/#constant-value
reproduce mutastic run --only=m32a8834e samples/arid
= arid mutastic:array-sizes: The size of a new array, written as a number. docs: https://docs.mutastic.io/reference/arid/#array-sizes to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Week#perDay arid: [mutastic:array-sizes] reason: <why a test should check it>In the Rust edition: no such rule.
In the Swift edition: no such rule.
Changed in: 1.0.0, with mutastic/constant-value. 1.3.0: its id; mutate: and @DoMutate
bring it back, by its id.
Split limits
Section titled “Split limits”Java prints arid: only limits a split
The Rust edition has no such rule: see below.
The Swift edition has no such rule: see below.
The limit given to String.split. Mutants of numbers come with --operators=stronger.
return line.split(":", 2)[1].strip();Why: for most text the limit is never reached, and a different one splits it the same way.
When to bring it back: the text you split can contain the separator, and your tests have such text.
rules: - mutate: com.example.arid.Headers#value arid: [mutastic:split-limits] reason: a header's value can have colons of its own@DoMutate(value = "a header's value can have colons of its own", arid = "mutastic:split-limits")public static String value(String line) {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only limits a split ┌─ src/main/java/com/example/arid/Headers.java:8 │ 7 │ public static String value(String line) { 8 │ return line.split(":", 2)[1].strip(); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 changed to 3 9 │ } │ = mutant - return line.split(":", 2)[1].strip(); + return line.split(":", 3)[1].strip(); = operator mutastic/constant-value · https://docs.mutastic.io/java/operators/arithmetic/#constant-value
reproduce mutastic run --only=m34ba4295 samples/arid
= arid mutastic:split-limits: The limit of a `String.split`. docs: https://docs.mutastic.io/reference/arid/#split-limits to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Headers#value arid: [mutastic:split-limits] reason: <why a test should check it>In the Rust edition: no such rule.
In the Swift edition: no such rule.
Changed in: 1.0.0, with mutastic/constant-value. 1.3.0: its id; mutate: and @DoMutate
bring it back, by its id.
Thread names
Section titled “Thread names”Java prints arid: only names a thread
Rust prints arid: only names a thread
The Swift edition has no such rule: see below.
A thread’s name: the name given to new Thread, setName, a Thread.Builder’s name and its
start index, Guava’s setNameFormat, and a value that only becomes part of a name, through
"worker-" + n or String.format.
var thread = new Thread(work, "report-worker");Why: nothing in the JVM acts on a thread’s name. It’s for people reading a thread dump, a profiler or a log line.
When to bring it back: something other than people relies on the names, and your tests check them.
rules: - mutate: com.example.arid.Workers#background arid: [mutastic:thread-names] reason: the server's health check finds its workers by name@DoMutate(value = "the server's health check finds its workers by name", arid = "mutastic:thread-names")public static Thread background(Runnable work) {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only names a thread ┌─ src/main/java/com/example/arid/Workers.java:12 │ 11 │ public static Thread background(Runnable work) { 12 │ var thread = new Thread(work, "report-worker"); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "report-worker" changed to "" 13 │ thread.setPriority(Thread.MIN_PRIORITY); │ = mutant - var thread = new Thread(work, "report-worker"); + var thread = new Thread(work, ""); = operator mutastic/string-constant · https://docs.mutastic.io/java/operators/library/#string-constant
reproduce mutastic run --only=m1db0b439 samples/arid
= arid mutastic:thread-names: A thread's or a pool's name, which only people and their tools read: a thread dump, a profiler, a log pattern. docs: https://docs.mutastic.io/reference/arid/#thread-names to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Workers#background arid: [mutastic:thread-names] reason: <why a test should check it>In the Rust edition: a name given to thread::Builder::name, or to tokio’s thread_name or
thread_name_fn, is skipped the same way, on a builder the code visibly starts from
thread::Builder::new() or tokio’s runtime Builder. A crate that reads a thread’s name keeps them.
In the Swift edition: no such rule.
Changed in: 1.3.0, both editions.
Thread priorities
Section titled “Thread priorities”Java prints arid: only sets a priority hint
The Rust edition has no such rule: see below.
The Swift edition has no such rule: see below.
A removed setPriority, and a priority from 1 to 10 given to setPriority, a Thread.Builder or
Guava’s ThreadFactoryBuilder. One out of that range throws, and counts.
thread.setPriority(Thread.MIN_PRIORITY);Why: a priority is a hint the operating system may ignore. HotSpot on Linux ignores it unless started with a flag only root can use, and a virtual thread’s is always the normal one.
When to bring it back: you ship on a system that honours priorities, and test the scheduling there.
rules: - mutate: com.example.arid.Workers#background arid: [mutastic:thread-priorities] reason: reports must yield to requests on the Windows servers@DoMutate(value = "reports must yield to requests on the Windows servers", arid = "mutastic:thread-priorities")public static Thread background(Runnable work) {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only sets a priority hint ┌─ src/main/java/com/example/arid/Workers.java:13 │ 12 │ var thread = new Thread(work, "report-worker"); 13 │ thread.setPriority(Thread.MIN_PRIORITY); │ ^^^^^^^^^^^ call removed 14 │ return thread; │ = mutant - thread.setPriority(Thread.MIN_PRIORITY); = operator mutastic/remove-void-call · https://docs.mutastic.io/java/operators/calls/#remove-void-call
reproduce mutastic run --only=m888732e4 samples/arid
= arid mutastic:thread-priorities: A thread's priority from 1 to 10: a hint, which Linux ignores by default and a virtual thread always does. docs: https://docs.mutastic.io/reference/arid/#thread-priorities to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Workers#background arid: [mutastic:thread-priorities] reason: <why a test should check it>In the Rust edition: no such rule: the standard library has no call to set a priority.
In the Swift edition: no such rule.
Changed in: 1.3.0.
Keep alive
Section titled “Keep alive”Java prints arid: only sets how long idle threads live
Rust prints arid: only sets how long idle threads live
The Swift edition has no such rule: see below.
How long a ThreadPoolExecutor’s idle threads live, given to its constructor or to
setKeepAliveTime, while it stays above zero.
return new ThreadPoolExecutor(1, 4, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<>());Why: it decides when an idle thread is let go, which is memory and start-up time, not what the pool runs. A time of zero can throw, so it counts.
When to bring it back: the pool’s threads must be gone by a time something relies on, and your tests check it.
rules: - mutate: com.example.arid.Workers#pool arid: [mutastic:keep-alive] reason: the batch job exits only once the pool's threads are gone@DoMutate(value = "the batch job exits only once the pool's threads are gone", arid = "mutastic:keep-alive")public static ThreadPoolExecutor pool() {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only sets how long idle threads live ┌─ src/main/java/com/example/arid/Workers.java:22 │ 21 │ public static ThreadPoolExecutor pool() { 22 │ return new ThreadPoolExecutor(1, 4, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 30 changed to 29 23 │ } │ = mutant - return new ThreadPoolExecutor(1, 4, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); + return new ThreadPoolExecutor(1, 4, 29, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); = operator mutastic/constant-value · https://docs.mutastic.io/java/operators/arithmetic/#constant-value
reproduce mutastic run --only=m6adab85f samples/arid
= arid mutastic:keep-alive: How long a pool's idle threads live before they stop, while it stays above zero. docs: https://docs.mutastic.io/reference/arid/#keep-alive to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Workers#pool arid: [mutastic:keep-alive] reason: <why a test should check it>In the Rust edition: the duration given to tokio’s thread_keep_alive is skipped the same way,
while it stays above zero.
In the Swift edition: no such rule.
Changed in: 1.3.0, both editions.
Stack sizes
Section titled “Stack sizes”Java prints arid: only sizes a thread's stack
Rust prints arid: only sizes a thread's stack
The Swift edition has no such rule: see below.
The stack size given to new Thread(group, task, name, size) or a Thread.Builder’s stackSize,
while it stays above zero.
return new Thread(null, work, "deep-worker", 64L * 1024 * 1024);Why: most code never comes near its stack’s end, and the JVM may round the size, or ignore it.
When to bring it back: the thread recurses deeply on purpose, and your tests run it that deep.
rules: - mutate: com.example.arid.Workers#deep arid: [mutastic:stack-sizes] reason: the parser recurses once for each level of nesting@DoMutate(value = "the parser recurses once for each level of nesting", arid = "mutastic:stack-sizes")public static Thread deep(Runnable work) {Check it: what mutastic explain says of the skipped mutant, with its rule and the setting to copy:
SKIPPED arid: only sizes a thread's stack ┌─ src/main/java/com/example/arid/Workers.java:18 │ 17 │ public static Thread deep(Runnable work) { 18 │ return new Thread(null, work, "deep-worker", 64L * 1024 * 1024); │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 67108864 changed to 1 19 │ } │ = change the constant 67108864 becomes 1 (not shown in the source) = operator mutastic/constant-value · https://docs.mutastic.io/java/operators/arithmetic/#constant-value
reproduce mutastic run --only=m638dca75 samples/arid
= arid mutastic:stack-sizes: The size of a thread's stack, while it stays above zero. docs: https://docs.mutastic.io/reference/arid/#stack-sizes to run it, add to mutastic.yaml: rules: - mutate: com.example.arid.Workers#deep arid: [mutastic:stack-sizes] reason: <why a test should check it>In the Rust edition: the size given to thread::Builder::stack_size or tokio’s
thread_stack_size is skipped the same way, while it stays above zero.
In the Swift edition: no such rule.
Changed in: 1.3.0, both editions.
Gatherer sizes
Skipped by default mutastic:gatherer-sizes judges one call or value.
How many calls Gatherers.mapConcurrent runs at once, while it stays above zero.
Java prints arid: only sets how many run at once, for code like this:
items.stream().gather(Gatherers.mapConcurrent(4, this::price)).toList();To bring it back, cover the code that needs it with a mutate: rule or@DoMutate, as in the sections above.
C results
Skipped by default mutastic:c-results judges one call or value.
A check that a C call succeeded, where failing only stops the program: the comparison of the call’s result, or of a name the statement just before sets to it, with a constant. No test can make the C library fail there.
Rust prints arid: only checks a C call's result, for code like this:
if unsafe { libc::pthread_mutex_lock(lock) } != 0 { panic!("lock failed"); }Swift prints arid: only checks a C call's result, for code like this:
guard pthread_mutex_lock(&lock) == 0 else { fatalError("lock failed") }To bring it back, cover the code that needs it with a mutate: rule or@DoMutate, as in the sections above.
No longer skipped
Section titled “No longer skipped”First values
Section titled “First values”Until 1.3.0, a variable’s first value of 0 or 1, as in int total = 0;, was skipped as arid.
It isn’t now. Where a total, a count or an index starts flows into what the code gives, so a test
of the result sees a wrong start: the skip hid mutants such tests catch, and the ones they miss.
A first value the code replaces before anything reads it is skipped as equivalent instead. Mutants
of numbers come with --operators=stronger.
In the Rust edition: a let’s first value of 0 or 1 gets its mutants too.
Changed in: 1.3.0, both editions.