Skip to content

Commit e773081

Browse files
authored
Merge pull request #621 from Quick/7.x-pr619
[7.x] Fix Swift 4.2 compatibility on Linux
2 parents cd6dfb8 + c381428 commit e773081

File tree

6 files changed

+78
-9
lines changed

6 files changed

+78
-9
lines changed

.travis.yml

+31-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@ matrix:
2626
- os: osx
2727
env: TYPE=macos
2828
osx_image: xcode9.4
29+
- os: osx
30+
env: TYPE=macos
31+
osx_image: xcode10.1
2932
- os: osx
3033
env: TYPE=swiftpm
3134
- os: osx
3235
env: TYPE=swiftpm
3336
osx_image: xcode9
37+
- os: osx
38+
env: TYPE=swiftpm
39+
osx_image: xcode10.1
3440
- os: linux
3541
dist: trusty
3642
sudo: required
@@ -42,9 +48,33 @@ matrix:
4248
sudo: required
4349
env:
4450
- TYPE=swiftpm
45-
- SWIFT_VERSION=4.0.2
51+
- SWIFT_VERSION=4.0.3
52+
install:
53+
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
54+
- os: linux
55+
dist: trusty
56+
sudo: required
57+
env:
58+
- TYPE=swiftpm
59+
- SWIFT_VERSION=4.1.3
60+
install:
61+
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
62+
- os: linux
63+
dist: trusty
64+
sudo: required
65+
env:
66+
- TYPE=swiftpm
67+
- SWIFT_VERSION=4.2.1
4668
install:
4769
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
70+
# - os: linux
71+
# dist: trusty
72+
# sudo: required
73+
# env:
74+
# - TYPE=swiftpm
75+
# - SWIFT_VERSION=5.0-DEVELOPMENT-SNAPSHOT-2019-01-13-a
76+
# install:
77+
# - eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
4878
install:
4979
- if [[ "$TYPE" == "podspec" ]]; then sudo gem install bundler; bundle install; fi
5080
script:

Sources/Nimble/Adapters/NimbleEnvironment.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33

44
/// "Global" state of Nimble is stored here. Only DSL functions should access / be aware of this
55
/// class' existence
6-
internal class NimbleEnvironment {
6+
internal class NimbleEnvironment: NSObject {
77
static var activeInstance: NimbleEnvironment {
88
get {
99
let env = Thread.current.threadDictionary["NimbleEnvironment"]
@@ -29,7 +29,7 @@ internal class NimbleEnvironment {
2929
var suppressTVOSAssertionWarning: Bool = false
3030
var awaiter: Awaiter
3131

32-
init() {
32+
override init() {
3333
let timeoutQueue: DispatchQueue
3434
if #available(OSX 10.10, *) {
3535
timeoutQueue = DispatchQueue.global(qos: .userInitiated)
@@ -40,6 +40,9 @@ internal class NimbleEnvironment {
4040
awaiter = Awaiter(
4141
waitLock: AssertionWaitLock(),
4242
asyncQueue: .main,
43-
timeoutQueue: timeoutQueue)
43+
timeoutQueue: timeoutQueue
44+
)
45+
46+
super.init()
4447
}
4548
}

Sources/Nimble/Matchers/BeIdenticalTo.swift

+26-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,38 @@ import Foundation
55
public func beIdenticalTo(_ expected: Any?) -> Predicate<Any> {
66
return Predicate.define { actualExpression in
77
#if os(Linux)
8-
let actual = try actualExpression.evaluate() as? AnyObject
8+
#if swift(>=4.0)
9+
#if !swift(>=4.1.50)
10+
let actual = try actualExpression.evaluate() as? AnyObject
11+
#else
12+
let actual = try actualExpression.evaluate() as AnyObject?
13+
#endif
14+
#else
15+
#if !swift(>=3.4)
16+
let actual = try actualExpression.evaluate() as? AnyObject
17+
#else
18+
let actual = try actualExpression.evaluate() as AnyObject?
19+
#endif
20+
#endif
921
#else
1022
let actual = try actualExpression.evaluate() as AnyObject?
1123
#endif
1224

1325
let bool: Bool
1426
#if os(Linux)
15-
bool = actual === (expected as? AnyObject) && actual !== nil
27+
#if swift(>=4.0)
28+
#if !swift(>=4.1.50)
29+
bool = actual === (expected as? AnyObject) && actual !== nil
30+
#else
31+
bool = actual === (expected as AnyObject?) && actual !== nil
32+
#endif
33+
#else
34+
#if !swift(>=3.4)
35+
bool = actual === (expected as? AnyObject) && actual !== nil
36+
#else
37+
bool = actual === (expected as AnyObject?) && actual !== nil
38+
#endif
39+
#endif
1640
#else
1741
bool = actual === (expected as AnyObject?) && actual !== nil
1842
#endif

Sources/Nimble/Utils/Await.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ internal class AwaitPromiseBuilder<T> {
263263
self.trigger.timeoutSource.resume()
264264
while self.promise.asyncResult.isIncomplete() {
265265
// Stopping the run loop does not work unless we run only 1 mode
266-
#if swift(>=4.2)
266+
#if swift(>=4.2) && (os(macOS) || os(iOS) || os(tvOS))
267267
_ = RunLoop.current.run(mode: .default, before: .distantFuture)
268268
#else
269269
_ = RunLoop.current.run(mode: .defaultRunLoopMode, before: .distantFuture)

Sources/Nimble/Utils/Stringers.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@ import Foundation
33
internal func identityAsString(_ value: Any?) -> String {
44
let anyObject: AnyObject?
55
#if os(Linux)
6-
anyObject = value as? AnyObject
6+
#if swift(>=4.0)
7+
#if !swift(>=4.1.50)
8+
anyObject = value as? AnyObject
9+
#else
10+
anyObject = value as AnyObject?
11+
#endif
12+
#else
13+
#if !swift(>=3.4)
14+
anyObject = value as? AnyObject
15+
#else
16+
anyObject = value as AnyObject?
17+
#endif
18+
#endif
719
#else
820
anyObject = value as AnyObject?
921
#endif

test

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function test_podspec {
8080

8181
function test_swiftpm {
8282
if [ -d .build ]; then
83-
run swift build --clean
83+
run swift build --clean || swift package clean
8484
fi
8585
run swift build && swift test
8686
}

0 commit comments

Comments
 (0)