Skip to content
mutastic

Swift edition

Returns and errors

Operators that change what a function gives back, or what happens when the code it calls throws.

OperatorChangesSet
mutastic/return-valuea returned value to a plain onedefaults
mutastic/unwrap-trytry to try!defaults
swift/try-niltry? to nilextended

The mutants each makes, on samples/operators/Sources/Operators/Returns.swift:

Terminal window
mutastic mutants samples/operators --at=Sources/Operators/Returns.swift:1-99 --operators=mutastic/return-value,mutastic/unwrap-try,swift/try-nil
Terminal window
m744350a0 Sources/Operators/Returns.swift:9:10 mutastic/return-value returns 0 instead in quantity
m9f1b2d06 Sources/Operators/Returns.swift:14:14 mutastic/unwrap-try try becomes try! in doubled
mec14e21a Sources/Operators/Returns.swift:15:10 mutastic/return-value returns 0 instead in doubled
m7af31f52 Sources/Operators/Returns.swift:20:15 swift/try-nil try? quantity(text) becomes nil in maybeQuantity
m19078168 Sources/Operators/Returns.swift:21:10 mutastic/return-value returns nil instead in maybeQuantity
no estimate: no run is recorded here yet; run once to get estimates, or add --estimate
5 mutants

mutastic/return-value, in the defaults. A returned value is replaced by a plain one of its type: 0, or 1 where the code returns 0; true or false; ""; nil for an optional. It asks whether any test looks at what the function returns.

mutastic/unwrap-try, in the defaults. A try becomes try!, so an error thrown there crashes instead of reaching the code that handles it. It asks for a test where the call throws.

swift/try-nil, in extended and all, not in the defaults or stronger. Swift’s own. A try? whose value is used gives nil, as if what it tried had thrown. It asks for a test where the call works, and one where it doesn’t.