Skip to content

Commit 997d6e6

Browse files
authored
Merge pull request #52 from CodaFi/fourt-sumter
Update to Swift 4.0
2 parents 6904e7a + 1deea5d commit 997d6e6

33 files changed

+291
-211
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ DerivedData
1919
*.xcuserstate
2020
*.xcscmblueprint
2121
Carthage/
22+
Package.resolved
2223

2324
# CocoaPods
2425
#

.travis.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ matrix:
55
include:
66
- os: osx
77
language: objective-c
8-
osx_image: xcode8.3
8+
osx_image: xcode9
99
before_install:
1010
- git submodule update --init --recursive
1111
script:
@@ -14,7 +14,7 @@ matrix:
1414
- carthage build --no-skip-current
1515
- os: osx
1616
language: objective-c
17-
osx_image: xcode8.3
17+
osx_image: xcode9
1818
before_install:
1919
- git submodule update --init --recursive
2020
script:
@@ -37,11 +37,11 @@ matrix:
3737
before_install:
3838
- git submodule update --init --recursive
3939
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
40-
- wget https://swift.org/builds/swift-3.1-release/ubuntu1404/swift-3.1-RELEASE/swift-3.1-RELEASE-ubuntu14.04.tar.gz
41-
- tar xzf swift-3.1-RELEASE-ubuntu14.04.tar.gz
42-
- export PATH=${PWD}/swift-3.1-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
40+
- wget https://swift.org/builds/swift-4.0-release/ubuntu1404/swift-4.0-RELEASE/swift-4.0-RELEASE-ubuntu14.04.tar.gz
41+
- tar xzf swift-4.0-RELEASE-ubuntu14.04.tar.gz
42+
- export PATH=${PWD}/swift-4.0-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
4343
script:
44-
- swift build
44+
- swift test
4545
notifications:
4646
webhooks:
4747
urls:

Cartfile.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "typelift/SwiftCheck" "0.8.0"
1+
github "typelift/SwiftCheck" "0.8.1"

Concurrent.xcodeproj/project.pbxproj

+169-164
Large diffs are not rendered by default.

Concurrent.xcodeproj/xcshareddata/xcschemes/Concurrent-iOS.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -40,6 +40,7 @@
4040
buildConfiguration = "Debug"
4141
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4242
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43+
language = ""
4344
shouldUseLaunchSchemeArgsEnv = "YES">
4445
<Testables>
4546
<TestableReference
@@ -69,6 +70,7 @@
6970
buildConfiguration = "Debug"
7071
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
7172
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
73+
language = ""
7274
launchStyle = "0"
7375
useCustomWorkingDirectory = "NO"
7476
ignoresPersistentStateOnLaunch = "NO"

Concurrent.xcodeproj/xcshareddata/xcschemes/Concurrent-tvOS.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
<TestableReference
@@ -55,6 +56,7 @@
5556
buildConfiguration = "Debug"
5657
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5758
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
59+
language = ""
5860
launchStyle = "0"
5961
useCustomWorkingDirectory = "NO"
6062
ignoresPersistentStateOnLaunch = "NO"

Concurrent.xcodeproj/xcshareddata/xcschemes/Concurrent-watchOS.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
</Testables>
@@ -36,6 +37,7 @@
3637
buildConfiguration = "Debug"
3738
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3839
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
40+
language = ""
3941
launchStyle = "0"
4042
useCustomWorkingDirectory = "NO"
4143
ignoresPersistentStateOnLaunch = "NO"

Concurrent.xcodeproj/xcshareddata/xcschemes/Concurrent.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -40,6 +40,7 @@
4040
buildConfiguration = "Debug"
4141
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4242
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43+
language = ""
4344
shouldUseLaunchSchemeArgsEnv = "YES">
4445
<Testables>
4546
<TestableReference
@@ -69,6 +70,7 @@
6970
buildConfiguration = "Debug"
7071
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
7172
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
73+
language = ""
7274
launchStyle = "0"
7375
useCustomWorkingDirectory = "NO"
7476
ignoresPersistentStateOnLaunch = "NO"

Package.swift

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
// swift-tools-version:4.0
2+
13
import PackageDescription
24

