-
Notifications
You must be signed in to change notification settings - Fork 263
Add @autoclosure to message parameter, so it's constructed only if it's needed. #17
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
Conversation
The
Here's the Swift public func XCTAssert(@autoclosure expression: () -> BooleanType, _ message: String = default, file: String = default, line: UInt = default) |
Oh, I see. This is an API change indeed. However, it doesn't lead to any changes to tests. |
There are already a few differentials and I think this might be something that would perhaps be an improvement to both; in that the messages could have side-effects that would not be intended unless in a failure case. e.g. calculating a debug description etc. I would be interested to see how this change would work if it were in the XCTest overlay as well performance wise; faster tests usually mean people are more willing to have more tests execute for the one thing they are iterating on. |
@modocache current implementation already have slightly different signature: public func XCTAssert(@autoclosure expression: () -> BooleanType, _ message: String = "", file: StaticString = __FILE__, line: UInt = __LINE__) |
Hey yeah, look at that! What the heck is a |
How about What's the final goal? To make sure it's letter-by-letter the same as the previous declaration? It's already not. If the goal is
Then |
@modocache StaticString is specifically anything written as "" instead of a variable. This was initially required for the linux implementation to even work (at least at the time of when I originally wrote that portion). It may no longer be needed |
@phausler No, it was added to the library for a different reason. It was added to represent a string that does not need to be dynamically allocated (like a file name in an assertion). It is cheaper than String. |
@kovpas I agree! If we're willing to deviate slightly from the function signatures in Objective-C XCTest, using an
I think these are the default parameters for Objective-C XCTest as well, they're just represented as |
This is correct, "", FILE, and LINE are the default values in the Xcode XCTest assertions. They're implemented in the XCTest overlay in the Swift codebase, so you can see them there.
|
I like this change. Could you make a similar pull request for the XCTest overlay in the swift project as well? |
@mike-ferris-apple sure, will do today. |
Also, some of the other pull requests we've taken lately have caused this to have conflicts. Do you mind rebasing it? |
e3f2fcc
to
5171abb
Compare
@mike-ferris-apple done. |
@mike-ferris-apple also created a pull request in the swift project: swiftlang/swift#913 |
Thanks! |
Add @autoclosure to message parameter, so it's constructed only if it's needed.
Sometimes it's nice to have a complex "conditional"
XCTAssert
message.This is already a small performance impact, but it's nothing too bad, unless it's in a loop. There was a test in NSCharacterSet, which used to take quite a lot of time: https://github.com/apple/swift-corelibs-foundation/pull/149/files
I think it would be nice if
message
param is only evaluated if it's needed.The test, that used to take 116 sec on my linux machine, takes only 3.5 seconds with this change.