-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8962d23
commit d91d92d
Showing
3 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#import <XCTest/XCTest.h> | ||
|
||
@import WordPressSharedObjC; | ||
|
||
@interface CaptureLogs : NSObject<WordPressLoggingDelegate> | ||
|
||
@property (nonatomic, strong) NSMutableArray *infoLogs; | ||
@property (nonatomic, strong) NSMutableArray *errorLogs; | ||
|
||
@end | ||
|
||
@implementation CaptureLogs | ||
|
||
- (instancetype)init | ||
{ | ||
if ((self = [super init])) { | ||
self.infoLogs = [NSMutableArray new]; | ||
self.errorLogs = [NSMutableArray new]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)logInfo:(NSString *)str | ||
{ | ||
[self.infoLogs addObject:str]; | ||
} | ||
|
||
- (void)logError:(NSString *)str | ||
{ | ||
[self.errorLogs addObject:str]; | ||
} | ||
|
||
@end | ||
|
||
@interface LoggingTest : XCTestCase | ||
|
||
@property (nonatomic, strong) CaptureLogs *logger; | ||
|
||
@end | ||
|
||
@implementation LoggingTest | ||
|
||
- (void)setUp | ||
{ | ||
self.logger = [CaptureLogs new]; | ||
WPSharedSetLoggingDelegate(self.logger); | ||
} | ||
|
||
- (void)testLogging | ||
{ | ||
WPSharedLogInfo(@"This is an info log"); | ||
WPSharedLogInfo(@"This is an info log %@", @"with an argument"); | ||
XCTAssertEqualObjects(self.logger.infoLogs, (@[@"This is an info log", @"This is an info log with an argument"])); | ||
|
||
WPSharedLogError(@"This is an error log"); | ||
WPSharedLogError(@"This is an error log %@", @"with an argument"); | ||
XCTAssertEqualObjects(self.logger.errorLogs, (@[@"This is an error log", @"This is an error log with an argument"])); | ||
} | ||
|
||
- (void)testUnimplementedLoggingMethod | ||
{ | ||
XCTAssertNoThrow(WPSharedLogVerbose(@"verbose logging is not implemented")); | ||
} | ||
|
||
- (void)testNoLogging | ||
{ | ||
WPSharedSetLoggingDelegate(nil); | ||
XCTAssertNoThrow(WPSharedLogInfo(@"this log should not be printed")); | ||
XCTAssertEqual(self.logger.infoLogs.count, 0); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import XCTest | ||
|
||
@testable import WordPressShared | ||
|
||
private class CaptureLogs: NSObject, WordPressLoggingDelegate { | ||
var verboseLogs = [String]() | ||
var debugLogs = [String]() | ||
var infoLogs = [String]() | ||
var warningLogs = [String]() | ||
var errorLogs = [String]() | ||
|
||
func logError(_ str: String) { | ||
errorLogs.append(str) | ||
} | ||
|
||
func logWarning(_ str: String) { | ||
warningLogs.append(str) | ||
} | ||
|
||
func logInfo(_ str: String) { | ||
infoLogs.append(str) | ||
} | ||
|
||
func logDebug(_ str: String) { | ||
debugLogs.append(str) | ||
} | ||
|
||
func logVerbose(_ str: String) { | ||
verboseLogs.append(str) | ||
} | ||
|
||
} | ||
|
||
class LoggingTest: XCTestCase { | ||
|
||
private let logger = CaptureLogs() | ||
|
||
override func setUp() { | ||
WPSharedSetLoggingDelegate(logger) | ||
} | ||
|
||
func testLogging() { | ||
WPSharedLogVerbose("This is a verbose log") | ||
WPSharedLogVerbose("This is a verbose log %@", "with an argument") | ||
XCTAssertEqual(self.logger.verboseLogs, ["This is a verbose log", "This is a verbose log with an argument"]) | ||
|
||
WPSharedLogDebug("This is a debug log") | ||
WPSharedLogDebug("This is a debug log %@", "with an argument") | ||
XCTAssertEqual(self.logger.debugLogs, ["This is a debug log", "This is a debug log with an argument"]) | ||
|
||
WPSharedLogInfo("This is an info log") | ||
WPSharedLogInfo("This is an info log %@", "with an argument") | ||
XCTAssertEqual(self.logger.infoLogs, ["This is an info log", "This is an info log with an argument"]) | ||
|
||
WPSharedLogWarning("This is a warning log") | ||
WPSharedLogWarning("This is a warning log %@", "with an argument") | ||
XCTAssertEqual(self.logger.warningLogs, ["This is a warning log", "This is a warning log with an argument"]) | ||
|
||
WPSharedLogError("This is an error log") | ||
WPSharedLogError("This is an error log %@", "with an argument") | ||
XCTAssertEqual(self.logger.errorLogs, ["This is an error log", "This is an error log with an argument"]) | ||
} | ||
|
||
func testNoLogging() { | ||
WPSharedSetLoggingDelegate(nil); | ||
XCTAssertNoThrow(WPSharedLogInfo("this log should not be printed")); | ||
XCTAssertEqual(self.logger.infoLogs.count, 0); | ||
} | ||
|
||
} |