Bgerstle has uploaded a new change for review. https://gerrit.wikimedia.org/r/215659
Change subject: fix unit tests (again) & crash reporting ...................................................................... fix unit tests (again) & crash reporting Crash reporting is now expected to always be enabled. Exceptions (not assertions) will be thrown if it fails to be setup. This will give us early feedback (immediate at app launch) if it is ever accidentally disabled again. - Use bundle identifier instead of bundle version to get HockeyApp App ID for current bundle ID (auto-complete mistake) - Remove conditional logic in HockeyApp setup (should always setup, and fail silently if attached to debugger) - Add convenience macros to verify certain preconditions inline (see WMFPreconditions.h & WMFPreconditionsTests.m) - Re-add fixtures to the testing target Bug: T100331 Change-Id: I97730f9f599e8fbb6f8c0662b39a5b8bb9bf8220 --- M Wikipedia.xcodeproj/project.pbxproj M Wikipedia/Categories/BITHockeyManager+WMFExtensions.h M Wikipedia/Categories/BITHockeyManager+WMFExtensions.m M Wikipedia/Categories/NSBundle+WMFInfoUtils.h M Wikipedia/Categories/NSBundle+WMFInfoUtils.m A Wikipedia/mw-utils/WMFPreconditions.h M Wikipedia/mw-utils/WikipediaAppUtils.h M Wikipedia/mw-utils/WikipediaAppUtils.m D WikipediaUnitTests/BITHockeyManagerWMFExtensionsTests.m A WikipediaUnitTests/WMFPreconditionsTests.m 10 files changed, 157 insertions(+), 99 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/ios/wikipedia refs/changes/59/215659/1 diff --git a/Wikipedia.xcodeproj/project.pbxproj b/Wikipedia.xcodeproj/project.pbxproj index 925775e..1683c9d 100644 --- a/Wikipedia.xcodeproj/project.pbxproj +++ b/Wikipedia.xcodeproj/project.pbxproj @@ -187,7 +187,6 @@ 0EA4402E1AA6281200B09DBA /* NSDateFormatter+WMFExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EA4402D1AA6281200B09DBA /* NSDateFormatter+WMFExtensions.m */; }; 0EBC56681AD3656900E82CDD /* WMFAsyncTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = BC7ACB631AB34C9C00791497 /* WMFAsyncTestCase.m */; }; 0EBC567F1AD442CC00E82CDD /* BITHockeyManager+WMFExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EBC567E1AD442CC00E82CDD /* BITHockeyManager+WMFExtensions.m */; }; - 0EBC56961AD5B22800E82CDD /* BITHockeyManagerWMFExtensionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EBC56951AD5B22800E82CDD /* BITHockeyManagerWMFExtensionsTests.m */; }; 0EBC56971AD5B69300E82CDD /* BITHockeyManager+WMFExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EBC567E1AD442CC00E82CDD /* BITHockeyManager+WMFExtensions.m */; }; 0EE7687B1AF982C100A5D046 /* WMFArticleProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EE7687A1AF982C100A5D046 /* WMFArticleProtocol.m */; }; 0EE768811AFD25CC00A5D046 /* WMFSearchFunnel.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EE768801AFD25CC00A5D046 /* WMFSearchFunnel.m */; }; @@ -282,18 +281,19 @@ BCC185D81A9E5628005378F8 /* UILabel+WMFStyling.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC185D71A9E5628005378F8 /* UILabel+WMFStyling.m */; }; BCC185E01A9EC836005378F8 /* UIButton+FrameUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC185DF1A9EC836005378F8 /* UIButton+FrameUtils.m */; }; BCC185E81A9FA498005378F8 /* UICollectionViewFlowLayout+AttributeUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = BCC185E71A9FA498005378F8 /* UICollectionViewFlowLayout+AttributeUtils.m */; }; + BCCEC1211B1F68CF00A8B522 /* golden-gate.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DDE1B11CC5800231BB1 /* golden-gate.jpg */; }; + BCCEC1221B1F68CF00A8B522 /* MainPageMobileView.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DDF1B11CC5800231BB1 /* MainPageMobileView.json */; }; + BCCEC1231B1F68CF00A8B522 /* Obama.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE01B11CC5800231BB1 /* Obama.json */; }; + BCCEC1241B1F68CF00A8B522 /* organization-anon.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE11B11CC5800231BB1 /* organization-anon.json */; }; + BCCEC1251B1F68CF00A8B522 /* protection-empty.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE21B11CC5800231BB1 /* protection-empty.json */; }; + BCCEC1261B1F68CF00A8B522 /* protection-obama.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE31B11CC5800231BB1 /* protection-obama.json */; }; + BCCEC1271B1F68CF00A8B522 /* section0.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE41B11CC5800231BB1 /* section0.json */; }; + BCCEC1281B1F68CF00A8B522 /* section1-end.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE51B11CC5800231BB1 /* section1-end.json */; }; + BCCEC1291B1F68CF00A8B522 /* TemplateIcon2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE61B11CC5800231BB1 /* TemplateIcon2x.png */; }; + BCCEC12A1B1F68CF00A8B522 /* test-notes.txt in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE71B11CC5800231BB1 /* test-notes.txt */; }; + BCCEC12B1B1F68CF00A8B522 /* user-anon.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE81B11CC5800231BB1 /* user-anon.json */; }; BCCED2D01AE03BE20094EB7E /* MWKSectionListTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BCCED2CF1AE03BE20094EB7E /* MWKSectionListTests.m */; }; - BCD41DEA1B11CC5800231BB1 /* golden-gate.jpg in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DDE1B11CC5800231BB1 /* golden-gate.jpg */; }; - BCD41DEB1B11CC5800231BB1 /* MainPageMobileView.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DDF1B11CC5800231BB1 /* MainPageMobileView.json */; }; - BCD41DEC1B11CC5800231BB1 /* Obama.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE01B11CC5800231BB1 /* Obama.json */; }; - BCD41DED1B11CC5800231BB1 /* organization-anon.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE11B11CC5800231BB1 /* organization-anon.json */; }; - BCD41DEE1B11CC5800231BB1 /* protection-empty.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE21B11CC5800231BB1 /* protection-empty.json */; }; - BCD41DEF1B11CC5800231BB1 /* protection-obama.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE31B11CC5800231BB1 /* protection-obama.json */; }; - BCD41DF01B11CC5800231BB1 /* section0.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE41B11CC5800231BB1 /* section0.json */; }; - BCD41DF11B11CC5800231BB1 /* section1-end.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE51B11CC5800231BB1 /* section1-end.json */; }; - BCD41DF21B11CC5800231BB1 /* TemplateIcon2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE61B11CC5800231BB1 /* TemplateIcon2x.png */; }; - BCD41DF31B11CC5800231BB1 /* test-notes.txt in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE71B11CC5800231BB1 /* test-notes.txt */; }; - BCD41DF41B11CC5800231BB1 /* user-anon.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE81B11CC5800231BB1 /* user-anon.json */; }; + BCCF02A51B1F5A28004DA97E /* WMFPreconditionsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BCCF02A41B1F5A28004DA97E /* WMFPreconditionsTests.m */; }; BCD41DF61B11CC5E00231BB1 /* user-loggedin.json in Resources */ = {isa = PBXBuildFile; fileRef = BCD41DE91B11CC5800231BB1 /* user-loggedin.json */; }; BCD41E001B11D1B200231BB1 /* XCTestCase+MWKFixtures.m in Sources */ = {isa = PBXBuildFile; fileRef = BCD41DFE1B11D17100231BB1 /* XCTestCase+MWKFixtures.m */; }; BCDB75C41AB0E8300005593F /* WMFSubstringUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BCDB75C31AB0E8300005593F /* WMFSubstringUtilsTests.m */; }; @@ -727,7 +727,6 @@ 0EA4402D1AA6281200B09DBA /* NSDateFormatter+WMFExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSDateFormatter+WMFExtensions.m"; path = "Wikipedia/Categories/NSDateFormatter+WMFExtensions.m"; sourceTree = SOURCE_ROOT; }; 0EBC567D1AD442CC00E82CDD /* BITHockeyManager+WMFExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "BITHockeyManager+WMFExtensions.h"; path = "Wikipedia/Categories/BITHockeyManager+WMFExtensions.h"; sourceTree = SOURCE_ROOT; }; 0EBC567E1AD442CC00E82CDD /* BITHockeyManager+WMFExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "BITHockeyManager+WMFExtensions.m"; path = "Wikipedia/Categories/BITHockeyManager+WMFExtensions.m"; sourceTree = SOURCE_ROOT; }; - 0EBC56951AD5B22800E82CDD /* BITHockeyManagerWMFExtensionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITHockeyManagerWMFExtensionsTests.m; sourceTree = "<group>"; }; 0EE768791AF982C100A5D046 /* WMFArticleProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WMFArticleProtocol.h; path = Wikipedia/Protocols/WMFArticleProtocol.h; sourceTree = SOURCE_ROOT; }; 0EE7687A1AF982C100A5D046 /* WMFArticleProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WMFArticleProtocol.m; path = Wikipedia/Protocols/WMFArticleProtocol.m; sourceTree = SOURCE_ROOT; }; 0EE7687F1AFD25CC00A5D046 /* WMFSearchFunnel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMFSearchFunnel.h; sourceTree = "<group>"; }; @@ -898,6 +897,8 @@ BCC185E71A9FA498005378F8 /* UICollectionViewFlowLayout+AttributeUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UICollectionViewFlowLayout+AttributeUtils.m"; sourceTree = "<group>"; }; BCCED2CF1AE03BE20094EB7E /* MWKSectionListTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWKSectionListTests.m; sourceTree = "<group>"; }; BCCED2D21AE041BD0094EB7E /* MWKSectionList_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWKSectionList_Private.h; sourceTree = "<group>"; }; + BCCF02A31B1F549E004DA97E /* WMFPreconditions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WMFPreconditions.h; sourceTree = "<group>"; }; + BCCF02A41B1F5A28004DA97E /* WMFPreconditionsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WMFPreconditionsTests.m; sourceTree = "<group>"; }; BCD41DDE1B11CC5800231BB1 /* golden-gate.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "golden-gate.jpg"; sourceTree = "<group>"; }; BCD41DDF1B11CC5800231BB1 /* MainPageMobileView.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = MainPageMobileView.json; sourceTree = "<group>"; }; BCD41DE01B11CC5800231BB1 /* Obama.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Obama.json; sourceTree = "<group>"; }; @@ -2080,11 +2081,11 @@ BCA9575C1ABE473800B62AE8 /* OldDataSchemaMigratorTests.m */, BC31B2511AB1D9DC008138CA /* WMFImageInfoControllerTests.m */, BCE912BC1ACC629B00B74B42 /* NSIndexSet+BKReduceTests.m */, - 0EBC56951AD5B22800E82CDD /* BITHockeyManagerWMFExtensionsTests.m */, BCCED2CF1AE03BE20094EB7E /* MWKSectionListTests.m */, BC49B3631AEECFD8009F55BE /* ArticleLoadingTests.m */, BC92A7721AFA88D3003C4212 /* MWKSection+WMFSharingTests.m */, BCAFC5CF1AFD5E7D004615BA /* MWKArticle+WMFSharingTests.m */, + BCCF02A41B1F5A28004DA97E /* WMFPreconditionsTests.m */, ); name = Tests; path = WikipediaUnitTests; @@ -2362,6 +2363,7 @@ BC7A4A231B17B3510003E73E /* NSObjectUtilities.h */, BC092B971B18E8AF00093C59 /* NSString+WMFPageUtilities.h */, BC092B951B18E89200093C59 /* NSString+WMFPageUtilities.m */, + BCCF02A31B1F549E004DA97E /* WMFPreconditions.h */, ); path = "mw-utils"; sourceTree = "<group>"; @@ -2746,8 +2748,19 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + BCCEC1251B1F68CF00A8B522 /* protection-empty.json in Resources */, + BCCEC1261B1F68CF00A8B522 /* protection-obama.json in Resources */, + BCCEC1221B1F68CF00A8B522 /* MainPageMobileView.json in Resources */, + BCCEC1211B1F68CF00A8B522 /* golden-gate.jpg in Resources */, BCA6764E1AC05FD600A16160 /* Info.plist in Resources */, + BCCEC1281B1F68CF00A8B522 /* section1-end.json in Resources */, + BCCEC1291B1F68CF00A8B522 /* TemplateIcon2x.png in Resources */, + BCCEC12B1B1F68CF00A8B522 /* user-anon.json in Resources */, + BCCEC1231B1F68CF00A8B522 /* Obama.json in Resources */, + BCCEC1241B1F68CF00A8B522 /* organization-anon.json in Resources */, BCD41DF61B11CC5E00231BB1 /* user-loggedin.json in Resources */, + BCCEC12A1B1F68CF00A8B522 /* test-notes.txt in Resources */, + BCCEC1271B1F68CF00A8B522 /* section0.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2758,35 +2771,24 @@ BCE912D31ACCAF6900B74B42 /* OldDataSchemaBundle.bundle in Resources */, D46CD8C418A1AC4F0042959E /* InfoPlist.strings in Resources */, D499144C181D51DE00E6073C /* Main_iPhone.storyboard in Resources */, - BCD41DEF1B11CC5800231BB1 /* protection-obama.json in Resources */, D46CD8C518A1AC4F0042959E /* Localizable.strings in Resources */, 0480AE981AA4E65D00A9950C /* WMFWebViewFooterViewController.xib in Resources */, D401C2C11A659E5000D4D127 /* DataMigrationProgressViewController.xib in Resources */, 049B2BDB1AB9016A00CE27FF /* MWKArticle+ConvenienceSpecs in Resources */, 04EDEE251A20788700798076 /* SearchResultPrototypeView.xib in Resources */, - BCD41DF01B11CC5800231BB1 /* section0.json in Resources */, - BCD41DEB1B11CC5800231BB1 /* MainPageMobileView.json in Resources */, 04478631185145090050563B /* HistoryResultPrototypeView.xib in Resources */, C98990361A699DFB00AF44FC /* ShareCard.xib in Resources */, 0493C2D419526A0100EBB973 /* WikiFont-Glyphs.ttf in Resources */, - BCD41DED1B11CC5800231BB1 /* organization-anon.json in Resources */, 04F27B7618FE0F2E00EDD838 /* PageHistoryResultPrototypeView.xib in Resources */, 04B0EA47190B2319007458AF /* PreviewLicenseView.xib in Resources */, - BCD41DEA1B11CC5800231BB1 /* golden-gate.jpg in Resources */, - BCD41DF31B11CC5800231BB1 /* test-notes.txt in Resources */, 04CCCFEF1935093A00E3F60C /* SecondaryMenuRowView.xib in Resources */, - BCD41DF41B11CC5800231BB1 /* user-anon.json in Resources */, 0480AE911AA4E61000A9950C /* WMFReadMoreViewController.xib in Resources */, - BCD41DEC1B11CC5800231BB1 /* Obama.json in Resources */, 047E74141860509000916964 /* SavedPagesResultPrototypeView.xib in Resources */, C46FBA4B1A8530EE00C5730F /* Pods-acknowledgements.plist in Resources */, - BCD41DF11B11CC5800231BB1 /* section1-end.json in Resources */, D4BC22B4181E9E6300CAC673 /* empty.png in Resources */, - BCD41DEE1B11CC5800231BB1 /* protection-empty.json in Resources */, 04C7576F1A1AA2D00084AC39 /* RecentSearchCell.xib in Resources */, C979727A1A731EAA00C6ED7A /* ShareOptions.xib in Resources */, 0443961D1A3C134F0081557D /* NearbyResultCollectionCell.xib in Resources */, - BCD41DF21B11CC5800231BB1 /* TemplateIcon2x.png in Resources */, BCF012331AD2FA38008D3675 /* assets in Resources */, BCB58F591A89747400465627 /* WMFImageGalleryDetailOverlayView.xib in Resources */, 0480AE891AA4E61000A9950C /* WMFLegalFooterViewController.xib in Resources */, @@ -2981,7 +2983,6 @@ BCA6765A1AC0600500A16160 /* MWKDataStore+TemporaryDataStore.m in Sources */, 04F122671ACB818F002FC3B5 /* NSString+FormattedAttributedString.m in Sources */, BC0FED711AAA026C002488D7 /* WMFJoinedPropertyParametersTests.m in Sources */, - 0EBC56961AD5B22800E82CDD /* BITHockeyManagerWMFExtensionsTests.m in Sources */, BC0FED6A1AAA0268002488D7 /* MWKDataStorePathTests.m in Sources */, BC0FED761AAA026C002488D7 /* NSString+WMFHTMLParsingTests.m in Sources */, BCA676571AC05FE200A16160 /* XCTestCase+WMFBundleConvenience.m in Sources */, @@ -2989,6 +2990,7 @@ BCD41E001B11D1B200231BB1 /* XCTestCase+MWKFixtures.m in Sources */, BC0FED631AAA0263002488D7 /* MWKTestCase.m in Sources */, BC92A7731AFA88D3003C4212 /* MWKSection+WMFSharingTests.m in Sources */, + BCCF02A51B1F5A28004DA97E /* WMFPreconditionsTests.m in Sources */, BCAFC5ED1B02490A004615BA /* WMFRandomFileUtilities.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -3812,7 +3814,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = EDA528BC357952A7D914F8E0 /* Pods.debug.xcconfig */; buildSettings = { - APP_ID_SUFFIX = .dev; + APP_ID_SUFFIX = .developer; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CODE_SIGN_IDENTITY = "iPhone Developer"; diff --git a/Wikipedia/Categories/BITHockeyManager+WMFExtensions.h b/Wikipedia/Categories/BITHockeyManager+WMFExtensions.h index b5b9b55..d529bb7 100644 --- a/Wikipedia/Categories/BITHockeyManager+WMFExtensions.h +++ b/Wikipedia/Categories/BITHockeyManager+WMFExtensions.h @@ -11,15 +11,6 @@ - (void)wmf_setupAndStart; /** - * Set the Hockey API Key based on a bundle ID - * - * @param bundleID The bundle ID to map to an API Key - * - * @return YES if successful, otherwise NO - */ -- (BOOL)wmf_setAPIKeyForBundleID:(NSString*)bundleID; - -/** * Configure the alert to be displayed when a user is prompeted to send a crash report */ - (void)wmf_setupCrashNotificationAlert; diff --git a/Wikipedia/Categories/BITHockeyManager+WMFExtensions.m b/Wikipedia/Categories/BITHockeyManager+WMFExtensions.m index dccda06..7083ebe 100644 --- a/Wikipedia/Categories/BITHockeyManager+WMFExtensions.m +++ b/Wikipedia/Categories/BITHockeyManager+WMFExtensions.m @@ -1,7 +1,9 @@ #import "BITHockeyManager+WMFExtensions.h" #import "WikipediaAppUtils.h" +#import "NSBundle+WMFInfoUtils.h" #import "WMFCrashAlertView.h" +#import "WMFPreconditions.h" // See also: // http://support.hockeyapp.net/kb/client-integration-ios-mac-os-x/hockeyapp-for-ios @@ -14,9 +16,7 @@ static NSString* const kHockeyAppAlwaysSendStringsKey = @"hockeyapp-alert-always-send"; static NSString* const kHockeyAppDoNotSendStringsKey = @"hockeyapp-alert-do-not-send"; -@implementation BITHockeyManager (WMFExtensions) - -+ (NSString*)crashReportingIDFor:(NSString*)bundleID { +static NSString* WMFCurrentHockeyReportingID() { static NSDictionary* hockeyAPIKeysByBundleID; if (!hockeyAPIKeysByBundleID) { hockeyAPIKeysByBundleID = @{ @@ -26,9 +26,10 @@ @"org.wikimedia.wikipedia.developer": @"76947f174e31a9e33fe67d81ff31732e" }; } - - return hockeyAPIKeysByBundleID[bundleID]; + return WMFNotEmpty(hockeyAPIKeysByBundleID[[[NSBundle mainBundle] wmf_bundleIdentifier]]); } + +@implementation BITHockeyManager (WMFExtensions) + (NSString*)crashSendText { return MWLocalizedString(kHockeyAppSendStringsKey, nil); @@ -43,27 +44,11 @@ } - (void)wmf_setupAndStart { - NSString* bundleID = [WikipediaAppUtils bundleID]; - - if ([[BITHockeyManager sharedHockeyManager] wmf_setAPIKeyForBundleID:bundleID]) { - [[BITHockeyManager sharedHockeyManager] startManager]; - - [BITHockeyManager sharedHockeyManager].updateManager.updateSetting = BITUpdateCheckManually; - - [[BITHockeyManager sharedHockeyManager].authenticator authenticateInstallation]; - - [[BITHockeyManager sharedHockeyManager] wmf_setupCrashNotificationAlert]; - } -} - -- (BOOL)wmf_setAPIKeyForBundleID:(NSString*)bundleID { - NSString* crashReportingAppID = [[self class] crashReportingIDFor:bundleID]; - if (!crashReportingAppID) { - return NO; - } - [[BITHockeyManager sharedHockeyManager] configureWithIdentifier:crashReportingAppID]; - - return YES; + [[BITHockeyManager sharedHockeyManager] configureWithIdentifier:WMFCurrentHockeyReportingID()]; + [[BITHockeyManager sharedHockeyManager] startManager]; + [BITHockeyManager sharedHockeyManager].updateManager.updateSetting = BITUpdateCheckManually; + [[BITHockeyManager sharedHockeyManager].authenticator authenticateInstallation]; + [[BITHockeyManager sharedHockeyManager] wmf_setupCrashNotificationAlert]; } - (void)wmf_setupCrashNotificationAlert { diff --git a/Wikipedia/Categories/NSBundle+WMFInfoUtils.h b/Wikipedia/Categories/NSBundle+WMFInfoUtils.h index d106816..59bc583 100644 --- a/Wikipedia/Categories/NSBundle+WMFInfoUtils.h +++ b/Wikipedia/Categories/NSBundle+WMFInfoUtils.h @@ -22,10 +22,10 @@ /// @return The value for Info.plist key `CFBundleVersion`, i.e. the build number. - (NSString*)wmf_bundleVersion; -/// @return A string which represents the full app verison, including the build number (e.g. `4.1.3.96`). +/// @return A string which represents the full app verison, including the build number: `M.m.p.build`. - (NSString*)wmf_debugVersion; -/// Alias for `wmf_shortVersionString`. +/// @return A string that shows the full version in "TestFlight/Apple" format: `M.m.p (build)`. - (NSString*)wmf_releaseVersion; /// @return Either `wmf_releaseVersion` or `wmf_debugVersion` depending on the bundle identifier. diff --git a/Wikipedia/Categories/NSBundle+WMFInfoUtils.m b/Wikipedia/Categories/NSBundle+WMFInfoUtils.m index 485ff92..6a20d8f 100644 --- a/Wikipedia/Categories/NSBundle+WMFInfoUtils.m +++ b/Wikipedia/Categories/NSBundle+WMFInfoUtils.m @@ -7,11 +7,12 @@ // #import "NSBundle+WMFInfoUtils.h" +#import "WMFPreconditions.h" @implementation NSBundle (WMFInfoUtils) - (NSString*)wmf_bundleIdentifier { - return [self objectForInfoDictionaryKey:@"CFBundleIdentifier"]; + return WMFNotEmpty([self objectForInfoDictionaryKey:@"CFBundleIdentifier"]); } - (BOOL)wmf_isAppStoreBundleIdentifier { @@ -19,19 +20,19 @@ } - (NSString*)wmf_bundleVersion { - return [self objectForInfoDictionaryKey:@"CFBundleVersion"] ? : @""; + return WMFNotEmpty([self objectForInfoDictionaryKey:@"CFBundleVersion"]); } - (NSString*)wmf_shortVersionString { - return [self objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ? : @""; + return WMFNotEmpty([self objectForInfoDictionaryKey:@"CFBundleShortVersionString"]); } - (NSString*)wmf_releaseVersion { - return [self wmf_shortVersionString]; + return [[self wmf_shortVersionString] stringByAppendingFormat:@" (%@)", [self wmf_bundleVersion]]; } - (NSString*)wmf_debugVersion { - return [[self wmf_releaseVersion] stringByAppendingFormat:@".%@", [self wmf_bundleVersion] ? : @"0"]; + return [[self wmf_shortVersionString] stringByAppendingFormat:@".%@", [self wmf_bundleVersion]]; } - (NSString*)wmf_versionForCurrentBundleIdentifier { diff --git a/Wikipedia/mw-utils/WMFPreconditions.h b/Wikipedia/mw-utils/WMFPreconditions.h new file mode 100644 index 0000000..b23c2dc --- /dev/null +++ b/Wikipedia/mw-utils/WMFPreconditions.h @@ -0,0 +1,62 @@ +// +// WMFPreconditions.h +// Wikipedia +// +// Created by Brian Gerstle on 6/3/15. +// Copyright (c) 2015 Wikimedia Foundation. All rights reserved. +// + +/** + * @name Preconditions + * + * A collection macros which verify that a given value or expression meets a precondition, + * then returns the value. + * + * @warning Use the "Assert" variant if you don't want to throw an exception in production. + */ + +/** + * Generic way of checking if an object is empty. + * @warning This method uses `respondsToSelector:`, so be sure to not use it in a tight loop. + */ +static NSUInteger WMFCollectionSize(id collection) { + if ([collection respondsToSelector:@selector(length)]) { + return [collection length]; + } else if ([collection respondsToSelector:@selector(count)]) { + return [collection count]; + } else { + return 0; + } +} + +/** + * Verifies that a colleciton is not empty then returns it, where a collection is any object that contains + * other objects (i.e. responds to `length` or `count`). + * + * @see WMFCollectionSize + */ +static void WMFPreconditionNotEmpty(id collection) { + if (!collection || !WMFCollectionSize(collection)) { + [NSException raise:@"WMFPreconditionNilOrEmptyFailed" + format:@"Expected %@ to be a non-empty collection.", collection]; + } +} + +/** + * Macro which wraps WMFPreconditionNotEmpty so you can use it without losing type safety. + * + * Without this macro, @c WMFPreconditionNotEmpty would need to return @c id, which forgoes all + * static type checking. + */ +#define WMFNotEmpty(coll) (WMFPreconditionNotEmpty((coll)), (coll) ) + +#if DEBUG + +/// Same as WMFNotEmpty, but only throw in debug mode. +#define WMFAssertNotEmpty(coll) WMFNotEmpty(coll) + +#else + +#define WMFAssertNotEmpty(coll) coll + +#endif diff --git a/Wikipedia/mw-utils/WikipediaAppUtils.h b/Wikipedia/mw-utils/WikipediaAppUtils.h index 96f7797..c7b3f22 100644 --- a/Wikipedia/mw-utils/WikipediaAppUtils.h +++ b/Wikipedia/mw-utils/WikipediaAppUtils.h @@ -18,7 +18,6 @@ @interface WikipediaAppUtils : NSObject + (NSString*)appVersion; -+ (NSString*)bundleID; + (NSString*)formFactor; + (NSString*)versionedUserAgent; + (NSString*)localizedStringForKey:(NSString*)key; diff --git a/Wikipedia/mw-utils/WikipediaAppUtils.m b/Wikipedia/mw-utils/WikipediaAppUtils.m index 74011c5..aae28d5 100644 --- a/Wikipedia/mw-utils/WikipediaAppUtils.m +++ b/Wikipedia/mw-utils/WikipediaAppUtils.m @@ -18,7 +18,7 @@ } + (NSString*)bundleID { - return [[NSBundle mainBundle] wmf_bundleVersion]; + return [[NSBundle mainBundle] wmf_bundleIdentifier]; } + (NSString*)formFactor { diff --git a/WikipediaUnitTests/BITHockeyManagerWMFExtensionsTests.m b/WikipediaUnitTests/BITHockeyManagerWMFExtensionsTests.m deleted file mode 100644 index ed3075f..0000000 --- a/WikipediaUnitTests/BITHockeyManagerWMFExtensionsTests.m +++ /dev/null @@ -1,28 +0,0 @@ - -#define HC_SHORTHAND 1 -#define MOCKITO_SHORTHAND 1 - -#import <XCTest/XCTest.h> -#import <OCHamcrest/OCHamcrest.h> - -#import "BITHockeyManager+WMFExtensions.h" - - -@interface BITHockeyManagerWMFExtensionsTests : XCTestCase - -@end - - -@implementation BITHockeyManagerWMFExtensionsTests - -- (void)testKnownBundleID { - BOOL success = [[BITHockeyManager sharedHockeyManager] wmf_setAPIKeyForBundleID:@"org.wikimedia.wikipedia.tfalpha"]; - assertThat(@(success), is(isTrue())); -} - -- (void)testUnknownBundleID { - BOOL success = [[BITHockeyManager sharedHockeyManager] wmf_setAPIKeyForBundleID:@"org.wikimedia.wikipedia.garbage"]; - assertThat(@(success), is(isFalse())); -} - -@end \ No newline at end of file diff --git a/WikipediaUnitTests/WMFPreconditionsTests.m b/WikipediaUnitTests/WMFPreconditionsTests.m new file mode 100644 index 0000000..f241d29 --- /dev/null +++ b/WikipediaUnitTests/WMFPreconditionsTests.m @@ -0,0 +1,46 @@ +// +// WMFPreconditionsTests.m +// Wikipedia +// +// Created by Brian Gerstle on 6/3/15. +// Copyright (c) 2015 Wikimedia Foundation. All rights reserved. +// + +#import <UIKit/UIKit.h> +#import <XCTest/XCTest.h> +#import "WMFPreconditions.h" + +#define HC_SHORTHAND 1 +#import <OCHamcrest/OCHamcrest.h> + +#define MOCKITO_SHORTHAND 1 +#import <OCMockito/OCMockito.h> + +@interface WMFPreconditionsTests : XCTestCase +@end + +@implementation WMFPreconditionsTests + +- (void)testDoesNotThrowWithNonEmptyCollection { + NSArray* nonEmptyCollections = @[@[@0], + @"foo", + [NSSet setWithObject:@0], + @{@"foo": @"bar"}]; + [nonEmptyCollections enumerateObjectsUsingBlock:^(id coll, NSUInteger idx, BOOL* stop) { + id result; + XCTAssertNoThrow(result = WMFNotEmpty(coll)); + assertThat(result, is(nonEmptyCollections[idx])); + }]; +} + +- (void)testThrowsWhenGivenEmptyCollections { + NSArray* emptyCollections = @[@[], + @"", + [NSSet new], + @{}]; + [emptyCollections enumerateObjectsUsingBlock:^(id coll, NSUInteger idx, BOOL* stop) { + XCTAssertThrows(WMFNotEmpty(coll)); + }]; +} + +@end -- To view, visit https://gerrit.wikimedia.org/r/215659 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I97730f9f599e8fbb6f8c0662b39a5b8bb9bf8220 Gerrit-PatchSet: 1 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Bgerstle <bgers...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits