From 6c10774c4a317560157b8bf6b1ef48024f5b986e Mon Sep 17 00:00:00 2001 From: Tim Ekl Date: Tue, 31 Dec 2019 19:36:42 -0600 Subject: [PATCH] Fix build errors stemming from FeedlyTestSupport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was one call to a throwing function inside `checkArticles(in:correspondToStreamItemsIn:)` which was not appropriately marked with `try`. Add that keyword, and then bubble out the chain of errors through additional layers of helpers to the enclosing test: * This `checkArticles` variant was called by two others * …one of which was used in `testAddNewFeedSuccess()` * …another of which was used in various `verify` sync helpers * …which were referenced from `testSyncing()`, a test case method None of these involved any particular async hoops to jump through, and since the top-level callers were all test functions, we can count on XCTest to handle any errors thrown — no additional `catch` or handling on our part is necessary. --- .../FeedlyAddNewFeedOperationTests.swift | 4 +- .../Feedly/FeedlySyncAllOperationTests.swift | 42 +++++++++---------- .../Feedly/FeedlyTestSupport.swift | 12 +++--- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift index c218e8f07..396cc8783 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlyAddNewFeedOperationTests.swift @@ -120,7 +120,7 @@ class FeedlyAddNewFeedOperationTests: XCTestCase { XCTAssert(progress.isComplete) } - func testAddNewFeedSuccess() { + func testAddNewFeedSuccess() throws { guard let folder = getFolderByLoadingInitialContent() else { return } @@ -163,7 +163,7 @@ class FeedlyAddNewFeedOperationTests: XCTestCase { XCTAssert(progress.isComplete) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "feedStream", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "feedStream", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) } diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift b/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift index 914c25e8a..403250314 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlySyncAllOperationTests.swift @@ -114,18 +114,18 @@ class FeedlySyncAllOperationTests: XCTestCase { return caller }() - func testSyncing() { + func testSyncing() throws { performInitialSync() - verifyInitialSync() + try verifyInitialSync() performChangeStatuses() - verifyChangeStatuses() + try verifyChangeStatuses() performChangeStatusesAgain() - verifyChangeStatusesAgain() + try verifyChangeStatusesAgain() performAddFeedsAndFolders() - verifyAddFeedsAndFolders() + try verifyAddFeedsAndFolders() } // MARK: 1 - Initial Sync @@ -166,15 +166,15 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-1-initial") } - func verifyInitialSync() { + func verifyInitialSync() throws { let subdirectory = "feedly-1-initial" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all@MTZkOTdkZWQ1NzM6NTE2OjUzYjgyNmEy", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all@MTZkOTdkZWQ1NzM6NTE2OjUzYjgyNmEy", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOTRhOTNhZTQ6MzExOjUzYjgyNmEy", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: 2 - Change Statuses @@ -183,14 +183,14 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-2-changestatuses") } - func verifyChangeStatuses() { + func verifyChangeStatuses() throws { let subdirectory = "feedly-2-changestatuses" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOTJkNjIwM2Q6MTEzYjpkNDUwNjA3MQ==", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: 3 - Change Statuses Again @@ -199,14 +199,14 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-3-changestatusesagain") } - func verifyChangeStatusesAgain() { + func verifyChangeStatusesAgain() throws { let subdirectory = "feedly-3-changestatusesagain" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOGRlMjVmM2M6M2YyOmQ0NTA2MDcx", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: 4 - Add Feeds and Folders @@ -215,14 +215,14 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-4-addfeedsandfolders") } - func verifyAddFeedsAndFolders() { + func verifyAddFeedsAndFolders() throws { let subdirectory = "feedly-4-addfeedsandfolders" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOTE3YTRlMzQ6YWZjOmQ0NTA2MDcx", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: 5 - Remove Feeds and Folders @@ -231,14 +231,14 @@ class FeedlySyncAllOperationTests: XCTestCase { loadMockData(inSubdirectoryNamed: "feedly-5-removefeedsandfolders") } - func verifyRemoveFeedsAndFolders() { + func verifyRemoveFeedsAndFolders() throws { let subdirectory = "feedly-5-removefeedsandfolders" support.checkFoldersAndFeeds(in: account, againstCollectionsAndFeedsInJSONNamed: "collections", subdirectory: subdirectory) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "global.all", subdirectory: subdirectory) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds", subdirectory: subdirectory, testCase: self) support.checkUnreadStatuses(in: account, againstIdsInStreamInJSONNamed: "unreadIds@MTZkOGRlMjVmM2M6M2YxOmQ0NTA2MDcx", subdirectory: subdirectory, testCase: self) support.checkStarredStatuses(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory, testCase: self) - support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) + try support.checkArticles(in: account, againstItemsInStreamInJSONNamed: "starred", subdirectory: subdirectory) } // MARK: Downloading Test Data diff --git a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift index fb52eb781..4e3ef6d87 100644 --- a/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift +++ b/Frameworks/Account/AccountTests/Feedly/FeedlyTestSupport.swift @@ -141,13 +141,13 @@ class FeedlyTestSupport { XCTAssertTrue(missingFeedIds.isEmpty, "Feeds with these ids were not found in the \"\(label)\" folder.") } - func checkArticles(in account: Account, againstItemsInStreamInJSONNamed name: String, subdirectory: String? = nil) { + func checkArticles(in account: Account, againstItemsInStreamInJSONNamed name: String, subdirectory: String? = nil) throws { let stream = testJSON(named: name, subdirectory: subdirectory) as! [String:Any] - checkArticles(in: account, againstItemsInStreamInJSONPayload: stream) + try checkArticles(in: account, againstItemsInStreamInJSONPayload: stream) } - func checkArticles(in account: Account, againstItemsInStreamInJSONPayload stream: [String: Any]) { - checkArticles(in: account, correspondToStreamItemsIn: stream) + func checkArticles(in account: Account, againstItemsInStreamInJSONPayload stream: [String: Any]) throws { + try checkArticles(in: account, correspondToStreamItemsIn: stream) } private struct ArticleItem { @@ -188,13 +188,13 @@ class FeedlyTestSupport { } /// Awkwardly titled to make it clear the JSON given is from a stream response. - func checkArticles(in testAccount: Account, correspondToStreamItemsIn stream: [String: Any]) { + func checkArticles(in testAccount: Account, correspondToStreamItemsIn stream: [String: Any]) throws { let items = stream["items"] as! [[String: Any]] let articleItems = items.map { ArticleItem(item: $0) } let itemIds = Set(articleItems.map { $0.id }) - let articles = testAccount.fetchArticles(.articleIDs(itemIds)) + let articles = try testAccount.fetchArticles(.articleIDs(itemIds)) let articleIds = Set(articles.map { $0.articleID }) let missing = itemIds.subtracting(articleIds)