Skip to content

Commit

Permalink
Merge branch 'main' into rename_predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
younata authored Sep 27, 2023
2 parents 50521d5 + 67aca90 commit 2a4cc4c
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 21 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci-swiftpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,16 @@ jobs:
- uses: actions/checkout@v4
- run: swift build -Xswiftc -suppress-warnings
- run: swift test -Xswiftc -suppress-warnings --enable-test-discovery

swiftpm_windows:
name: SwiftPM, Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Install Swift
uses: compnerd/gha-setup-swift@main
with:
branch: swift-5.9-release
tag: 5.9-RELEASE
- name: Test Windows
run: swift test -Xswiftc -suppress-warnings
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# A sample Gemfile
source "https://rubygems.org"

gem 'cocoapods', '~> 1.12'
gem 'cocoapods', '~> 1.13'
22 changes: 11 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ GEM
specs:
CFPropertyList (3.0.6)
rexml
activesupport (7.0.7.2)
activesupport (7.0.8)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.4)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.1.0)
cocoapods (1.12.1)
cocoapods (1.13.0)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.12.1)
cocoapods-core (= 1.13.0)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.6.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
Expand All @@ -32,8 +32,8 @@ GEM
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.21.0, < 2.0)
cocoapods-core (1.12.1)
xcodeproj (>= 1.23.0, < 2.0)
cocoapods-core (1.13.0)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
Expand All @@ -57,27 +57,27 @@ GEM
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.15.5)
ffi (1.16.1)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
minitest (5.19.0)
minitest (5.20.0)
molinillo (0.8.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.7)
rexml (3.2.5)
rexml (3.2.6)
ruby-macho (2.5.1)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcodeproj (1.22.0)
xcodeproj (1.23.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
Expand All @@ -89,7 +89,7 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (~> 1.12)
cocoapods (~> 1.13)

BUNDLED WITH
2.1.4
4 changes: 4 additions & 0 deletions Sources/Nimble/Matchers/PostNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ internal class NotificationCollector {
}
}

#if !os(Windows)
private let mainThread = pthread_self()
#else
private let mainThread = Thread.mainThread
#endif

