[swift-evolution] [Proposal] XCTFail should be @noreturn

Alexander Momchilov alexandermomchilov at gmail.com
Wed Jun 8 17:59:43 CDT 2016


Because XCTFail() isn't annotated @noreturn, it isn't sufficient in a guard statement

guard var b = a as? B else {
	XCTFail("Result wasn't castable to B")
	return //this is redundant
}

This could be broken down into a XCTAssertTrue(a is B) statement, followed by a forced cast, but that seems redundant.

I realize that continueAfterFailure exists to make the test cases continue even after failures. This complicates the solution beyond just adding the @noreturn annotation.

The only solution I can think of happens to be the simplest: add a new variation of XCTFail() that ignores continueAfterFailure, such as XCTAlwaysFail()

A true solution would be for the @noreturn attribute to be conditional… the compiler would somehow need to be aware of the continueAfterFailure property's value. I don't know how that could be done.

Thoughts?


- Regards,
        Alexander Momchilov

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160608/e8aeb365/attachment.html>


More information about the swift-evolution mailing list