diff --git a/RxTests/Event+Equatable.swift b/RxTests/Event+Equatable.swift index 413cd16b..d5ce04ce 100644 --- a/RxTests/Event+Equatable.swift +++ b/RxTests/Event+Equatable.swift @@ -15,12 +15,17 @@ Compares two events. They are equal if they are both the same member of `Event` In case `Error` events are being compared, they are equal in case their `NSError` representations are equal (domain and code) and their string representations are equal. */ -func == (lhs: Event, rhs: Event) -> Bool { +public func == (lhs: Event, rhs: Event) -> Bool { switch (lhs, rhs) { case (.Completed, .Completed): return true case (.Error(let e1), .Error(let e2)): let error1 = e1 as NSError let error2 = e2 as NSError + + // if the references are equal, then it's the same object + if let lhsObject = lhs as? AnyObject, rhsObject = rhs as? AnyObject where lhsObject === rhsObject { + return true + } return error1.domain == error2.domain && error1.code == error2.code diff --git a/Tests/RxSwiftTests/Tests/AssumptionsTest.swift b/Tests/RxSwiftTests/Tests/AssumptionsTest.swift index 85a27634..939c05e6 100644 --- a/Tests/RxSwiftTests/Tests/AssumptionsTest.swift +++ b/Tests/RxSwiftTests/Tests/AssumptionsTest.swift @@ -18,11 +18,11 @@ func clearRealTest() { } func returnSomething() -> Observable { - return Observable.just("a") + return Observable.just(NSNull()) } -func returnSomething() -> Observable { - return Observable.just(CGRectMake(0, 0, 100, 100)) +func returnSomething() -> Observable { + return Observable.just(3) } class AssumptionsTest : RxTest { @@ -66,12 +66,12 @@ class AssumptionsTest : RxTest { func testFunctionReturnValueOverload() { _ = returnSomething() .subscribeNext { (n: AnyObject?) in - XCTAssertEqual("\(n ?? NSNull())", "a") + XCTAssertEqual(n as? NSNull, NSNull()) } _ = returnSomething() - .subscribeNext { (n: CGRect?) in - XCTAssertEqual(n!, CGRectMake(0, 0, 100, 100)) + .subscribeNext { (n: Int?) in + XCTAssertEqual(n!, 3) } } diff --git a/Tests/RxSwiftTests/Tests/Observable+StandardSequenceOperatorsTest.swift b/Tests/RxSwiftTests/Tests/Observable+StandardSequenceOperatorsTest.swift index 8fd0a94d..57a58cea 100644 --- a/Tests/RxSwiftTests/Tests/Observable+StandardSequenceOperatorsTest.swift +++ b/Tests/RxSwiftTests/Tests/Observable+StandardSequenceOperatorsTest.swift @@ -27,7 +27,11 @@ func isPrime(i: Int) -> Bool { } let max = Int(sqrt(Float(i))) - for (var j = 2; j <= max; ++j) { + if max <= 1 { + return true + } + + for j in 2 ... max { if i % j == 0 { return false } diff --git a/Tests/RxSwiftTests/Tests/Observable+TimeTest.swift b/Tests/RxSwiftTests/Tests/Observable+TimeTest.swift index c4b35a4b..9ac483b9 100644 --- a/Tests/RxSwiftTests/Tests/Observable+TimeTest.swift +++ b/Tests/RxSwiftTests/Tests/Observable+TimeTest.swift @@ -759,30 +759,32 @@ extension ObservableTimeTest { let observer = PrimitiveMockObserver() - var lock = OS_SPINLOCK_INIT - - OSSpinLockLock(&lock) + let expectCompleted = expectationWithDescription("It will complete") let d = Observable.interval(0, scheduler: scheduler).takeWhile { $0 < 10 } .subscribe(onNext: { t in observer.on(.Next(t)) }, onCompleted: { - OSSpinLockUnlock(&lock) + expectCompleted.fulfill() }) defer { d.dispose() } - OSSpinLockLock(&lock) - OSSpinLockUnlock(&lock) + waitForExpectationsWithTimeout(1.0) { e in + XCTAssert(e == nil, "Did not complete") + } + + let cleanResources = expectationWithDescription("Clean resources") scheduler.schedule(()) { _ in - OSSpinLockUnlock(&lock) + cleanResources.fulfill() return NopDisposable.instance } - // wait until dispatch queue cleans it's resources - OSSpinLockLock(&lock) + waitForExpectationsWithTimeout(1.0) { e in + XCTAssert(e == nil, "Did not clean up") + } XCTAssertTrue(observer.events.count == 10) } diff --git a/Tests/RxSwiftTests/Tests/SubjectConcurrencyTest.swift b/Tests/RxSwiftTests/Tests/SubjectConcurrencyTest.swift index 9a233ba3..fb1da520 100644 --- a/Tests/RxSwiftTests/Tests/SubjectConcurrencyTest.swift +++ b/Tests/RxSwiftTests/Tests/SubjectConcurrencyTest.swift @@ -63,11 +63,11 @@ extension SubjectConcurrencyTest { } } else if state == 1 { - XCTAssertTrue(!NSThread.isMainThread()) + XCTAssertTrue(!NSThread.currentThread().isMainThread) state = 2 } else if state == 2 { - XCTAssertTrue(NSThread.isMainThread()) + XCTAssertTrue(NSThread.currentThread().isMainThread) allDone = true } } diff --git a/Tests/RxTest.swift b/Tests/RxTest.swift index 0c92e842..0f347c3e 100644 --- a/Tests/RxTest.swift +++ b/Tests/RxTest.swift @@ -26,7 +26,10 @@ import RxTests typealias Time = Int func XCTAssertErrorEqual(lhs: ErrorType, _ rhs: ErrorType) { - XCTAssertTrue(lhs as NSError === rhs as NSError) + let event1: Event = .Error(lhs) + let event2: Event = .Error(rhs) + + XCTAssertTrue(event1 == event2) } func XCTAssertEqualNSValues(lhs: AnyObject, rhs: AnyObject) {