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
First Off I'd like to say that I found this mini library super handy for building my own assertion helpers on the Result type. Thank you for making it available. I attempted to tackle a Combine test helper that where I typically use an XCTExpectation within the implementation like so:
publicextensionPublisher{typealiasCollection=Result<[Output],Failure>
/// A Test Operator that subscribes to the Publisher and blocks while it aggregates the output into a Collection type
///
/// - parameters:
/// - timeout: A maximum time that the operator is allowed to collect output from the Publisher.
/// - limit: A maximum amount of output from the Publisher that should be collected. 0 disables the limit.
/// - testTasks: Environmental testing tasks that should be run directly after subscription.
///
/// - returns: A Publisher Collection that contains a list of all the output or the provided failure
///
func wait(
timeout:TimeInterval=5,
limit:Int=0,
testTasks:()->Void={},
_ file:StaticString= #file,
_ line:UInt= #line
)->Collection{varcollected:[Output]=[]varfailure:Failure?varcancellables=Set<AnyCancellable>()letexpectation=XCTestExpectation(description:"wait")func evaluateLimit(){letshouldFulfill= limit == collected.count
if shouldFulfill { expectation.fulfill()}}sink(
receiveCompletion:{ completion in
switch completion {case.finished:
expectation.fulfill()caselet.failure(error):
failure = error
expectation.fulfill()}},
receiveValue:{ value in
collected.append(value)evaluateLimit()}).store(in:&cancellables)testTasks()letwaiter=XCTWaiter()
waiter.wait(for:[expectation], timeout: timeout)
guard let foundFailure = failure else{return.success(collected)}return.failure(foundFailure)}}
I wanted something similar to RxBlocking which was suuuuper handy for testing Observables. This seemed to work well enough for my purposes when I had it as an extension in my test target. However I wanted to include it along with my Source Code in a TestSupport file so I tried to use your XCTFail and ended up replacing the Expectation and Waiter with a DispatchSemaphore. It seemed to work identical to the Expectation/Waiter combo until I tried delivering inputs from the main thread. Lol, I should have known the Semaphore froze the main thread and so no future work could be delivered onto it until the signal released it, which then gives me veeeery different results than using the Expectation/Waiter combo.
Are there any plans to include other XCTest members like XCTExpectation and XCTWaiter or is it just going to be the XCTFail?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Off I'd like to say that I found this mini library super handy for building my own assertion helpers on the Result type. Thank you for making it available. I attempted to tackle a Combine test helper that where I typically use an XCTExpectation within the implementation like so:
I wanted something similar to RxBlocking which was suuuuper handy for testing Observables. This seemed to work well enough for my purposes when I had it as an extension in my test target. However I wanted to include it along with my Source Code in a TestSupport file so I tried to use your XCTFail and ended up replacing the Expectation and Waiter with a DispatchSemaphore. It seemed to work identical to the Expectation/Waiter combo until I tried delivering inputs from the main thread. Lol, I should have known the Semaphore froze the main thread and so no future work could be delivered onto it until the signal released it, which then gives me veeeery different results than using the Expectation/Waiter combo.
Are there any plans to include other XCTest members like XCTExpectation and XCTWaiter or is it just going to be the XCTFail?
Beta Was this translation helpful? Give feedback.
All reactions