private func _postNotifications<Out>(
_ matcher: Matcher<[Notification]>,
Expand Down
3 changes: 3 additions & 0 deletions Sources/Nimble/Utils/AsyncAwait.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#if !os(WASI)

#if canImport(CoreFoundation)
import CoreFoundation
#endif

import Dispatch
import Foundation

Expand Down
2 changes: 2 additions & 0 deletions Sources/Nimble/Utils/AsyncTimerSequence.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#if !os(WASI)

#if canImport(CoreFoundation)
import CoreFoundation
#endif
import Dispatch
import Foundation

Expand Down
33 changes: 33 additions & 0 deletions Sources/Nimble/Utils/PollAwait.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#if !os(WASI)

#if canImport(CoreFoundation)
import CoreFoundation
#endif
import Dispatch
import Foundation

Expand Down Expand Up @@ -192,6 +194,7 @@ internal class AwaitPromiseBuilder<T> {
let timedOutSem = DispatchSemaphore(value: 0)
let semTimedOutOrBlocked = DispatchSemaphore(value: 0)
semTimedOutOrBlocked.signal()
#if canImport(CoreFoundation)
let runLoop = CFRunLoopGetMain()
#if canImport(Darwin)
let runLoopMode = CFRunLoopMode.defaultMode.rawValue
Expand All @@ -209,12 +212,30 @@ internal class AwaitPromiseBuilder<T> {
}
// potentially interrupt blocking code on run loop to let timeout code run
CFRunLoopStop(runLoop)
#else
let runLoop = RunLoop.main
runLoop.perform(inModes: [.default], block: {
if semTimedOutOrBlocked.wait(timeout: .now()) == .success {
timedOutSem.signal()
semTimedOutOrBlocked.signal()
if self.promise.resolveResult(.timedOut) {
RunLoop.main._stop()
}
}
})
// potentially interrupt blocking code on run loop to let timeout code run
runLoop._stop()
#endif
let now = DispatchTime.now() + forcefullyAbortTimeout.dispatchTimeInterval
let didNotTimeOut = timedOutSem.wait(timeout: now) != .success
let timeoutWasNotTriggered = semTimedOutOrBlocked.wait(timeout: .now()) == .success
if didNotTimeOut && timeoutWasNotTriggered {
if self.promise.resolveResult(.blockedRunLoop) {
#if canImport(CoreFoundation)
CFRunLoopStop(CFRunLoopGetMain())
#else
RunLoop.main._stop()
#endif
}
}
}
Expand Down Expand Up @@ -302,7 +323,11 @@ internal class Awaiter {
if completionCount < 2 {
func completeBlock() {
if promise.resolveResult(.completed(result)) {
#if canImport(CoreFoundation)
CFRunLoopStop(CFRunLoopGetMain())
#else
RunLoop.main._stop()
#endif
}
}

Expand Down Expand Up @@ -340,12 +365,20 @@ internal class Awaiter {
do {
if let result = try closure() {
if promise.resolveResult(.completed(result)) {
#if canImport(CoreFoundation)
CFRunLoopStop(CFRunLoopGetCurrent())
#else
RunLoop.current._stop()
#endif
}
}
} catch let error {
if promise.resolveResult(.errorThrown(error)) {
#if canImport(CoreFoundation)
CFRunLoopStop(CFRunLoopGetCurrent())
#else
RunLoop.current._stop()
#endif
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/NimbleTests/AsyncAwaitTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final class AsyncAwaitTest: XCTestCase { // swiftlint:disable:this type_body_len
@MainActor
func testToEventuallyOnMain() async {
await expect(1).toEventually(equal(1), timeout: .seconds(300))
await expect { usleep(10); return 1 }.toEventually(equal(1))
await expect { try? await Task.sleep(nanoseconds: 10_000); return 1 }.toEventually(equal(1))
}

@MainActor
Expand Down
16 changes: 8 additions & 8 deletions Tests/NimbleTests/Matchers/ThrowAssertionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ private let error: Error = NSError(domain: "test", code: 0, userInfo: nil)

final class ThrowAssertionTest: XCTestCase {
func testPositiveMatch() {
#if arch(x86_64) || arch(arm64)
#if (arch(x86_64) || arch(arm64)) && !os(Windows)
expect { () -> Void in fatalError() }.to(throwAssertion())
#endif
}

func testErrorThrown() {
#if arch(x86_64) || arch(arm64)
#if (arch(x86_64) || arch(arm64)) && !os(Windows)
expect { throw error }.toNot(throwAssertion())
#endif
}

func testPostAssertionCodeNotRun() {
#if arch(x86_64) || arch(arm64)
#if (arch(x86_64) || arch(arm64)) && !os(Windows)
var reachedPoint1 = false
var reachedPoint2 = false

Expand All @@ -37,7 +37,7 @@ final class ThrowAssertionTest: XCTestCase {
}

func testNegativeMatch() {
#if arch(x86_64) || arch(arm64)
#if (arch(x86_64) || arch(arm64)) && !os(Windows)
var reachedPoint1 = false

expect { reachedPoint1 = true }.toNot(throwAssertion())
Expand All @@ -47,7 +47,7 @@ final class ThrowAssertionTest: XCTestCase {
}

func testPositiveMessage() {
#if arch(x86_64) || arch(arm64)
#if (arch(x86_64) || arch(arm64)) && !os(Windows)
failsWithErrorMessage("expected to throw an assertion") {
expect { () -> Void? in return }.to(throwAssertion())
}
Expand All @@ -59,21 +59,21 @@ final class ThrowAssertionTest: XCTestCase {
}

func testNegativeMessage() {
#if arch(x86_64) || arch(arm64)
#if (arch(x86_64) || arch(arm64)) && !os(Windows)
failsWithErrorMessage("expected to not throw an assertion") {
expect { () -> Void in fatalError() }.toNot(throwAssertion())
}
#endif
}

func testNonVoidClosure() {
#if arch(x86_64) || arch(arm64)
#if (arch(x86_64) || arch(arm64)) && !os(Windows)
expect { () -> Int in fatalError() }.to(throwAssertion())
#endif
}

func testChainOnThrowAssertion() {
#if arch(x86_64) || arch(arm64)
#if (arch(x86_64) || arch(arm64)) && !os(Windows)
expect { () -> Int in return 5 }.toNot(throwAssertion()).to(equal(5))
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/NimbleTests/PollingTest.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#if !os(WASI)

import Dispatch
#if canImport(CoreFoundation)
import CoreFoundation
#endif
import Foundation
import XCTest
import Nimble
Expand Down

0 comments on commit 2a4cc4c

Please sign in to comment.