You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After looking thorough the code and the QuickCheck code I realize that what I'm asking to do is probably not possible to do automatically. But instead forAllShrink can be used with a custom shrinker that filters the values according to my predicate. Like this:
func stringDoesNotContainA(_ string: String) -> Bool {
precondition(!string.isEmpty)
return !string.contains("a" as Character)
}
class SwiftCheckTests: XCTestCase {
func testSwiftCheck() {
let predicate = { (str: String) -> Bool in
return !str.isEmpty
}
let stringShrinker = { (str: String) -> [String] in
String.shrink(str).filter(predicate)
}
property("string is not \"a\"") <- forAllShrink(String.arbitrary.suchThat(predicate) , shrinker: stringShrinker, f: stringDoesNotContainA)
}
}
Hi @niilohlin, apologies for the delay in getting to this.
This is the expected behavior. shrink is defined as a static requirement on the type that conforms to arbitrary. We do not derive shrinkers from generators as other, more recent, frameworks may try to do. Instead, you should write a modifier type for strings that pass your predicate and add your own shrinker there.
Version
SwiftCheck (0.10.0)
Environment
Xcode 9.4.1. iOS target.
Description
When a property fails with a custom
Gen<T>
the generator is not used while shrinking. And therefore calling the test block without it.Steps To Reproduce
sample code:
Expected Result
The function
stringDoesNotContainA
is expected to only be called with non empty strings.Actual Result
After the test fails. The function is called with an empty String and execution halts.
The text was updated successfully, but these errors were encountered: