From b545da7c8a41f62aebb284bd46a42e9262b985f7 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 4 Jan 2025 20:33:28 -0500 Subject: [PATCH 1/3] Android support --- .github/workflows/ci.yml | 5 +++++ Tests/A+/2.1.2.swift | 6 +++--- Tests/A+/2.1.3.swift | 8 ++++---- Tests/A+/2.2.2.swift | 20 ++++++++++---------- Tests/A+/2.2.3.swift | 2 +- Tests/CorePromise/AfterTests.swift | 12 ++++++------ Tests/CorePromise/CatchableTests.swift | 6 +++--- Tests/CorePromise/LoggingTests.swift | 3 +++ Tests/CorePromise/ResolverTests.swift | 13 ++++++++----- Tests/CorePromise/StressTests.swift | 2 +- Tests/CorePromise/WhenTests.swift | 6 +++--- 11 files changed, 47 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68bc51d67..5b669014e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,3 +95,8 @@ jobs: action: test enable-code-coverage: true - uses: codecov/codecov-action@v1 + test-android: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: skiptools/swift-android-action@v2 diff --git a/Tests/A+/2.1.2.swift b/Tests/A+/2.1.2.swift index c895c2f93..fffadb847 100644 --- a/Tests/A+/2.1.2.swift +++ b/Tests/A+/2.1.2.swift @@ -5,17 +5,17 @@ class Test212: XCTestCase { func test() { describe("2.1.2.1: When fulfilled, a promise: must not transition to any other state.") { testFulfilled { promise, expectation, _ in - promise.test(onFulfilled: expectation.fulfill, onRejected: { XCTFail() }) + promise.test(onFulfilled: { expectation.fulfill() }, onRejected: { XCTFail() }) } specify("trying to fulfill then immediately reject") { d, expectation in - d.promise.test(onFulfilled: expectation.fulfill, onRejected: { XCTFail() }) + d.promise.test(onFulfilled: { expectation.fulfill() }, onRejected: { XCTFail() }) d.fulfill() d.reject(Error.dummy) } specify("trying to fulfill then reject, delayed") { d, expectation in - d.promise.test(onFulfilled: expectation.fulfill, onRejected: { XCTFail() }) + d.promise.test(onFulfilled: { expectation.fulfill() }, onRejected: { XCTFail() }) after(ticks: 1) { d.fulfill() d.reject(Error.dummy) diff --git a/Tests/A+/2.1.3.swift b/Tests/A+/2.1.3.swift index d24ae683f..b0ac08e17 100644 --- a/Tests/A+/2.1.3.swift +++ b/Tests/A+/2.1.3.swift @@ -5,17 +5,17 @@ class Test213: XCTestCase { func test() { describe("2.1.3.1: When rejected, a promise: must not transition to any other state.") { testRejected { promise, expectation, _ in - promise.test(onFulfilled: { XCTFail() }, onRejected: expectation.fulfill) + promise.test(onFulfilled: { XCTFail() }, onRejected: { expectation.fulfill() }) } specify("trying to reject then immediately fulfill") { d, expectation in - d.promise.test(onFulfilled: { XCTFail() }, onRejected: expectation.fulfill) + d.promise.test(onFulfilled: { XCTFail() }, onRejected: { expectation.fulfill() }) d.reject(Error.dummy) d.fulfill() } specify("trying to reject then fulfill, delayed") { d, expectation in - d.promise.test(onFulfilled: { XCTFail() }, onRejected: expectation.fulfill) + d.promise.test(onFulfilled: { XCTFail() }, onRejected: { expectation.fulfill() }) after(ticks: 1) { d.reject(Error.dummy) d.fulfill() @@ -23,7 +23,7 @@ class Test213: XCTestCase { } specify("trying to reject immediately then fulfill delayed") { d, expectation in - d.promise.test(onFulfilled: { XCTFail() }, onRejected: expectation.fulfill) + d.promise.test(onFulfilled: { XCTFail() }, onRejected: { expectation.fulfill() }) d.reject(Error.dummy) after(ticks: 1) { d.fulfill() diff --git a/Tests/A+/2.2.2.swift b/Tests/A+/2.2.2.swift index f1ba89917..6c4b45aaa 100644 --- a/Tests/A+/2.2.2.swift +++ b/Tests/A+/2.2.2.swift @@ -27,7 +27,7 @@ class Test222: XCTestCase { } specify("never fulfilled") { d, expectation in d.promise.done{ XCTFail() }.silenceWarning() - after(ticks: 1000, execute: expectation.fulfill) + after(ticks: 1000, execute: { expectation.fulfill() }) } } @@ -42,12 +42,12 @@ class Test222: XCTestCase { } } specify("trying to fulfill a pending promise more than once, immediately") { d, expectation in - d.promise.done(expectation.fulfill).silenceWarning() + d.promise.done({ expectation.fulfill() }).silenceWarning() d.fulfill() d.fulfill() } specify("trying to fulfill a pending promise more than once, delayed") { d, expectation in - d.promise.done(expectation.fulfill).silenceWarning() + d.promise.done({ expectation.fulfill() }).silenceWarning() after(ticks: 5) { d.fulfill() d.fulfill() @@ -55,24 +55,24 @@ class Test222: XCTestCase { } specify("trying to fulfill a pending promise more than once, immediately then delayed") { d, expectation in let ex = (expectation, mkex()) - d.promise.done(ex.0.fulfill).silenceWarning() + d.promise.done({ ex.0.fulfill() }).silenceWarning() d.fulfill() after(ticks: 5) { d.fulfill() } - after(ticks: 10, execute: ex.1.fulfill) + after(ticks: 10, execute: { ex.1.fulfill() }) } specify("when multiple `then` calls are made, spaced apart in time") { d, expectation in let ex = (expectation, self.expectation(description: ""), self.expectation(description: ""), self.expectation(description: "")) do { - d.promise.done(ex.0.fulfill).silenceWarning() + d.promise.done({ ex.0.fulfill() }).silenceWarning() } after(ticks: 5) { - d.promise.done(ex.1.fulfill).silenceWarning() + d.promise.done({ ex.1.fulfill() }).silenceWarning() } after(ticks: 10) { - d.promise.done(ex.2.fulfill).silenceWarning() + d.promise.done({ ex.2.fulfill() }).silenceWarning() } after(ticks: 15) { d.fulfill() @@ -82,9 +82,9 @@ class Test222: XCTestCase { specify("when `then` is interleaved with fulfillment") { d, expectation in let ex = (expectation, self.expectation(description: ""), self) - d.promise.done(ex.0.fulfill).silenceWarning() + d.promise.done({ ex.0.fulfill() }).silenceWarning() d.fulfill() - d.promise.done(ex.1.fulfill).silenceWarning() + d.promise.done({ ex.1.fulfill() }).silenceWarning() } } } diff --git a/Tests/A+/2.2.3.swift b/Tests/A+/2.2.3.swift index 996d6a226..161923309 100644 --- a/Tests/A+/2.2.3.swift +++ b/Tests/A+/2.2.3.swift @@ -30,7 +30,7 @@ class Test223: XCTestCase { } specify("never rejected") { d, expectation in d.promise.catch { _ in XCTFail() } - after(ticks: 1, execute: expectation.fulfill) + after(ticks: 1, execute: { expectation.fulfill() }) } } describe("2.2.3.3: it must not be called more than once.") { diff --git a/Tests/CorePromise/AfterTests.swift b/Tests/CorePromise/AfterTests.swift index 6b587c954..314700ba5 100644 --- a/Tests/CorePromise/AfterTests.swift +++ b/Tests/CorePromise/AfterTests.swift @@ -4,11 +4,11 @@ import XCTest class AfterTests: XCTestCase { func testZero() { let ex2 = expectation(description: "") - after(seconds: 0).done(ex2.fulfill) + after(seconds: 0).done({ ex2.fulfill() }) waitForExpectations(timeout: 2, handler: nil) let ex3 = expectation(description: "") - after(.seconds(0)).done(ex3.fulfill) + after(.seconds(0)).done({ ex3.fulfill() }) waitForExpectations(timeout: 2, handler: nil) #if !SWIFT_PACKAGE @@ -20,11 +20,11 @@ class AfterTests: XCTestCase { func testNegative() { let ex2 = expectation(description: "") - after(seconds: -1).done(ex2.fulfill) + after(seconds: -1).done({ ex2.fulfill() }) waitForExpectations(timeout: 2, handler: nil) let ex3 = expectation(description: "") - after(.seconds(-1)).done(ex3.fulfill) + after(.seconds(-1)).done({ ex3.fulfill() }) waitForExpectations(timeout: 2, handler: nil) #if !SWIFT_PACKAGE @@ -36,11 +36,11 @@ class AfterTests: XCTestCase { func testPositive() { let ex2 = expectation(description: "") - after(seconds: 1).done(ex2.fulfill) + after(seconds: 1).done({ ex2.fulfill() }) waitForExpectations(timeout: 2, handler: nil) let ex3 = expectation(description: "") - after(.seconds(1)).done(ex3.fulfill) + after(.seconds(1)).done({ ex3.fulfill() }) waitForExpectations(timeout: 2, handler: nil) #if !SWIFT_PACKAGE diff --git a/Tests/CorePromise/CatchableTests.swift b/Tests/CorePromise/CatchableTests.swift index d94b2b6f5..d1f0a5cb4 100644 --- a/Tests/CorePromise/CatchableTests.swift +++ b/Tests/CorePromise/CatchableTests.swift @@ -55,7 +55,7 @@ extension CatchableTests { func helper(error: Swift.Error) { let ex = expectation(description: "") - Promise(error: error).recover { _ in }.done(ex.fulfill) + Promise(error: error).recover { _ in }.done({ ex.fulfill() }) wait(for: [ex], timeout: 10) } @@ -65,7 +65,7 @@ extension CatchableTests { func test__void_specialized_full_recover__fulfilled_path() { let ex = expectation(description: "") - Promise().recover { _ in XCTFail() }.done(ex.fulfill) + Promise().recover { _ in XCTFail() }.done({ ex.fulfill() }) wait(for: [ex], timeout: 10) } @@ -76,7 +76,7 @@ extension CatchableTests { Promise(error: error).recover(policy: policy) { err in guard x < 1 else { throw err } x += 1 - }.done(ex.fulfill).silenceWarning() + }.done({ ex.fulfill() }).silenceWarning() wait(for: [ex], timeout: 10) } diff --git a/Tests/CorePromise/LoggingTests.swift b/Tests/CorePromise/LoggingTests.swift index ab869d1ac..387391f9f 100644 --- a/Tests/CorePromise/LoggingTests.swift +++ b/Tests/CorePromise/LoggingTests.swift @@ -1,6 +1,9 @@ @testable import PromiseKit import Dispatch import XCTest +#if canImport(Android) +import Android +#endif class LoggingTests: XCTestCase { /** diff --git a/Tests/CorePromise/ResolverTests.swift b/Tests/CorePromise/ResolverTests.swift index 63b35322d..76f2057d5 100644 --- a/Tests/CorePromise/ResolverTests.swift +++ b/Tests/CorePromise/ResolverTests.swift @@ -131,13 +131,13 @@ class WrapTests: XCTestCase { let ex1 = expectation(description: "") let kf1 = KittenFetcher(value: nil, error: nil) Promise { seal in - kf1.fetchWithCompletionBlock4(block: seal.resolve) - }.done(ex1.fulfill).silenceWarning() + kf1.fetchWithCompletionBlock4(block: { seal.resolve($0) }) + }.done({ ex1.fulfill() }).silenceWarning() let ex2 = expectation(description: "") let kf2 = KittenFetcher(value: nil, error: Error.test) Promise { seal in - kf2.fetchWithCompletionBlock4(block: seal.resolve) + kf2.fetchWithCompletionBlock4(block: { seal.resolve($0) }) }.catch { _ in ex2.fulfill() } wait(for: [ex1, ex2], timeout: 1) @@ -182,7 +182,10 @@ class WrapTests: XCTestCase { XCTAssertFalse(Promise(error: Error.test).result?.isFulfilled ?? true) } - func testPendingPromiseDeallocated() { + func testPendingPromiseDeallocated() throws { + #if os(Android) + throw XCTSkip() + #endif // NOTE this doesn't seem to register the `deinit` as covered :( // BUT putting a breakpoint in the deinit CLEARLY shows it getting covered… @@ -192,7 +195,7 @@ class WrapTests: XCTestCase { var ex: XCTestExpectation! deinit { - after(.milliseconds(100)).done(ex.fulfill) + after(.milliseconds(100)).done({ self.ex.fulfill() }) } } diff --git a/Tests/CorePromise/StressTests.swift b/Tests/CorePromise/StressTests.swift index 787e485d0..011603d9a 100644 --- a/Tests/CorePromise/StressTests.swift +++ b/Tests/CorePromise/StressTests.swift @@ -74,5 +74,5 @@ private func stressDataRace(expectation e1: XCTestExpectation, ite } } - group.notify(queue: queue, execute: e1.fulfill) + group.notify(queue: queue, execute: { e1.fulfill() }) } diff --git a/Tests/CorePromise/WhenTests.swift b/Tests/CorePromise/WhenTests.swift index d1efd74a9..599628fd7 100644 --- a/Tests/CorePromise/WhenTests.swift +++ b/Tests/CorePromise/WhenTests.swift @@ -124,7 +124,7 @@ class WhenTests: XCTestCase { let p3 = Promise.value(3).done { _ in } let p4 = Promise.value(4).done { _ in } - when(fulfilled: p1, p2, p3, p4).done(e1.fulfill).silenceWarning() + when(fulfilled: p1, p2, p3, p4).done({ e1.fulfill() }).silenceWarning() waitForExpectations(timeout: 1, handler: nil) } @@ -244,8 +244,8 @@ class WhenTests: XCTestCase { ex1.fulfill() } - p2.ensure { after(.milliseconds(100)).done(ex2.fulfill) }.silenceWarning() - p3.ensure { after(.milliseconds(100)).done(ex3.fulfill) }.silenceWarning() + p2.ensure { after(.milliseconds(100)).done({ ex2.fulfill() }) }.silenceWarning() + p3.ensure { after(.milliseconds(100)).done({ ex3.fulfill() }) }.silenceWarning() waitForExpectations(timeout: 1, handler: nil) } From 700dafcc2a7d63f58f68ac1986d6ff4dc09e1a1a Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 4 Jan 2025 20:38:59 -0500 Subject: [PATCH 2/3] Update CI for Android --- Tests/CorePromise/ResolverTests.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Tests/CorePromise/ResolverTests.swift b/Tests/CorePromise/ResolverTests.swift index 76f2057d5..3e5bc3dd7 100644 --- a/Tests/CorePromise/ResolverTests.swift +++ b/Tests/CorePromise/ResolverTests.swift @@ -183,10 +183,7 @@ class WrapTests: XCTestCase { } func testPendingPromiseDeallocated() throws { - #if os(Android) - throw XCTSkip() - #endif - + #if !os(Android) // NOTE this doesn't seem to register the `deinit` as covered :( // BUT putting a breakpoint in the deinit CLEARLY shows it getting covered… @@ -195,7 +192,7 @@ class WrapTests: XCTestCase { var ex: XCTestExpectation! deinit { - after(.milliseconds(100)).done({ self.ex.fulfill() }) + after(.milliseconds(100)).done(ex.fulfill) } } @@ -206,6 +203,7 @@ class WrapTests: XCTestCase { foo.ex = ex } wait(for: [ex], timeout: 10) + #endif } func testVoidResolverFulfillAmbiguity() { From 6d067d7a25e182fbc03c160a39e32397110ae5b4 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 4 Jan 2025 21:02:51 -0500 Subject: [PATCH 3/3] Update Android CI --- Tests/A+/2.1.2.swift | 6 +++--- Tests/A+/2.1.3.swift | 8 ++++---- Tests/A+/2.2.2.swift | 20 ++++++++++---------- Tests/A+/2.2.3.swift | 2 +- Tests/A+/XCTestManifests.swift | 8 ++++++++ Tests/CorePromise/AfterTests.swift | 12 ++++++------ Tests/CorePromise/CatchableTests.swift | 6 +++--- Tests/CorePromise/ResolverTests.swift | 11 +++++------ Tests/CorePromise/StressTests.swift | 2 +- Tests/CorePromise/Utilities.swift | 2 +- Tests/CorePromise/WhenTests.swift | 6 +++--- 11 files changed, 45 insertions(+), 38 deletions(-) diff --git a/Tests/A+/2.1.2.swift b/Tests/A+/2.1.2.swift index fffadb847..c895c2f93 100644 --- a/Tests/A+/2.1.2.swift +++ b/Tests/A+/2.1.2.swift @@ -5,17 +5,17 @@ class Test212: XCTestCase { func test() { describe("2.1.2.1: When fulfilled, a promise: must not transition to any other state.") { testFulfilled { promise, expectation, _ in - promise.test(onFulfilled: { expectation.fulfill() }, onRejected: { XCTFail() }) + promise.test(onFulfilled: expectation.fulfill, onRejected: { XCTFail() }) } specify("trying to fulfill then immediately reject") { d, expectation in - d.promise.test(onFulfilled: { expectation.fulfill() }, onRejected: { XCTFail() }) + d.promise.test(onFulfilled: expectation.fulfill, onRejected: { XCTFail() }) d.fulfill() d.reject(Error.dummy) } specify("trying to fulfill then reject, delayed") { d, expectation in - d.promise.test(onFulfilled: { expectation.fulfill() }, onRejected: { XCTFail() }) + d.promise.test(onFulfilled: expectation.fulfill, onRejected: { XCTFail() }) after(ticks: 1) { d.fulfill() d.reject(Error.dummy) diff --git a/Tests/A+/2.1.3.swift b/Tests/A+/2.1.3.swift index b0ac08e17..d24ae683f 100644 --- a/Tests/A+/2.1.3.swift +++ b/Tests/A+/2.1.3.swift @@ -5,17 +5,17 @@ class Test213: XCTestCase { func test() { describe("2.1.3.1: When rejected, a promise: must not transition to any other state.") { testRejected { promise, expectation, _ in - promise.test(onFulfilled: { XCTFail() }, onRejected: { expectation.fulfill() }) + promise.test(onFulfilled: { XCTFail() }, onRejected: expectation.fulfill) } specify("trying to reject then immediately fulfill") { d, expectation in - d.promise.test(onFulfilled: { XCTFail() }, onRejected: { expectation.fulfill() }) + d.promise.test(onFulfilled: { XCTFail() }, onRejected: expectation.fulfill) d.reject(Error.dummy) d.fulfill() } specify("trying to reject then fulfill, delayed") { d, expectation in - d.promise.test(onFulfilled: { XCTFail() }, onRejected: { expectation.fulfill() }) + d.promise.test(onFulfilled: { XCTFail() }, onRejected: expectation.fulfill) after(ticks: 1) { d.reject(Error.dummy) d.fulfill() @@ -23,7 +23,7 @@ class Test213: XCTestCase { } specify("trying to reject immediately then fulfill delayed") { d, expectation in - d.promise.test(onFulfilled: { XCTFail() }, onRejected: { expectation.fulfill() }) + d.promise.test(onFulfilled: { XCTFail() }, onRejected: expectation.fulfill) d.reject(Error.dummy) after(ticks: 1) { d.fulfill() diff --git a/Tests/A+/2.2.2.swift b/Tests/A+/2.2.2.swift index 6c4b45aaa..f1ba89917 100644 --- a/Tests/A+/2.2.2.swift +++ b/Tests/A+/2.2.2.swift @@ -27,7 +27,7 @@ class Test222: XCTestCase { } specify("never fulfilled") { d, expectation in d.promise.done{ XCTFail() }.silenceWarning() - after(ticks: 1000, execute: { expectation.fulfill() }) + after(ticks: 1000, execute: expectation.fulfill) } } @@ -42,12 +42,12 @@ class Test222: XCTestCase { } } specify("trying to fulfill a pending promise more than once, immediately") { d, expectation in - d.promise.done({ expectation.fulfill() }).silenceWarning() + d.promise.done(expectation.fulfill).silenceWarning() d.fulfill() d.fulfill() } specify("trying to fulfill a pending promise more than once, delayed") { d, expectation in - d.promise.done({ expectation.fulfill() }).silenceWarning() + d.promise.done(expectation.fulfill).silenceWarning() after(ticks: 5) { d.fulfill() d.fulfill() @@ -55,24 +55,24 @@ class Test222: XCTestCase { } specify("trying to fulfill a pending promise more than once, immediately then delayed") { d, expectation in let ex = (expectation, mkex()) - d.promise.done({ ex.0.fulfill() }).silenceWarning() + d.promise.done(ex.0.fulfill).silenceWarning() d.fulfill() after(ticks: 5) { d.fulfill() } - after(ticks: 10, execute: { ex.1.fulfill() }) + after(ticks: 10, execute: ex.1.fulfill) } specify("when multiple `then` calls are made, spaced apart in time") { d, expectation in let ex = (expectation, self.expectation(description: ""), self.expectation(description: ""), self.expectation(description: "")) do { - d.promise.done({ ex.0.fulfill() }).silenceWarning() + d.promise.done(ex.0.fulfill).silenceWarning() } after(ticks: 5) { - d.promise.done({ ex.1.fulfill() }).silenceWarning() + d.promise.done(ex.1.fulfill).silenceWarning() } after(ticks: 10) { - d.promise.done({ ex.2.fulfill() }).silenceWarning() + d.promise.done(ex.2.fulfill).silenceWarning() } after(ticks: 15) { d.fulfill() @@ -82,9 +82,9 @@ class Test222: XCTestCase { specify("when `then` is interleaved with fulfillment") { d, expectation in let ex = (expectation, self.expectation(description: ""), self) - d.promise.done({ ex.0.fulfill() }).silenceWarning() + d.promise.done(ex.0.fulfill).silenceWarning() d.fulfill() - d.promise.done({ ex.1.fulfill() }).silenceWarning() + d.promise.done(ex.1.fulfill).silenceWarning() } } } diff --git a/Tests/A+/2.2.3.swift b/Tests/A+/2.2.3.swift index 161923309..996d6a226 100644 --- a/Tests/A+/2.2.3.swift +++ b/Tests/A+/2.2.3.swift @@ -30,7 +30,7 @@ class Test223: XCTestCase { } specify("never rejected") { d, expectation in d.promise.catch { _ in XCTFail() } - after(ticks: 1, execute: { expectation.fulfill() }) + after(ticks: 1, execute: expectation.fulfill) } } describe("2.2.3.3: it must not be called more than once.") { diff --git a/Tests/A+/XCTestManifests.swift b/Tests/A+/XCTestManifests.swift index 5f78de59e..47a695d91 100644 --- a/Tests/A+/XCTestManifests.swift +++ b/Tests/A+/XCTestManifests.swift @@ -1,6 +1,14 @@ #if !canImport(ObjectiveC) import XCTest +#if os(Linux) || os(Android) +extension XCTestExpectation { + func fulfill() { + fulfill(#file, line: #line) + } +} +#endif + extension Test212 { // DO NOT MODIFY: This is autogenerated, use: // `swift test --generate-linuxmain` diff --git a/Tests/CorePromise/AfterTests.swift b/Tests/CorePromise/AfterTests.swift index 314700ba5..6b587c954 100644 --- a/Tests/CorePromise/AfterTests.swift +++ b/Tests/CorePromise/AfterTests.swift @@ -4,11 +4,11 @@ import XCTest class AfterTests: XCTestCase { func testZero() { let ex2 = expectation(description: "") - after(seconds: 0).done({ ex2.fulfill() }) + after(seconds: 0).done(ex2.fulfill) waitForExpectations(timeout: 2, handler: nil) let ex3 = expectation(description: "") - after(.seconds(0)).done({ ex3.fulfill() }) + after(.seconds(0)).done(ex3.fulfill) waitForExpectations(timeout: 2, handler: nil) #if !SWIFT_PACKAGE @@ -20,11 +20,11 @@ class AfterTests: XCTestCase { func testNegative() { let ex2 = expectation(description: "") - after(seconds: -1).done({ ex2.fulfill() }) + after(seconds: -1).done(ex2.fulfill) waitForExpectations(timeout: 2, handler: nil) let ex3 = expectation(description: "") - after(.seconds(-1)).done({ ex3.fulfill() }) + after(.seconds(-1)).done(ex3.fulfill) waitForExpectations(timeout: 2, handler: nil) #if !SWIFT_PACKAGE @@ -36,11 +36,11 @@ class AfterTests: XCTestCase { func testPositive() { let ex2 = expectation(description: "") - after(seconds: 1).done({ ex2.fulfill() }) + after(seconds: 1).done(ex2.fulfill) waitForExpectations(timeout: 2, handler: nil) let ex3 = expectation(description: "") - after(.seconds(1)).done({ ex3.fulfill() }) + after(.seconds(1)).done(ex3.fulfill) waitForExpectations(timeout: 2, handler: nil) #if !SWIFT_PACKAGE diff --git a/Tests/CorePromise/CatchableTests.swift b/Tests/CorePromise/CatchableTests.swift index d1f0a5cb4..d94b2b6f5 100644 --- a/Tests/CorePromise/CatchableTests.swift +++ b/Tests/CorePromise/CatchableTests.swift @@ -55,7 +55,7 @@ extension CatchableTests { func helper(error: Swift.Error) { let ex = expectation(description: "") - Promise(error: error).recover { _ in }.done({ ex.fulfill() }) + Promise(error: error).recover { _ in }.done(ex.fulfill) wait(for: [ex], timeout: 10) } @@ -65,7 +65,7 @@ extension CatchableTests { func test__void_specialized_full_recover__fulfilled_path() { let ex = expectation(description: "") - Promise().recover { _ in XCTFail() }.done({ ex.fulfill() }) + Promise().recover { _ in XCTFail() }.done(ex.fulfill) wait(for: [ex], timeout: 10) } @@ -76,7 +76,7 @@ extension CatchableTests { Promise(error: error).recover(policy: policy) { err in guard x < 1 else { throw err } x += 1 - }.done({ ex.fulfill() }).silenceWarning() + }.done(ex.fulfill).silenceWarning() wait(for: [ex], timeout: 10) } diff --git a/Tests/CorePromise/ResolverTests.swift b/Tests/CorePromise/ResolverTests.swift index 3e5bc3dd7..63b35322d 100644 --- a/Tests/CorePromise/ResolverTests.swift +++ b/Tests/CorePromise/ResolverTests.swift @@ -131,13 +131,13 @@ class WrapTests: XCTestCase { let ex1 = expectation(description: "") let kf1 = KittenFetcher(value: nil, error: nil) Promise { seal in - kf1.fetchWithCompletionBlock4(block: { seal.resolve($0) }) - }.done({ ex1.fulfill() }).silenceWarning() + kf1.fetchWithCompletionBlock4(block: seal.resolve) + }.done(ex1.fulfill).silenceWarning() let ex2 = expectation(description: "") let kf2 = KittenFetcher(value: nil, error: Error.test) Promise { seal in - kf2.fetchWithCompletionBlock4(block: { seal.resolve($0) }) + kf2.fetchWithCompletionBlock4(block: seal.resolve) }.catch { _ in ex2.fulfill() } wait(for: [ex1, ex2], timeout: 1) @@ -182,8 +182,8 @@ class WrapTests: XCTestCase { XCTAssertFalse(Promise(error: Error.test).result?.isFulfilled ?? true) } - func testPendingPromiseDeallocated() throws { - #if !os(Android) + func testPendingPromiseDeallocated() { + // NOTE this doesn't seem to register the `deinit` as covered :( // BUT putting a breakpoint in the deinit CLEARLY shows it getting covered… @@ -203,7 +203,6 @@ class WrapTests: XCTestCase { foo.ex = ex } wait(for: [ex], timeout: 10) - #endif } func testVoidResolverFulfillAmbiguity() { diff --git a/Tests/CorePromise/StressTests.swift b/Tests/CorePromise/StressTests.swift index 011603d9a..787e485d0 100644 --- a/Tests/CorePromise/StressTests.swift +++ b/Tests/CorePromise/StressTests.swift @@ -74,5 +74,5 @@ private func stressDataRace(expectation e1: XCTestExpectation, ite } } - group.notify(queue: queue, execute: { e1.fulfill() }) + group.notify(queue: queue, execute: e1.fulfill) } diff --git a/Tests/CorePromise/Utilities.swift b/Tests/CorePromise/Utilities.swift index 6e9bce694..a83c2cc29 100644 --- a/Tests/CorePromise/Utilities.swift +++ b/Tests/CorePromise/Utilities.swift @@ -4,7 +4,7 @@ extension Promise { func silenceWarning() {} } -#if os(Linux) +#if os(Linux) || os(Android) import func CoreFoundation._CFIsMainThread extension Thread { diff --git a/Tests/CorePromise/WhenTests.swift b/Tests/CorePromise/WhenTests.swift index 599628fd7..d1efd74a9 100644 --- a/Tests/CorePromise/WhenTests.swift +++ b/Tests/CorePromise/WhenTests.swift @@ -124,7 +124,7 @@ class WhenTests: XCTestCase { let p3 = Promise.value(3).done { _ in } let p4 = Promise.value(4).done { _ in } - when(fulfilled: p1, p2, p3, p4).done({ e1.fulfill() }).silenceWarning() + when(fulfilled: p1, p2, p3, p4).done(e1.fulfill).silenceWarning() waitForExpectations(timeout: 1, handler: nil) } @@ -244,8 +244,8 @@ class WhenTests: XCTestCase { ex1.fulfill() } - p2.ensure { after(.milliseconds(100)).done({ ex2.fulfill() }) }.silenceWarning() - p3.ensure { after(.milliseconds(100)).done({ ex3.fulfill() }) }.silenceWarning() + p2.ensure { after(.milliseconds(100)).done(ex2.fulfill) }.silenceWarning() + p3.ensure { after(.milliseconds(100)).done(ex3.fulfill) }.silenceWarning() waitForExpectations(timeout: 1, handler: nil) }