35
let package = Package(
4-
name: "Concurrent",
5-
targets: [
6-
Target(
7-
name: "Concurrent",
8-
dependencies: []),
9-
]
6+
name: "Concurrent",
7+
products: [
8+
.library(
9+
name: "Concurrent",
10+
targets: ["Concurrent"]),
11+
],
12+
dependencies: [
13+
.package(url: "https://github.com/typelift/SwiftCheck.git", .branch("master"))
14+
],
15+
targets: [
16+
.target(
17+
name: "Concurrent"),
18+
.testTarget(
19+
name: "ConcurrentTests",
20+
dependencies: ["Concurrent", "SwiftCheck"]),
21+
]
1022
)
1123

12-
let libConcurrent = Product(name: "Concurrent", type: .Library(.Dynamic), modules: "Concurrent")
13-
products.append(libConcurrent)
File renamed without changes.
File renamed without changes.
File renamed without changes.

Sources/MVar.swift Sources/Concurrent/MVar.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ public final class MVar<A> {
148148
return (self.val == nil)
149149
}
150150

151-
/// Atomically, take a value from the `MVar`, put a given new value in the
151+
/// Take a value from the `MVar`, put a given new value in the
152152
/// `MVar`, then return the `MVar`'s old value.
153+
///
154+
/// This operation is atomic only if no writes occur during its execution.
153155
public func swap(_ x : A) -> A {
154156
let old = self.take()
155157
self.put(x)
File renamed without changes.
File renamed without changes.

Sources/SVar.swift Sources/Concurrent/SVar.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public struct SVar<A> {
4747
let (readers, val) = s
4848
if readers > 0 {
4949
let _ = val.take()
50-
self.svar.put((Int.allZeros, val))
50+
self.svar.put((0, val))
5151
} else {
5252
self.svar.put(s)
5353
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Tests/ConcurrentTests/ChanSpec.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ class ChanSpec : XCTestCase {
4747
switch x {
4848
case .readChan:
4949
return self.delta((i == 0) ? error("read on empty MVar") : (i - 1), ac: xs)
50-
case .isEmptyChan:
51-
fallthrough
5250
case .returnInt(_):
5351
fallthrough
5452
case .returnBool(_):
@@ -74,7 +72,7 @@ class ChanSpec : XCTestCase {
7472
var result = [Action]()
7573
while empty != 0 {
7674
empty -= 1
77-
let branch = arc4random() % 3
75+
let branch = randomInteger() % 3
7876
if branch == 0 {
7977
return Gen.pure(ArrayOf(Array(repeating: .readChan, count: empty) + result))
8078
} else if branch == 1 {
@@ -146,4 +144,10 @@ class ChanSpec : XCTestCase {
146144
((l1 == l2) <?> "MVar Values Match")
147145
}
148146
}
147+
148+
#if !os(macOS) && !os(iOS) && !os(tvOS)
149+
static var allTests = testCase([
150+
("testProperties", testProperties),
151+
])
152+
#endif
149153
}

Tests/ConcurrentTests/ConcurrentSpec.swift

+13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ import Concurrent
1111
@testable import SwiftCheck
1212
import Dispatch
1313

14+
#if os(Linux)
15+
import Glibc
16+
public func randomInteger() -> UInt32 {
17+
return UInt32(rand())
18+
}
19+
#else
20+
import Darwin
21+
22+
public func randomInteger() -> UInt32 {
23+
return arc4random()
24+
}
25+
#endif
26+
1427
public func error<A>(_ x : String) -> A {
1528
XCTFail(x)
1629
fatalError(x)

Tests/ConcurrentTests/IVarSpec.swift

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Foundation
1010
import Concurrent
1111
import XCTest
1212
import SwiftCheck
13-
import func Darwin.C.stdlib.arc4random
1413

1514
private enum Action {
1615
case newEmptyIVar
@@ -47,8 +46,6 @@ class IVarSpec : XCTestCase {
4746
switch x {
4847
case .readIVar:
4948
return self.delta(b ? error("read on empty IVar") : false, ac: xs)
50-
case .isEmptyIVar:
51-
fallthrough
5249
case .returnInt(_):
5350
fallthrough
5451
case .returnBool(_):
@@ -75,7 +72,7 @@ class IVarSpec : XCTestCase {
7572
if n == 0 {
7673
return Gen.pure(ArrayOf(result))
7774
}
78-
while (arc4random() % UInt32(n)) != 0 {
75+
while (randomInteger() % UInt32(n)) != 0 {
7976
if empty {
8077
result = result + [.putIVar(Int.arbitrary.generate), .readIVar]
8178
empty = false
@@ -149,4 +146,10 @@ class IVarSpec : XCTestCase {
149146
((l1 == l2) <?> "IVar Values Match")
150147
}
151148
}
149+
150+
#if !os(macOS) && !os(iOS) && !os(tvOS)
151+
static var allTests = testCase([
152+
("testProperties", testProperties),
153+
])
154+
#endif
152155
}

Tests/ConcurrentTests/MVarSpec.swift

+8-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import Concurrent
1010
import XCTest
1111
import SwiftCheck
12-
import func Darwin.C.stdlib.arc4random
1312

1413
private enum Action {
1514
case newEmptyMVar
@@ -67,8 +66,6 @@ class MVarSpec : XCTestCase {
6766
return self.delta(b ? error("read on empty MVar") : false, ac: xs)
6867
case .swapMVar(_):
6968
return self.delta(b ? error("swap on empty MVar") : false, ac: xs)
70-
case .isEmptyMVar:
71-
fallthrough
7269
case .returnInt(_):
7370
fallthrough
7471
case .returnBool(_):
@@ -95,9 +92,9 @@ class MVarSpec : XCTestCase {
9592
if n == 0 {
9693
return Gen.pure(ArrayOf(result))
9794
}
98-
while (arc4random() % UInt32(n)) != 0 {
95+
while (randomInteger() % UInt32(n)) != 0 {
9996
if empty {
100-
result = result + [.putMVar(Int.arbitrary.generate)] + ((arc4random() % 2) == 0 ? [.swapMVar(Int.arbitrary.generate)] : [.readMVar])
97+
result = result + [.putMVar(Int.arbitrary.generate)] + ((randomInteger() % 2) == 0 ? [.swapMVar(Int.arbitrary.generate)] : [.readMVar])
10198
empty = false
10299
} else {
103100
result = result + [.takeMVar]
@@ -177,4 +174,10 @@ class MVarSpec : XCTestCase {
177174
((l1 == l2) <?> "MVar Values Match")
178175
}
179176
}
177+
178+
#if !os(macOS) && !os(iOS) && !os(tvOS)
179+
static var allTests = testCase([
180+
("testProperties", testProperties),
181+
])
182+
#endif
180183
}

Tests/ConcurrentTests/QSemSpec.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Foundation
1010
import Concurrent
1111
import XCTest
1212
import SwiftCheck
13-
import func Darwin.C.stdlib.arc4random
1413

1514
private enum Action {
1615
case newQSem(UInt)
@@ -62,7 +61,7 @@ class QSemSpec : XCTestCase {
6261
if n == 0 {
6362
return Gen.pure(ArrayOf(result))
6463
}
65-
while (arc4random() % UInt32(n)) != 0 {
64+
while (randomInteger() % UInt32(n)) != 0 {
6665
if quantity <= 0 {
6766
result.append(.signalQSem)
6867
quantity += 1
@@ -116,4 +115,10 @@ class QSemSpec : XCTestCase {
116115
self.setupPerformance(d + suff.getArray)
117116
}
118117
}
118+
119+
#if !os(macOS) && !os(iOS) && !os(tvOS)
120+
static var allTests = testCase([
121+
("testProperties", testProperties),
122+
])
123+
#endif
119124
}

Tests/ConcurrentTests/STMSpec.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Concurrent
1010
import XCTest
1111

12-
let initTVars = STM<(TVar<Int>, TVar<Int>)>.pure(TVar(0), TVar(0))
12+
let initTVars = STM<(TVar<Int>, TVar<Int>)>.pure((TVar(0), TVar(0)))
1313

1414
func optionOne(_ v1 : TVar<Int>, _ v2 : TVar<Int>) -> STM<()> {
1515
return v1.read().flatMap({ x in
@@ -53,7 +53,6 @@ func snapshot(_ v1 : TVar<Int>, _ v2 : TVar<Int>) -> STM<(Int, Int)> {
5353

5454
class STMSpec : XCTestCase {
5555
func testMain() {
56-
5756
let (sv1, sv2) = initTVars.atomically()
5857

5958
_ = elseTestA(sv1, sv2).atomically()
@@ -91,4 +90,10 @@ class STMSpec : XCTestCase {
9190
XCTAssert(vs.1 == 50)
9291
}()
9392
}
93+
94+
#if !os(macOS) && !os(iOS) && !os(tvOS)
95+
static var allTests = testCase([
96+
("testMain", testMain),
97+
])
98+
#endif
9499
}

0 commit comments

Comments
 (0)