Releases: typelift/SwiftCheck
Target Practice
- Fixes a compatibility issue with the Swift Package Manager
- Thanks to gyb,
zip
andmap
now extend all the way out to arity 22. - The default
RawRepresentable
arbitrary instance has been removed.
The Seven Chekras
SwiftCheck now fully supports Swift 3.0 and Xcode 8.0. That entails a bit of breakage:
- The operator equivalents for functional combinators have been removed - these are,
<^>
,<*>
, and>>-
. Please use their nominal equivalents.map
,.ap
, and.flatMap
respectively. - For long Applicative-style chains
a <^> b <*> c <*> ...
please useGen.compose
. - The little-known and barely-used
exhaustive
requirement ofArbitrary
has been removed. Please use.once
and.again
.
In addition, we have a number of framework improvements:
Gen.withBounds
andGen.chooseAny
have been added to make interacting withRandomType
andLatticeType
generators even easier.- Fixes a potential crash when interacting with
randomInRange
for large unsigned values. - Documentation coverage and robustness continues to increase with the addition of doc comments.
- SwiftCheck now builds without dependencies.
Thank you to everybody who contributed to this release.
@griotspeak
@bgerstle
@kouky
@EuAndreh
@kballard
@gfontenot
@kykim
❤️
Scrap Your [Applicative] Boilerplate
This release includes support for Swift 2.3. In addition, we've completely revamped the way you can interact with Gen
with a new combinator Gen.compose
.
Most users of this framework have to generate structures that involve significant amounts of setup and state. Previously, this meant you would have to go through the Applicative generator dance much like this
MyClass.create
<^> Int.arbitrary
<*> String.arbitrary
<*> Float.arbitrary
<*> // ...
This pattern, while terse, can lead to code bloat, bad compile times, and an overall bad experience with the framework. Instead, let's rewrite this in a more natural way [and infer all the types as a bonus!]
Gen<MyClass>.compose { c in
return MyClass(
// Use the nullary method to get an `arbitrary` value.
a: c.generate(),
// or pass a custom generator
b: c.generate(Bool.suchThat { $0 == false }),
// .. and so on, for as many values and types as you need.
c: c.generate(), ...
)
}
We're going to begin the process of deprecating the old pattern and replacing it with Gen.compose
.
The Exchequer
This is an exciting release for us, led by a ton of helpful new features and patterns to make the framework easier more Swifty. Let's get right to it:
- We know it can be a huge pain to work with the
Applicative
operators. To that end, we have included an instance ofMonoidal
Functors (rather than the oldApplicative
one) forGen
that provides an overload ofzip
up to 10 parameters. This means code that previously looked like this:
public struct ArbitraryFoo {
let x : Int
let y : Int
public static func create(x : Int) -> Int -> ArbitraryFoo {
return { y in ArbitraryFoo(x: x, y: y) }
}
}
extension ArbitraryFoo : Arbitrary {
public static var arbitrary : Gen<ArbitraryFoo> {
return ArbitraryFoo.create <^> Int.arbitrary <*> Int.arbitrary
}
}
Can instead scrap the horrific initializer boilerplate and move straight to zip
then map
like so:
public struct ArbitraryFoo {
let x : Int
let y : Int
}
extension ArbitraryFoo : Arbitrary {
public static var arbitrary : Gen<ArbitraryFoo> {
return Gen<(Int, Int)>.zip(Int.arbitrary, Int.arbitrary).map(ArbitraryFoo.init)
}
}
If you ever run out of parameters, try flatMap
ing generators together.
- Enums that conform to
RawRepresentable
now have a default instance ofArbitrary
if you ask for it. To do so, simply declare your conformance to bothRawRepresentable
andArbitrary
and we'll handle the rest (thanks @bgerstle!). zip
andap
now have much, much faster implementations.- Fixed a bug (h/t @bgerstle) where replay seeds and sizes would fail to print if the test failed through
cover
age. - The framework's overall documentation and code coverage continue to improve.
Check Yourself Before You Wreck Yourself
- SwiftCheck now fully supports Swift 2.2 and all that entails including
- Support for the Swift Package Manager
- Support for building SwiftCheck on Linux
- The order of
Gen.sequence
andRose.sequence
have been fixed. - Documentation has been added to more parts of the framework.
- Our own test suite is now more robust.
Arbiter of Perfection
- Adjusts internal RNG code for integers so it isn't subject to integer overflow conditions. This fixes #151 and may, as a side-effect, cause existing seed values created before this release to report different values as the calculations have become more robust.
Carthaginian Angst
- Fixes compatibility issues with the iOS Carthage scheme (h/t @samritchie).
Harry Potter and the Half-Blood print()s
For SwiftCheck's 5th birthday, we sped up all the insides and moved the furniture around a bit.
- The insides of
Gen
move an order of magnitude quicker because of framework-wide simplifications. - We now match Swift's naming convention for some big combinators (esp.
map
andflatMap
). Update your code accordingly! - Currying syntax has been removed framework-wide and labels have been made more semantically meaningful.
Gen.fromShufflingElementsOf
is unbelievably fast now.- pseudo-Equatable instances for modifier types have been removed.
- More things have been documented and what documentation there is has been improved.
- Quantifiers and property binders have more informative
@warn_unused_result
messages.
Finally, for the pièce de résistance, cover
has been made a first-class citizen of the framework. For those times when a particular property of a spec should hold a certain percentage of the time, you can ask SwiftCheck how well it's been covered. If we don't rise to meet your set goals, the test fails!
Production Rights
We fought xcodebuild tooth and nail to bring you tvOS support. Enjoy!
Effectric Slide
- Framework build times continue to improve.
- Fixes an issue where building the framework in release mode would cause strange crashes (h/t @kykim).