-
Notifications
You must be signed in to change notification settings - Fork 263
[XCTestExpectation] Adding expectationForPredicate constructor #103
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
// CHECK: Test Suite 'PredicateExpectationsTestCase' started at \d+:\d+:\d+\.\d+ | ||
class PredicateExpectationsTestCase: XCTestCase { | ||
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTruePredicateAndObject_passes' started at \d+:\d+:\d+\.\d+ | ||
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTruePredicateAndObject_passes' passed \(\d+\.\d+ seconds\). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With #94 merged you may now indent the // CHECK:
, like so:
func myFunc() {
// CHECK: foo
print("foo")
if (bar) {
// CHECK: baz
print("baz")
}
}
I think indenting is more readable, so I'd encourage you to do that! (I had been meaning to start sending out pull requests to indent the checks in the tests, but forgot 😇 )
This is really excellent work, @yoonapps, thank you!! @mike-ferris-apple Could you ask @swift-ci to please test? |
@modocache Addressed reviews! I lowered the interval to |
@swift-ci please test |
/// first successful evaluation will fulfill the expectation. If provided, | ||
/// the handler can override that behavior which leaves the caller | ||
/// responsible for fulfilling the expectation. | ||
public func expectation(forPredicate predicate: NSPredicate, evaluatedWithObject object: AnyObject, file: StaticString = #file, line: UInt = #line, handler: XCPredicateExpectationHandler? = nil) -> XCPredicateExpectation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the precise signature of this method needs to be adjusted. I'm seeing the following imported signature in Xcode using the latest Swift toolchain:
public func expectation(for predicate: NSPredicate, evaluatedWith object: AnyObject, handler: XCPredicateExpectationHandler? = nil) -> XCTestExpectation
Does this look right? @mike-ferris-apple @modocache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This was generated with the Swift 3 importer from a month ago, but it matches @briancroom's signature.
Excited to see this come in @yoonapps, thanks! I just left a couple questions. |
I'm learning so much every PR! It's awesome. |
c586eef
to
f737155
Compare
timer.invalidate() | ||
} | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried CTRL + I here but this is where the indentation goes. Does this look funky or is it just me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does look strange. Personally, I would remove four spaces, in order to align it with the open brace on the self.timer = NSTimer.scheduledTimer(self.evaluationInterval, repeats: true, fire: {
line. It's up to you, though! :)
Good observation! Apple XCTest doesn't provide a public initializer for |
Gotcha! Is there anything else that needs to be addressed? |
@briancroom does the timer invalidation look good? @mike-ferris-apple Could you ask @swift-ci to please test? |
@swift-ci please test |
Looks great! Nice work @yoonapps |
import SwiftFoundation | ||
#endif | ||
|
||
public class XCPredicateExpectation: XCTestExpectation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, just one more thing - can we make this subclass have internal visibility, and return the base class type from the factory method on XCTestCase?
- Added class XCPredicateExpectation - Added typealias for XCPredicateExpectationHandler - Added tests for the expectation and handler
@briancroom Ah!! I had it |
Excellent, thanks @yoonapps!! That's two tasks under your belt! 💯 |
Not a problem. The experience I'm getting from these tasks are invaluable. Thanks for sending this task my way, @modocache! I'm always ready for more so let me know if you have any suggestions. |
What's in this pull request?
This pull request adds the XCTestCase convenience constructor for XCTestExpectation
expectation(forPredicate:evaluatedWithObject:handler:)
.I added
XCPredicateExpectation
, an internal subclass ofXCTestExpectation
, to keep the evaluation logic separated (and to match the obj-c implementation). The re-evaluation interval has been shorted to0.01
whereas the obj-c interval is about once per second.This also includes a separate file for the
typealias
XCPredicateExpectationHandler
.There are tests for the expectation and the handler. Let me know if you think there should be more tests, I'd be happy to add other ideas.
https://bugs.swift.org/browse/SR-1110
Why merge this pull request?
This will provide a full Swift implementation of
expectationForPredicate:evaluatedWithObject:handler:
that allows asynchronous testing forNSPredicate
.