From f148003fb3dc58cc3157aab299aa9a0bef7fb8ae Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 7 Dec 2017 10:42:10 -0500 Subject: [PATCH 1/3] Convert logTag to property. --- SignalServiceKit/src/Util/NSObject+OWS.h | 4 ++-- .../ShareViewController.swift | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/SignalServiceKit/src/Util/NSObject+OWS.h b/SignalServiceKit/src/Util/NSObject+OWS.h index 548437066..49ffe6b5a 100644 --- a/SignalServiceKit/src/Util/NSObject+OWS.h +++ b/SignalServiceKit/src/Util/NSObject+OWS.h @@ -8,9 +8,9 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Logging -+ (NSString *)logTag; +@property (nonatomic) NSString *logTag; -- (NSString *)logTag; ++ (NSString *)logTag; @end diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index 689acce43..ca9093864 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -18,7 +18,7 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S override open func loadView() { super.loadView() - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") // This should be the first thing we do. let appContext = ShareAppExtensionContext(rootViewController:self) @@ -103,7 +103,7 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S } private func activate() { - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") // We don't need to use "screen protection" in the SAE. @@ -162,7 +162,7 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S func databaseViewRegistrationComplete() { AssertIsOnMainThread() - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") if TSAccountManager.isRegistered() { Logger.info("\(self.logTag) localNumber: \(TSAccountManager.localNumber)") @@ -197,7 +197,7 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S func registrationStateDidChange() { AssertIsOnMainThread() - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") if TSAccountManager.isRegistered() { Logger.info("\(self.logTag) localNumber: \(TSAccountManager.localNumber)") @@ -211,7 +211,7 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S } private func ensureRootViewController() { - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") guard !TSDatabaseView.hasPendingViewRegistrations() else { return @@ -285,7 +285,7 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S override open func viewDidLoad() { super.viewDidLoad() - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") if isReadyForAppExtensions { activate() @@ -293,19 +293,19 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S } override open func viewWillAppear(_ animated: Bool) { - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") super.viewWillAppear(animated) } override open func viewDidAppear(_ animated: Bool) { - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") super.viewDidAppear(animated) } override open func viewWillDisappear(_ animated: Bool) { - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") super.viewWillDisappear(animated) @@ -313,7 +313,7 @@ public class ShareViewController: UINavigationController, SAELoadViewDelegate, S } override open func viewDidDisappear(_ animated: Bool) { - Logger.debug("\(self.logTag()) \(#function)") + Logger.debug("\(self.logTag) \(#function)") super.viewDidDisappear(animated) From 1be828574dbe635fdfd6972ea0899782e71c42bb Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 7 Dec 2017 14:33:54 -0500 Subject: [PATCH 2/3] Respond to CR. --- SignalMessaging/utils/SwiftSingletons.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SignalMessaging/utils/SwiftSingletons.swift b/SignalMessaging/utils/SwiftSingletons.swift index b69231b7b..a19ef4d80 100644 --- a/SignalMessaging/utils/SwiftSingletons.swift +++ b/SignalMessaging/utils/SwiftSingletons.swift @@ -19,10 +19,10 @@ public class SwiftSingletons: NSObject { } let singletonClassName = String(describing:type(of:singleton)) guard !classSet.contains(singletonClassName) else { - owsFail("\(self.logTag()) in \(#function) Duplicate singleton: \(singletonClassName).") + owsFail("\(self.logTag) in \(#function) Duplicate singleton: \(singletonClassName).") return } - Logger.verbose("\(self.logTag()) in \(#function) Registering singleton: \(singletonClassName).") + Logger.verbose("\(self.logTag) in \(#function) Registering singleton: \(singletonClassName).") classSet.insert(singletonClassName) } From f7bcf1d04d9bec8e5a61cff9c28c89973d30fa8b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 7 Dec 2017 14:44:38 -0500 Subject: [PATCH 3/3] Fix tests. --- Signal.xcodeproj/project.pbxproj | 17 +++++++++++++++-- Signal/test/util/SearcherTest.swift | 1 + SignalMessaging/utils/Searcher.swift | 2 +- SignalMessaging/utils/SwiftSingletons.swift | 3 +++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index ab456fc2f..922d45ec1 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -102,11 +102,11 @@ 3478504C1FD7496D007B8332 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B66DBF4919D5BBC8006EA940 /* Images.xcassets */; }; 347850551FD749C0007B8332 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = B6F509951AA53F760068F56A /* Localizable.strings */; }; 347850571FD86544007B8332 /* SAEFailedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850561FD86544007B8332 /* SAEFailedViewController.swift */; }; + 347850591FD9972E007B8332 /* SwiftSingletons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850581FD9972E007B8332 /* SwiftSingletons.swift */; }; 347850691FD9B78A007B8332 /* AppSetup.m in Sources */ = {isa = PBXBuildFile; fileRef = 347850651FD9B789007B8332 /* AppSetup.m */; }; 3478506A1FD9B78A007B8332 /* AppSetup.h in Headers */ = {isa = PBXBuildFile; fileRef = 347850661FD9B789007B8332 /* AppSetup.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3478506B1FD9B78A007B8332 /* NoopCallMessageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850671FD9B78A007B8332 /* NoopCallMessageHandler.swift */; }; 3478506C1FD9B78A007B8332 /* NoopNotificationsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850681FD9B78A007B8332 /* NoopNotificationsManager.swift */; }; - 347850591FD9972E007B8332 /* SwiftSingletons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347850581FD9972E007B8332 /* SwiftSingletons.swift */; }; 3497DBEC1ECE257500DB2605 /* OWSCountryMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEB1ECE257500DB2605 /* OWSCountryMetadata.m */; }; 3497DBEF1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3497DBEE1ECE2E4700DB2605 /* DomainFrontingCountryViewController.m */; }; 34B0796D1FCF46B100E248C2 /* MainAppContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B0796B1FCF46B000E248C2 /* MainAppContext.m */; }; @@ -400,6 +400,13 @@ remoteGlobalIDString = 453518911FC63DBF00210559; remoteInfo = SignalMessaging; }; + 3478506D1FD9CFF4007B8332 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = D221A080169C9E5E00537ABF /* Project object */; + proxyType = 1; + remoteGlobalIDString = 453518911FC63DBF00210559; + remoteInfo = SignalMessaging; + }; 453518701FC635DD00210559 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = D221A080169C9E5E00537ABF /* Project object */; @@ -569,11 +576,11 @@ 3472229D1EB22FFE00E53955 /* AddToGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToGroupViewController.h; sourceTree = ""; }; 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToGroupViewController.m; sourceTree = ""; }; 347850561FD86544007B8332 /* SAEFailedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SAEFailedViewController.swift; sourceTree = ""; }; + 347850581FD9972E007B8332 /* SwiftSingletons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftSingletons.swift; sourceTree = ""; }; 347850651FD9B789007B8332 /* AppSetup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppSetup.m; sourceTree = ""; }; 347850661FD9B789007B8332 /* AppSetup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppSetup.h; sourceTree = ""; }; 347850671FD9B78A007B8332 /* NoopCallMessageHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoopCallMessageHandler.swift; sourceTree = ""; }; 347850681FD9B78A007B8332 /* NoopNotificationsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoopNotificationsManager.swift; sourceTree = ""; }; - 347850581FD9972E007B8332 /* SwiftSingletons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftSingletons.swift; sourceTree = ""; }; 348F2EAD1F0D21BC00D4ECE0 /* DeviceSleepManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceSleepManager.swift; sourceTree = ""; }; 3495BC911F1426B800B478F5 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = translations/ar.lproj/Localizable.strings; sourceTree = ""; }; 3497DBEA1ECE257500DB2605 /* OWSCountryMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSCountryMetadata.h; sourceTree = ""; }; @@ -2134,6 +2141,7 @@ buildRules = ( ); dependencies = ( + 3478506E1FD9CFF4007B8332 /* PBXTargetDependency */, B6AFCEBB19A93DA60098CFCB /* PBXTargetDependency */, ); name = SignalTests; @@ -2922,6 +2930,11 @@ target = 453518911FC63DBF00210559 /* SignalMessaging */; targetProxy = 34480B391FD0950000BC14EF /* PBXContainerItemProxy */; }; + 3478506E1FD9CFF4007B8332 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 453518911FC63DBF00210559 /* SignalMessaging */; + targetProxy = 3478506D1FD9CFF4007B8332 /* PBXContainerItemProxy */; + }; 453518711FC635DD00210559 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 453518671FC635DD00210559 /* SignalShareExtension */; diff --git a/Signal/test/util/SearcherTest.swift b/Signal/test/util/SearcherTest.swift index 9394a6cab..acf78653a 100644 --- a/Signal/test/util/SearcherTest.swift +++ b/Signal/test/util/SearcherTest.swift @@ -4,6 +4,7 @@ import XCTest @testable import Signal +@testable import SignalMessaging class SearcherTest: XCTestCase { diff --git a/SignalMessaging/utils/Searcher.swift b/SignalMessaging/utils/Searcher.swift index f38956c50..207177641 100644 --- a/SignalMessaging/utils/Searcher.swift +++ b/SignalMessaging/utils/Searcher.swift @@ -20,7 +20,7 @@ import Foundation } // A generic searching class, configurable with an indexing block -class Searcher { +public class Searcher { private let indexer: (T) -> String diff --git a/SignalMessaging/utils/SwiftSingletons.swift b/SignalMessaging/utils/SwiftSingletons.swift index a19ef4d80..cccfa2e7e 100644 --- a/SignalMessaging/utils/SwiftSingletons.swift +++ b/SignalMessaging/utils/SwiftSingletons.swift @@ -14,6 +14,9 @@ public class SwiftSingletons: NSObject { } public func register(_ singleton: AnyObject) { + guard !CurrentAppContext().isRunningTests else { + return + } guard _isDebugAssertConfiguration() else { return }