Skip to content

Commit 98f8988

Browse files
committed
[Test] Update to Swift 3 syntax, removing Alamofire
1 parent a23a9ba commit 98f8988

16 files changed

+113
-135
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "Carthage/Checkouts/Alamofire"]
2-
path = Carthage/Checkouts/Alamofire
3-
url = https://github.com/Alamofire/Alamofire.git
41
[submodule "Carthage/Checkouts/Async"]
52
path = Carthage/Checkouts/Async
63
url = https://github.com/duemunk/Async.git

Cartfile.private

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
github "Alamofire/Alamofire" "swift3"
2-
github "duemunk/Async" "feature/Swift_3.0"
3-
github "mrackwitz/xcconfigs"
1+
github "duemunk/Async"
2+
github "mrackwitz/xcconfigs"

Cartfile.resolved

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
github "Alamofire/Alamofire" "e891699312a5215ad0da9f8322c5da949f90db35"
2-
github "duemunk/Async" "23d32df500f7ace6ea1526e7433a0fa7004c8d7d"
1+
github "duemunk/Async" "2.0.0"
32
github "mrackwitz/xcconfigs" "3.0"

Carthage/Checkouts/Alamofire

Lines changed: 0 additions & 1 deletion
This file was deleted.

Carthage/Checkouts/Async

Submodule Async updated 116 files

Configurations/Base.xcconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Developer;
1010
MACOSX_DEPLOYMENT_TARGET = 10.9;
1111
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
1212
WATCHOS_DEPLOYMENT_TARGET = 2.0;
13-
TVOS_DEPLOYMENT_TARGET = 9.0;
13+
TVOS_DEPLOYMENT_TARGET = 9.0;
14+
15+
SWIFT_VERSION = 3.0;

SwiftTask.xcodeproj/project.pbxproj

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
1F46DEDA199EDF1000F97868 /* SwiftTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F46DED9199EDF1000F97868 /* SwiftTask.h */; settings = {ATTRIBUTES = (Public, ); }; };
1616
1F46DEFB199EDF8100F97868 /* SwiftTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEFA199EDF8100F97868 /* SwiftTask.swift */; };
1717
1F46DEFD199EE2C200F97868 /* _TestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEFC199EE2C200F97868 /* _TestCase.swift */; };
18-
1F4C76A41AD8CF40004E47C1 /* AlamofireTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F5FA35619A374E600975FB9 /* AlamofireTests.swift */; };
19-
1F4C76A51AD8CF41004E47C1 /* AlamofireTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F5FA35619A374E600975FB9 /* AlamofireTests.swift */; };
2018
1F4C7AD71B7CD27200DEB1AE /* Async.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F4C7AD61B7CD27100DEB1AE /* Async.framework */; };
2119
1F4C7AD91B7CD27600DEB1AE /* Async.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F4C7AD81B7CD27600DEB1AE /* Async.framework */; };
2220
1F6A8CA319A4E4F200369A5D /* SwiftTaskTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEE3199EDF1000F97868 /* SwiftTaskTests.swift */; };
@@ -123,6 +121,14 @@
123121
/* End PBXFrameworksBuildPhase section */
124122

125123
/* Begin PBXGroup section */
124+
1F1BFFE21D97DCD9000105EB /* Deprecated */ = {
125+
isa = PBXGroup;
126+
children = (
127+
1F5FA35619A374E600975FB9 /* AlamofireTests.swift */,
128+
);
129+
name = Deprecated;
130+
sourceTree = "<group>";
131+
};
126132
1F46DECA199EDF1000F97868 = {
127133
isa = PBXGroup;
128134
children = (
@@ -175,9 +181,9 @@
175181
48511C5A19C17563002FE03C /* RetainCycleTests.swift */,
176182
485C31F01A1D619A00040DA3 /* TypeInferenceTests.swift */,
177183
1F218D5A1AFC3FFD00C849FF /* RemoveHandlerTests.swift */,
178-
1F5FA35619A374E600975FB9 /* AlamofireTests.swift */,
179184
1F29F6411B115EF500F476AF /* MultipleErrorTypesTests.swift */,
180185
1FF95CAF1CDD8F8D00899FEA /* MultipleTasksTests.swift */,
186+
1F1BFFE21D97DCD9000105EB /* Deprecated */,
181187
1F46DEE1199EDF1000F97868 /* Supporting Files */,
182188
);
183189
path = SwiftTaskTests;
@@ -384,7 +390,6 @@
384390
1FF95CB01CDD8F8D00899FEA /* MultipleTasksTests.swift in Sources */,
385391
1F6A8CA319A4E4F200369A5D /* SwiftTaskTests.swift in Sources */,
386392
1F29F6421B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */,
387-
1F4C76A41AD8CF40004E47C1 /* AlamofireTests.swift in Sources */,
388393
485C31F11A1D619A00040DA3 /* TypeInferenceTests.swift in Sources */,
389394
48511C5B19C17563002FE03C /* RetainCycleTests.swift in Sources */,
390395
1F46DEFD199EE2C200F97868 /* _TestCase.swift in Sources */,
@@ -401,7 +406,6 @@
401406
1FF95CB11CDD8F8D00899FEA /* MultipleTasksTests.swift in Sources */,
402407
1FF52EB51A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */,
403408
1F29F6431B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */,
404-
1F4C76A51AD8CF41004E47C1 /* AlamofireTests.swift in Sources */,
405409
485C31F21A1D619A00040DA3 /* TypeInferenceTests.swift in Sources */,
406410
4822F0DC19D00B2300F5F572 /* _TestCase.swift in Sources */,
407411
4822F0E019D00B2300F5F572 /* RetainCycleTests.swift in Sources */,
@@ -522,7 +526,6 @@
522526
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
523527
PRODUCT_NAME = "$(PROJECT_NAME)";
524528
SKIP_INSTALL = YES;
525-
SWIFT_VERSION = 3.0;
526529
};
527530
name = Debug;
528531
};
@@ -542,7 +545,6 @@
542545
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
543546
PRODUCT_NAME = "$(PROJECT_NAME)";
544547
SKIP_INSTALL = YES;
545-
SWIFT_VERSION = 3.0;
546548
};
547549
name = Release;
548550
};
@@ -556,11 +558,9 @@
556558
"$(inherited)",
557559
);
558560
INFOPLIST_FILE = SwiftTaskTests/Info.plist;
559-
MACOSX_DEPLOYMENT_TARGET = 10.10;
560561
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
561562
PRODUCT_NAME = "$(TARGET_NAME)";
562563
SDKROOT = macosx;
563-
SWIFT_VERSION = 3.0;
564564
};
565565
name = Debug;
566566
};
@@ -570,11 +570,9 @@
570570
buildSettings = {
571571
COMBINE_HIDPI_IMAGES = YES;
572572
INFOPLIST_FILE = SwiftTaskTests/Info.plist;
573-
MACOSX_DEPLOYMENT_TARGET = 10.10;
574573
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
575574
PRODUCT_NAME = "$(TARGET_NAME)";
576575
SDKROOT = macosx;
577-
SWIFT_VERSION = 3.0;
578576
};
579577
name = Release;
580578
};
@@ -587,7 +585,6 @@
587585
"$(inherited)",
588586
);
589587
INFOPLIST_FILE = SwiftTaskTests/Info.plist;
590-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
591588
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
592589
PRODUCT_NAME = "$(TARGET_NAME)";
593590
SDKROOT = iphoneos;
@@ -599,7 +596,6 @@
599596
baseConfigurationReference = 1FFADCDE1C5CEC1B000B66BE /* UniversalFramework_Test.xcconfig */;
600597
buildSettings = {
601598
INFOPLIST_FILE = SwiftTaskTests/Info.plist;
602-
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
603599
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
604600
PRODUCT_NAME = "$(TARGET_NAME)";
605601
SDKROOT = iphoneos;

SwiftTask.xcworkspace/contents.xcworkspacedata

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SwiftTaskTests/AlamofireTests.swift

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import XCTest
1212

1313
class AlamofireTests: _TestCase
1414
{
15-
typealias Progress = (bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
15+
typealias Progress = Double
1616

1717
func testFulfill()
1818
{
19-
let expect = self.expectation(withDescription: #function)
19+
let expect = self.expectation(description: #function)
2020

21-
let task = Task<Progress, String, NSError> { progress, fulfill, reject, configure in
22-
23-
request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
24-
.response { (request, response, data, error) in
21+
let task = Task<Progress, String, Error> { progress, fulfill, reject, configure in
22+
23+
Alamofire.request("http://httpbin.org/get", method: .get, parameters: ["foo": "bar"])
24+
.response { response in
2525

26-
if let error = error {
26+
if let error = response.error {
2727
reject(error)
2828
return
2929
}
@@ -46,21 +46,21 @@ class AlamofireTests: _TestCase
4646

4747
func testReject()
4848
{
49-
let expect = self.expectation(withDescription: #function)
49+
let expect = self.expectation(description: #function)
5050

51-
let task = Task<Progress, String?, NSError> { progress, fulfill, reject, configure in
51+
let task = Task<Progress, String?, Error> { progress, fulfill, reject, configure in
5252

5353
let dummyURLString = "http://xxx-swift-task.org/get"
5454

55-
request(.GET, dummyURLString, parameters: ["foo": "bar"])
56-
.response { (request, response, data, error) in
55+
Alamofire.request(dummyURLString, method: .get, parameters: ["foo": "bar"])
56+
.response { response in
5757

58-
if let error = error {
58+
if let error = response.error {
5959
reject(error) // pass non-nil error
6060
return
6161
}
6262

63-
if response?.statusCode >= 300 {
63+
if let status = response.response?.statusCode, status >= 300 {
6464
reject(NSError(domain: "", code: 0, userInfo: nil))
6565
}
6666

@@ -74,7 +74,7 @@ class AlamofireTests: _TestCase
7474

7575
XCTFail("Should never reach here.")
7676

77-
}.failure { (error: NSError?, isCancelled: Bool) -> Void in
77+
}.failure { (error: Error?, isCancelled: Bool) -> Void in
7878

7979
XCTAssertTrue(error != nil, "Should receive non-nil error.")
8080
expect.fulfill()
@@ -86,20 +86,20 @@ class AlamofireTests: _TestCase
8686

8787
func testProgress()
8888
{
89-
let expect = self.expectation(withDescription: #function)
89+
let expect = self.expectation(description: #function)
9090

9191
// define task
92-
let task = Task<Progress, String, NSError> { progress, fulfill, reject, configure in
92+
let task = Task<Progress, String, Error> { progress, fulfill, reject, configure in
9393

94-
download(.GET, "http://httpbin.org/stream/100", destination: Request.suggestedDownloadDestination(directory: .documentDirectory, domain: .userDomainMask))
94+
Alamofire.download("http://httpbin.org/stream/100", method: .get, to: DownloadRequest.suggestedDownloadDestination())
9595

96-
.progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
97-
98-
progress((bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) as Progress)
96+
.downloadProgress { progress_ in
97+
98+
progress(progress_.fractionCompleted)
9999

100-
}.response { (request, response, data, error) in
100+
}.response { response in
101101

102-
if let error = error {
102+
if let error = response.error {
103103
reject(error)
104104
return
105105
}
@@ -113,13 +113,8 @@ class AlamofireTests: _TestCase
113113
}
114114

115115
// set progress & then
116-
task.progress { _, progress in
117-
118-
print("bytesWritten = \(progress.bytesWritten)")
119-
print("totalBytesWritten = \(progress.totalBytesWritten)")
120-
print("totalBytesExpectedToWrite = \(progress.totalBytesExpectedToWrite)")
121-
print("")
122-
116+
task.progress { _, progress_ in
117+
print("progress = \(progress_)")
123118
}.then { value, errorInfo -> Void in
124119
expect.fulfill()
125120
}
@@ -129,20 +124,19 @@ class AlamofireTests: _TestCase
129124

130125
func testNSProgress()
131126
{
132-
let expect = self.expectation(withDescription: #function)
127+
let expect = self.expectation(description: #function)
133128
let nsProgress = Foundation.Progress(totalUnitCount: 100)
134129

135130
// define task
136-
let task = Task<Progress, String, NSError> { progress, fulfill, reject, configure in
131+
let task = Task<Progress, String, Error> { progress, fulfill, reject, configure in
137132

138133
nsProgress.becomeCurrent(withPendingUnitCount: 50)
139134

140135
// NOTE: test with url which returns totalBytesExpectedToWrite != -1
141-
download(.GET, "http://httpbin.org/bytes/1024", destination: Request.suggestedDownloadDestination(directory: .documentDirectory, domain: .userDomainMask))
142-
143-
.response { (request, response, data, error) in
136+
Alamofire.download("http://httpbin.org/bytes/1024", method: .get, to: DownloadRequest.suggestedDownloadDestination())
137+
.response { response in
144138

145-
if let error = error {
139+
if let error = response.error {
146140
reject(error)
147141
return
148142
}
@@ -176,15 +170,14 @@ class AlamofireTests: _TestCase
176170
//
177171
func testCancel()
178172
{
179-
let expect = self.expectation(withDescription: #function)
173+
let expect = self.expectation(description: #function)
180174

181-
let task = Task<Progress, String?, NSError> { progress, fulfill, reject, configure in
175+
let task = Task<Progress, String?, Error> { progress, fulfill, reject, configure in
182176

183-
let downloadRequst = download(.GET, "http://httpbin.org/stream/100", destination: Request.suggestedDownloadDestination(directory: .documentDirectory, domain: .userDomainMask))
184-
185-
.response { (request, response, data, error) in
177+
let downloadRequst = Alamofire.download("http://httpbin.org/stream/100", method: .get, to: DownloadRequest.suggestedDownloadDestination())
178+
.response { response in
186179

187-
if let error = error {
180+
if let error = response.error {
188181
reject(error)
189182
return
190183
}
@@ -207,7 +200,7 @@ class AlamofireTests: _TestCase
207200

208201
XCTFail("Should never reach here because task is cancelled.")
209202

210-
}.failure { (error: NSError?, isCancelled: Bool) -> Void in
203+
}.failure { (error: Error?, isCancelled: Bool) -> Void in
211204

212205
XCTAssertTrue(error == nil, "Should receive nil error via task.cancel().")
213206
XCTAssertTrue(isCancelled)
@@ -217,7 +210,7 @@ class AlamofireTests: _TestCase
217210
}
218211

219212
// cancel after 1ms
220-
DispatchQueue.main.after(when: .now() + 0.001) {
213+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.001) {
221214

222215
task.cancel() // sends no error
223216

SwiftTaskTests/BasicTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BasicTests: _TestCase
1616
{
1717
typealias Task = SwiftTask.Task<Float, String, ErrorString>
1818

19-
let expect = self.expectation(withDescription: #function)
19+
let expect = self.expectation(description: #function)
2020

2121
// define task
2222
let task = Task { progress, fulfill, reject, configure in

SwiftTaskTests/MultipleErrorTypesTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class MultipleErrorTypesTests: _TestCase
6161

6262
func testMultipleErrorTypes_then()
6363
{
64-
let expect = self.expectation(withDescription: #function)
64+
let expect = self.expectation(description: #function)
6565

6666
self._task1(ok: true)
6767
.then { value, errorInfo -> Task2 in
@@ -87,7 +87,7 @@ class MultipleErrorTypesTests: _TestCase
8787

8888
func testMultipleErrorTypes_success()
8989
{
90-
let expect = self.expectation(withDescription: #function)
90+
let expect = self.expectation(description: #function)
9191

9292
self._task1(ok: true)
9393
.success { value -> Task2 in
@@ -113,7 +113,7 @@ class MultipleErrorTypesTests: _TestCase
113113

114114
func testMultipleErrorTypes_success_differentErrorType()
115115
{
116-
let expect = self.expectation(withDescription: #function)
116+
let expect = self.expectation(description: #function)
117117

118118
self._task1(ok: true)
119119
.success { value -> Task2 in
@@ -151,7 +151,7 @@ class MultipleErrorTypesTests: _TestCase
151151

152152
func testMultipleErrorTypes_success_differentErrorType_conversion()
153153
{
154-
let expect = self.expectation(withDescription: #function)
154+
let expect = self.expectation(description: #function)
155155

156156
self._task1(ok: true)
157157
.success { value -> Task<Void, MyEnum, String> in
@@ -191,7 +191,7 @@ class MultipleErrorTypesTests: _TestCase
191191

192192
func testMultipleErrorTypes_failure()
193193
{
194-
let expect = self.expectation(withDescription: #function)
194+
let expect = self.expectation(description: #function)
195195

196196
self._task1(ok: false)
197197
.failure { errorInfo -> Task<Dummy, String /* must be task1's value type to recover */, Dummy> in

0 commit comments

Comments
 (0)