-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix assert<T>(T?, T -> Bool) #3
Conversation
Why is this change necessary? The tests on |
Because I tried to add test that expresses |
Ah, good catch—thank you! 🙇 |
👌 |
I think the only way we could reasonably test assertion failure would be to fork off |
(Alternatively, we might be able to construct a custom |
I found overriding final class AssertionsTests: XCTestCase {
var expectingFailure = false
var expectedFailureOccurred = false
override func recordFailureWithDescription(description: String!, inFile filePath: String!, atLine lineNumber: UInt, expected: Bool) {
if expectingFailure {
expectedFailureOccurred = true
} else {
super.recordFailureWithDescription(description, inFile: filePath, atLine: lineNumber, expected: false)
}
}
func expectFailure(test: Void -> Void) {
expectingFailure = true
expectedFailureOccurred = false
test()
expectingFailure = false
XCTAssert(expectedFailureOccurred)
}
func testAssertFailure() {
expectFailure {
assert(" ", { $0.isEmpty }) // calls XCTFail but is not collected as a failure
}
}
func testAssertSuccess() {
assert("", { $0.isEmpty })
}
} I'm not sure that this kind of code should be used in tests of this library. |
Cool, thank you for sharing that! That’s much simpler than I expected we could manage, and I think it’d be a great addition to the tests 👍 |
Fix
assert("foo", { $0.isEmpty })
passes tests.