From bcbff499e4af0f65dce85d8e4de8281c7e8ded92 Mon Sep 17 00:00:00 2001 From: slightair Date: Sat, 1 Oct 2016 23:10:53 +0900 Subject: [PATCH 1/5] Use setUp and tearDown --- .../Tests/PURLoggerStandardPluginTest.swift | 66 +++++-------------- 1 file changed, 15 insertions(+), 51 deletions(-) diff --git a/Example/Tests/PURLoggerStandardPluginTest.swift b/Example/Tests/PURLoggerStandardPluginTest.swift index 17a1eca..528baac 100644 --- a/Example/Tests/PURLoggerStandardPluginTest.swift +++ b/Example/Tests/PURLoggerStandardPluginTest.swift @@ -7,7 +7,14 @@ class PURLoggerStandardPluginTest: XCTestCase { let logStoreOperationDispatchQueue = DispatchQueue(label: "Puree logger test") } - static var loggerConfiguration: TestLoggerConfiguration { + var loggerConfiguration: TestLoggerConfiguration! + var logger: PURLogger! + + var testLogStorage: TestLogStorage { + return loggerConfiguration.logStorage + } + + override func setUp() { let configuration = TestLoggerConfiguration() let logStoreDBPath = NSTemporaryDirectory() + "/PureeLoggerTest-\(UUID().uuidString).db" let logStore = PURLogStore(databasePath: logStoreDBPath) @@ -27,14 +34,16 @@ class PURLoggerStandardPluginTest: XCTestCase { PUROutputSetting(output: PURTestFailureOutput.self, tagPattern: "failure", settings: ["logStorage": logStorage]), ] - return configuration + loggerConfiguration = configuration + logger = PURLogger(configuration: configuration) } - func testChangeTagFilterPlugin() { - let loggerConfiguration = PURLoggerStandardPluginTest.loggerConfiguration - let logger = PURLogger(configuration: loggerConfiguration) - let testLogStorage = loggerConfiguration.logStorage + override func tearDown() { + logger.logStore().clearAll() + logger.shutdown() + } + func testChangeTagFilterPlugin() { XCTAssertEqual(testLogStorage.description, "") logger.post(["aaa": "123"], tag: "filter.test") @@ -43,16 +52,9 @@ class PURLoggerStandardPluginTest: XCTestCase { logger.post(["eee": "not filtered"], tag: "filter.testXXX") XCTAssertEqual(testLogStorage.description, "[filter.testXXX|aaa:123][filter.testXXX|bbb:456,ccc:789][filter.testXXX|eee:not filtered]") - - logger.logStore().clearAll() - logger.shutdown() } func testAppendParamFilterPlugin() { - let loggerConfiguration = PURLoggerStandardPluginTest.loggerConfiguration - let logger = PURLogger(configuration: loggerConfiguration) - let testLogStorage = loggerConfiguration.logStorage - XCTAssertEqual(testLogStorage.description, "") logger.post(["aaa": "123"], tag: "filter.append") @@ -61,16 +63,9 @@ class PURLoggerStandardPluginTest: XCTestCase { logger.post(["ccc": "789"], tag: "filter.append.yyy") XCTAssertEqual(testLogStorage.description, "[filter.append|aaa:123,ext:][filter.append.xxx|bbb:456,ext:xxx][filter.append.yyy|ccc:789,ext:yyy]") - - logger.logStore().clearAll() - logger.shutdown() } func testUnbufferedOutputPlugin() { - let loggerConfiguration = PURLoggerStandardPluginTest.loggerConfiguration - let logger = PURLogger(configuration: loggerConfiguration) - let testLogStorage = loggerConfiguration.logStorage - XCTAssertEqual(testLogStorage.description, "") logger.post(["aaa": "123"], tag: "test.hoge") @@ -78,16 +73,9 @@ class PURLoggerStandardPluginTest: XCTestCase { logger.post(["ddd": "12345"], tag: "debug") XCTAssertEqual(testLogStorage.description, "[test.hoge|aaa:123][test.fuga|bbb:456,ccc:789]") - - logger.logStore().clearAll() - logger.shutdown() } func testBufferedOutputPlugin_writeLog() { - let loggerConfiguration = PURLoggerStandardPluginTest.loggerConfiguration - let logger = PURLogger(configuration: loggerConfiguration) - let testLogStorage = loggerConfiguration.logStorage - expectation(forNotification: Notification.Name.PURBufferedOutputDidStart.rawValue, object: nil, handler: nil) waitForExpectations(timeout: 1.0, handler: nil) @@ -118,16 +106,9 @@ class PURLoggerStandardPluginTest: XCTestCase { XCTAssertTrue(logStorageContent.contains("{buffered.b|aaa:4}")) XCTAssertTrue(logStorageContent.contains("{buffered.a|aaa:5}")) XCTAssertFalse(logStorageContent.contains("{buffered.a|aaa:6}")) - - logger.logStore().clearAll() - logger.shutdown() } func testBufferedOutputPlugin_resumeStoredLogs() { - let loggerConfiguration = PURLoggerStandardPluginTest.loggerConfiguration - var logger = PURLogger(configuration: loggerConfiguration) - let testLogStorage = loggerConfiguration.logStorage - expectation(forNotification: Notification.Name.PURBufferedOutputDidStart.rawValue, object: nil, handler: nil) waitForExpectations(timeout: 1.0, handler: nil) @@ -163,16 +144,9 @@ class PURLoggerStandardPluginTest: XCTestCase { XCTAssertFalse(logStorageContent.contains("{buffered.d|aaa:4}")) XCTAssertFalse(logStorageContent.contains("{buffered.c|aaa:5}")) XCTAssertFalse(logStorageContent.contains("{buffered.c|aaa:6}")) - - logger.logStore().clearAll() - logger.shutdown() } func testBufferedOutputPlugin_periodicalFlushing() { - let loggerConfiguration = PURLoggerStandardPluginTest.loggerConfiguration - let logger = PURLogger(configuration: loggerConfiguration) - let testLogStorage = loggerConfiguration.logStorage - expectation(forNotification: Notification.Name.PURBufferedOutputDidStart.rawValue, object: nil, handler: nil) waitForExpectations(timeout: 1.0, handler: nil) @@ -193,16 +167,9 @@ class PURLoggerStandardPluginTest: XCTestCase { XCTAssertTrue(logStorageContent.contains("{buffered.e|aaa:1}")) XCTAssertTrue(logStorageContent.contains("{buffered.e|aaa:2}")) XCTAssertTrue(logStorageContent.contains("{buffered.f|aaa:3}")) - - logger.logStore().clearAll() - logger.shutdown() } func testBufferedOutputPlugin_retry() { - let loggerConfiguration = PURLoggerStandardPluginTest.loggerConfiguration - let logger = PURLogger(configuration: loggerConfiguration) - let testLogStorage = loggerConfiguration.logStorage - expectation(forNotification: Notification.Name.PURBufferedOutputDidStart.rawValue, object: nil, handler: nil) waitForExpectations(timeout: 1.0, handler: nil) @@ -233,8 +200,5 @@ class PURLoggerStandardPluginTest: XCTestCase { // scheduled after 8sec waitForExpectations(timeout: 9.0, handler: nil) XCTAssertEqual(testLogStorage.description, "[error][error][error][error]") - - logger.logStore().clearAll() - logger.shutdown() } } From a62068579c2739eeaaaa535f5e215ad41659d03f Mon Sep 17 00:00:00 2001 From: slightair Date: Sun, 2 Oct 2016 19:46:52 +0900 Subject: [PATCH 2/5] Remove 'use_frameworks!' from test project --- Example/Podfile | 1 - Example/Podfile.lock | 6 +++--- Example/Puree.xcodeproj/project.pbxproj | 8 ++++---- Example/Tests/PURLogStoreTest.swift | 1 - Example/Tests/PURLoggerStandardPluginTest.swift | 1 - Example/Tests/PURLoggerTagPatternMatchingTest.swift | 1 - Example/Tests/PURTestAppendParamFilter.swift | 1 - Example/Tests/PURTestBufferedOutput.swift | 1 - Example/Tests/PURTestChangeTagFilter.swift | 1 - Example/Tests/PURTestFailureOutput.swift | 1 - Example/Tests/PURTestOutput.swift | 1 - 11 files changed, 7 insertions(+), 16 deletions(-) diff --git a/Example/Podfile b/Example/Podfile index c75f320..79c178f 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -1,5 +1,4 @@ source 'https://github.com/CocoaPods/Specs' -use_frameworks! target 'PureeTests' do pod "Puree", :path => "../" diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 5b54387..0fe9971 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -7,7 +7,7 @@ PODS: - CocoaLumberjack/Core - CocoaLumberjack/Extensions (2.4.0): - CocoaLumberjack/Default - - Puree (1.1.0): + - Puree (2.0.0): - YapDatabase (~> 2.9.2) - Reachability (3.2) - YapDatabase (2.9.2): @@ -70,10 +70,10 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: CocoaLumberjack: aa9dcab71bdf9eaf2a63bbd9ddc87863efe45457 - Puree: a71cf999f4bb504c2ed3257dbabc7377aaaac699 + Puree: dce923c586654f0b301801a2aecb6917cf6f8e82 Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96 YapDatabase: b1e43555a34a5298e23a045be96817a5ef0da58f -PODFILE CHECKSUM: ac4495e7212e7848dc39e4702fb4f7622665bd74 +PODFILE CHECKSUM: af5047754632caf7b29086116f921595e64a2970 COCOAPODS: 1.1.0.rc.2 diff --git a/Example/Puree.xcodeproj/project.pbxproj b/Example/Puree.xcodeproj/project.pbxproj index d5343cf..8511a6e 100644 --- a/Example/Puree.xcodeproj/project.pbxproj +++ b/Example/Puree.xcodeproj/project.pbxproj @@ -16,12 +16,11 @@ 5760F1D41BB7CD26009A143D /* PURTestOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5760F1CC1BB7CD26009A143D /* PURTestOutput.swift */; }; 5760F1D51BB7CD26009A143D /* TestLogStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5760F1CD1BB7CD26009A143D /* TestLogStorage.swift */; }; 57ABD6DC1D979CE300B3B52D /* PURLoggerStandardPluginTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57ABD6DB1D979CE300B3B52D /* PURLoggerStandardPluginTest.swift */; }; - 63558BFD2171AF61402ECA48 /* Pods_PureeTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 501F680AA62C916D4E54EF9E /* Pods_PureeTests.framework */; }; + 9F6C6315B68326F76296B9BF /* libPods-PureeTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F114EB7406FEADE718D7A6E5 /* libPods-PureeTests.a */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 2D02199567B505DD66CAAACC /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; - 501F680AA62C916D4E54EF9E /* Pods_PureeTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PureeTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5760F1B91BB7CBFC009A143D /* PureeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PureeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 5760F1BD1BB7CBFD009A143D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5760F1C11BB7CC7C009A143D /* PureeTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PureeTests-Bridging-Header.h"; sourceTree = ""; }; @@ -41,6 +40,7 @@ 6412CE7C1B65D0BBA34A4332 /* Puree.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Puree.podspec; path = ../Puree.podspec; sourceTree = ""; }; A74A5DDA68461D97C2E89F24 /* Pods-PureeTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PureeTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PureeTests/Pods-PureeTests.debug.xcconfig"; sourceTree = ""; }; D7F43655475AA82E9B4A327D /* Pods-PureeTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PureeTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-PureeTests/Pods-PureeTests.release.xcconfig"; sourceTree = ""; }; + F114EB7406FEADE718D7A6E5 /* libPods-PureeTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PureeTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -48,7 +48,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 63558BFD2171AF61402ECA48 /* Pods_PureeTests.framework in Frameworks */, + 9F6C6315B68326F76296B9BF /* libPods-PureeTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -116,7 +116,7 @@ 6003F58F195388D20070C39A /* CoreGraphics.framework */, 6003F591195388D20070C39A /* UIKit.framework */, 6003F5AF195388D20070C39A /* XCTest.framework */, - 501F680AA62C916D4E54EF9E /* Pods_PureeTests.framework */, + F114EB7406FEADE718D7A6E5 /* libPods-PureeTests.a */, ); name = Frameworks; sourceTree = ""; diff --git a/Example/Tests/PURLogStoreTest.swift b/Example/Tests/PURLogStoreTest.swift index 545c488..9bb3408 100644 --- a/Example/Tests/PURLogStoreTest.swift +++ b/Example/Tests/PURLogStoreTest.swift @@ -1,4 +1,3 @@ -import Puree import XCTest class PURLogStoreTest: XCTestCase { diff --git a/Example/Tests/PURLoggerStandardPluginTest.swift b/Example/Tests/PURLoggerStandardPluginTest.swift index 528baac..7644189 100644 --- a/Example/Tests/PURLoggerStandardPluginTest.swift +++ b/Example/Tests/PURLoggerStandardPluginTest.swift @@ -1,4 +1,3 @@ -import Puree import XCTest class PURLoggerStandardPluginTest: XCTestCase { diff --git a/Example/Tests/PURLoggerTagPatternMatchingTest.swift b/Example/Tests/PURLoggerTagPatternMatchingTest.swift index 212abf6..c1c2954 100644 --- a/Example/Tests/PURLoggerTagPatternMatchingTest.swift +++ b/Example/Tests/PURLoggerTagPatternMatchingTest.swift @@ -1,4 +1,3 @@ -import Puree import XCTest class PURLoggerTagPatternMatchingTest: XCTestCase { diff --git a/Example/Tests/PURTestAppendParamFilter.swift b/Example/Tests/PURTestAppendParamFilter.swift index 20d05ce..95c43c6 100644 --- a/Example/Tests/PURTestAppendParamFilter.swift +++ b/Example/Tests/PURTestAppendParamFilter.swift @@ -1,5 +1,4 @@ import Foundation -import Puree class PURTestAppendParamFilter: PURFilter { override func logs(object: Any, tag: String, captured: String?) -> [PURLog] { diff --git a/Example/Tests/PURTestBufferedOutput.swift b/Example/Tests/PURTestBufferedOutput.swift index f6da552..1b1b7a7 100644 --- a/Example/Tests/PURTestBufferedOutput.swift +++ b/Example/Tests/PURTestBufferedOutput.swift @@ -1,5 +1,4 @@ import Foundation -import Puree class PURTestBufferedOutput: PURBufferedOutput { var logStorage: TestLogStorage! diff --git a/Example/Tests/PURTestChangeTagFilter.swift b/Example/Tests/PURTestChangeTagFilter.swift index 59f3ec2..dde743f 100644 --- a/Example/Tests/PURTestChangeTagFilter.swift +++ b/Example/Tests/PURTestChangeTagFilter.swift @@ -1,5 +1,4 @@ import Foundation -import Puree class PURTestChangeTagFilter: PURFilter { var tagSuffix: String? diff --git a/Example/Tests/PURTestFailureOutput.swift b/Example/Tests/PURTestFailureOutput.swift index f253241..dbf26fe 100644 --- a/Example/Tests/PURTestFailureOutput.swift +++ b/Example/Tests/PURTestFailureOutput.swift @@ -1,5 +1,4 @@ import Foundation -import Puree class PURTestFailureOutput: PURBufferedOutput { var logStorage: TestLogStorage! diff --git a/Example/Tests/PURTestOutput.swift b/Example/Tests/PURTestOutput.swift index b01c17b..e08299a 100644 --- a/Example/Tests/PURTestOutput.swift +++ b/Example/Tests/PURTestOutput.swift @@ -1,5 +1,4 @@ import Foundation -import Puree class PURTestOutput: PUROutput { var logStorage: TestLogStorage! From 78919d5acc16374abad0de617e17ca6e6ca1f5d6 Mon Sep 17 00:00:00 2001 From: slightair Date: Sun, 2 Oct 2016 21:27:20 +0900 Subject: [PATCH 3/5] Rename some LogStore method --- Example/Tests/PURLogStoreTest.swift | 40 +++++++++++++++++------------ Pod/Classes/PURBufferedOutput.m | 9 +++---- Pod/Classes/PURLogStore.h | 8 +++--- Pod/Classes/PURLogStore.m | 10 ++++---- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/Example/Tests/PURLogStoreTest.swift b/Example/Tests/PURLogStoreTest.swift index 9bb3408..a69173a 100644 --- a/Example/Tests/PURLogStoreTest.swift +++ b/Example/Tests/PURLogStoreTest.swift @@ -24,10 +24,10 @@ class PURLogStoreTest: XCTestCase { logStore.clearAll() } - func assertLogStoreLogCount(pattern: String, output: PUROutput, expectedCount: Int, line: Int = #line) { + func assertLogCount(of output: PUROutput, expectedCount: Int, line: Int = #line) { let countExpectation = expectation(description: "log count") var count = -1 - logStore.retrieveLogs(forPattern: pattern, output:output) { logs in + logStore.retrieveLogs(for: output) { logs in count = logs.count countExpectation.fulfill() } @@ -37,16 +37,17 @@ class PURLogStoreTest: XCTestCase { func addTestLog(_ log: PURLog, output: PUROutput, description: String) { let addExpectation = expectation(description: description) - logStore.add(log, from: output) { addExpectation.fulfill() } + logStore.add(log, for: output) { addExpectation.fulfill() } } func addTestLogs(_ logs: [PURLog], output: PUROutput, description: String) { let addExpectation = expectation(description: description) - logStore.add(logs, from: output) { addExpectation.fulfill() } + logStore.add(logs, for: output) { addExpectation.fulfill() } } func testAddLog() { - assertLogStoreLogCount(pattern: "test.*", output: outputA, expectedCount: 0) + assertLogCount(of: outputA, expectedCount: 0) + assertLogCount(of: outputB, expectedCount: 0) addTestLog(PURLog(tag: "test.apple", date: Date(), userInfo: [:]), output: outputA, description: "add test log 1") addTestLog(PURLog(tag: "test.apple", date: Date(), userInfo: [:]), output: outputA, description: "add test log 2") @@ -56,11 +57,13 @@ class PURLogStoreTest: XCTestCase { waitForExpectations(timeout: 1.0, handler: nil) - assertLogStoreLogCount(pattern: "test.*", output: outputA, expectedCount: 4) + assertLogCount(of: outputA, expectedCount: 4) + assertLogCount(of: outputB, expectedCount: 1) } func testAddLogs() { - assertLogStoreLogCount(pattern: "test.*", output: outputA, expectedCount: 0) + assertLogCount(of: outputA, expectedCount: 0) + assertLogCount(of: outputB, expectedCount: 0) addTestLogs([ PURLog(tag: "test.apple", date: Date(), userInfo: [:]), @@ -77,7 +80,8 @@ class PURLogStoreTest: XCTestCase { waitForExpectations(timeout: 1.0, handler: nil) - assertLogStoreLogCount(pattern: "test.*", output: outputA, expectedCount: 5) + assertLogCount(of: outputA, expectedCount: 5) + assertLogCount(of: outputB, expectedCount: 2) } func testRemoveLogs() { @@ -101,19 +105,23 @@ class PURLogStoreTest: XCTestCase { waitForExpectations(timeout: 1.0, handler: nil) - assertLogStoreLogCount(pattern: "test.*", output: outputA, expectedCount: 5) - assertLogStoreLogCount(pattern: "test.*", output: outputB, expectedCount: 2) + assertLogCount(of: outputA, expectedCount: 5) + assertLogCount(of: outputB, expectedCount: 2) let removeExpectation = expectation(description: "remove logs") - logStore.remove(firstChunk, from: outputA) { removeExpectation.fulfill() } + logStore.remove(firstChunk, for: outputA) { removeExpectation.fulfill() } waitForExpectations(timeout: 1.0, handler: nil) - assertLogStoreLogCount(pattern: "test.*", output: outputA, expectedCount: 3) - assertLogStoreLogCount(pattern: "test.*", output: outputB, expectedCount: 2) + assertLogCount(of: outputA, expectedCount: 3) + assertLogCount(of: outputB, expectedCount: 2) } func testStressTest() { + assertLogCount(of: outputA, expectedCount: 0) + assertLogCount(of: outputB, expectedCount: 0) + assertLogCount(of: outputC, expectedCount: 0) + // write (3 + 3 + 4) * 100 logs (1000 logs) for i in 1...100 { addTestLogs([ @@ -142,8 +150,8 @@ class PURLogStoreTest: XCTestCase { } waitForExpectations(timeout: 8.0, handler: nil) - assertLogStoreLogCount(pattern: "testA.*", output: outputA, expectedCount: 300) - assertLogStoreLogCount(pattern: "testB.*", output: outputB, expectedCount: 300) - assertLogStoreLogCount(pattern: "testC.*", output: outputC, expectedCount: 1400) + assertLogCount(of: outputA, expectedCount: 300) + assertLogCount(of: outputB, expectedCount: 300) + assertLogCount(of: outputC, expectedCount: 1400) } } diff --git a/Pod/Classes/PURBufferedOutput.m b/Pod/Classes/PURBufferedOutput.m index 72be676..79b09e6 100644 --- a/Pod/Classes/PURBufferedOutput.m +++ b/Pod/Classes/PURBufferedOutput.m @@ -130,15 +130,14 @@ - (void)tick - (void)retrieveLogs:(PURLogStoreRetrieveCompletionBlock)completion { [self.buffer removeAllObjects]; - [self.logStore retrieveLogsForPattern:self.tagPattern - output:self - completion:completion]; + [self.logStore retrieveLogsForOutput:self + completion:completion]; } - (void)emitLog:(PURLog *)log { [self.buffer addObject:log]; - [self.logStore addLog:log fromOutput:self completion:^{ + [self.logStore addLog:log forOutput:self completion:^{ if ([self.buffer count] >= self.logLimit) { [self flush]; } @@ -171,7 +170,7 @@ - (void)callWriteChunk:(PURBufferedOutputChunk *)chunk [[NSNotificationCenter defaultCenter] postNotificationName:PURBufferedOutputDidTryWriteChunkNotification object:self]; if (success) { - [self.logStore removeLogs:chunk.logs fromOutput:self completion:nil]; + [self.logStore removeLogs:chunk.logs forOutput:self completion:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:PURBufferedOutputDidSuccessWriteChunkNotification object:self]; return; diff --git a/Pod/Classes/PURLogStore.h b/Pod/Classes/PURLogStore.h index 6e2ab28..39f75e1 100644 --- a/Pod/Classes/PURLogStore.h +++ b/Pod/Classes/PURLogStore.h @@ -14,10 +14,10 @@ typedef void(^PURLogStoreRetrieveCompletionBlock)(NSArray *logs); - (BOOL)prepare; -- (void)retrieveLogsForPattern:(NSString *)pattern output:(PUROutput *)output completion:(PURLogStoreRetrieveCompletionBlock)completion; -- (void)addLog:(PURLog *)log fromOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion; -- (void)addLogs:(NSArray *)logs fromOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion; -- (void)removeLogs:(NSArray *)logs fromOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion; +- (void)retrieveLogsForOutput:(PUROutput *)output completion:(PURLogStoreRetrieveCompletionBlock)completion; +- (void)addLog:(PURLog *)log forOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion; +- (void)addLogs:(NSArray *)logs forOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion; +- (void)removeLogs:(NSArray *)logs forOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion; - (void)clearAll; @end diff --git a/Pod/Classes/PURLogStore.m b/Pod/Classes/PURLogStore.m index 0af282e..6b0784e 100644 --- a/Pod/Classes/PURLogStore.m +++ b/Pod/Classes/PURLogStore.m @@ -99,7 +99,7 @@ + (NSString *)defaultDatabasePath return databasePath; } -- (void)retrieveLogsForPattern:(NSString *)pattern output:(PUROutput *)output completion:(PURLogStoreRetrieveCompletionBlock)completion; +- (void)retrieveLogsForOutput:(PUROutput *)output completion:(PURLogStoreRetrieveCompletionBlock)completion; { NSAssert(self.databaseConnection, @"Database connection is not available"); @@ -120,14 +120,14 @@ - (void)retrieveLogsForPattern:(NSString *)pattern output:(PUROutput *)output co }]; } -- (void)addLog:(PURLog *)log fromOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion +- (void)addLog:(PURLog *)log forOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion { NSAssert(self.databaseConnection, @"Database connection is not available"); - [self addLogs:@[ log ] fromOutput:output completion:completion]; + [self addLogs:@[ log ] forOutput:output completion:completion]; } -- (void)addLogs:(NSArray *)logs fromOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion +- (void)addLogs:(NSArray *)logs forOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion { NSAssert(self.databaseConnection, @"Database connection is not available"); @@ -141,7 +141,7 @@ - (void)addLogs:(NSArray *)logs fromOutput:(PUROutput *)output complet completionBlock:completion]; } -- (void)removeLogs:(NSArray *)logs fromOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion +- (void)removeLogs:(NSArray *)logs forOutput:(PUROutput *)output completion:(nullable dispatch_block_t)completion { NSAssert(self.databaseConnection, @"Database connection is not available"); From fa6f857f896706e18f1d43a382dc2205ae0a3a90 Mon Sep 17 00:00:00 2001 From: slightair Date: Sun, 2 Oct 2016 21:28:43 +0900 Subject: [PATCH 4/5] Remove unnecessary import --- Example/Tests/PureeTests-Bridging-Header.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Example/Tests/PureeTests-Bridging-Header.h b/Example/Tests/PureeTests-Bridging-Header.h index be5956e..33b350d 100644 --- a/Example/Tests/PureeTests-Bridging-Header.h +++ b/Example/Tests/PureeTests-Bridging-Header.h @@ -2,6 +2,4 @@ // Use this file to import your target's public headers that you would like to expose to Swift. // -#import -#import #import From f4291b6f713cd46685c38e93ed51543e9fcfd9b3 Mon Sep 17 00:00:00 2001 From: slightair Date: Sun, 9 Oct 2016 15:41:34 +0900 Subject: [PATCH 5/5] Use String(describing: object) --- .../Tests/PURLoggerStandardPluginTest.swift | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Example/Tests/PURLoggerStandardPluginTest.swift b/Example/Tests/PURLoggerStandardPluginTest.swift index 7644189..7a47297 100644 --- a/Example/Tests/PURLoggerStandardPluginTest.swift +++ b/Example/Tests/PURLoggerStandardPluginTest.swift @@ -43,42 +43,42 @@ class PURLoggerStandardPluginTest: XCTestCase { } func testChangeTagFilterPlugin() { - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") logger.post(["aaa": "123"], tag: "filter.test") logger.post(["bbb": "456", "ccc": "789"], tag: "filter.test") logger.post(["ddd": "12345"], tag: "debug") logger.post(["eee": "not filtered"], tag: "filter.testXXX") - XCTAssertEqual(testLogStorage.description, "[filter.testXXX|aaa:123][filter.testXXX|bbb:456,ccc:789][filter.testXXX|eee:not filtered]") + XCTAssertEqual(String(describing: testLogStorage), "[filter.testXXX|aaa:123][filter.testXXX|bbb:456,ccc:789][filter.testXXX|eee:not filtered]") } func testAppendParamFilterPlugin() { - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") logger.post(["aaa": "123"], tag: "filter.append") logger.post(["bbb": "456"], tag: "filter.append.xxx") logger.post(["ddd": "12345"], tag: "debug") logger.post(["ccc": "789"], tag: "filter.append.yyy") - XCTAssertEqual(testLogStorage.description, "[filter.append|aaa:123,ext:][filter.append.xxx|bbb:456,ext:xxx][filter.append.yyy|ccc:789,ext:yyy]") + XCTAssertEqual(String(describing: testLogStorage), "[filter.append|aaa:123,ext:][filter.append.xxx|bbb:456,ext:xxx][filter.append.yyy|ccc:789,ext:yyy]") } func testUnbufferedOutputPlugin() { - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") logger.post(["aaa": "123"], tag: "test.hoge") logger.post(["bbb": "456", "ccc": "789"], tag: "test.fuga") logger.post(["ddd": "12345"], tag: "debug") - XCTAssertEqual(testLogStorage.description, "[test.hoge|aaa:123][test.fuga|bbb:456,ccc:789]") + XCTAssertEqual(String(describing: testLogStorage), "[test.hoge|aaa:123][test.fuga|bbb:456,ccc:789]") } func testBufferedOutputPlugin_writeLog() { expectation(forNotification: Notification.Name.PURBufferedOutputDidStart.rawValue, object: nil, handler: nil) waitForExpectations(timeout: 1.0, handler: nil) - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") expectation(forNotification: Notification.Name.PURBufferedOutputDidSuccessWriteChunk.rawValue, object: nil, handler: nil) @@ -86,7 +86,7 @@ class PURLoggerStandardPluginTest: XCTestCase { logger.post(["aaa": "2"], tag: "buffered.a") logger.post(["aaa": "3"], tag: "buffered.b") - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") logger.post(["aaa": "4"], tag: "buffered.b") logger.post(["zzz": "###"], tag: "unbuffered") @@ -97,7 +97,7 @@ class PURLoggerStandardPluginTest: XCTestCase { waitForExpectations(timeout: 1.0, handler: nil) - let logStorageContent = testLogStorage.description + let logStorageContent = String(describing: testLogStorage) XCTAssertTrue(logStorageContent.contains("[unbuffered|zzz:###]")) XCTAssertTrue(logStorageContent.contains("{buffered.a|aaa:1}")) XCTAssertTrue(logStorageContent.contains("{buffered.a|aaa:2}")) @@ -111,7 +111,7 @@ class PURLoggerStandardPluginTest: XCTestCase { expectation(forNotification: Notification.Name.PURBufferedOutputDidStart.rawValue, object: nil, handler: nil) waitForExpectations(timeout: 1.0, handler: nil) - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") expectation(forNotification: Notification.Name.PURBufferedOutputDidSuccessWriteChunk.rawValue, object: nil, handler: nil) @@ -119,7 +119,7 @@ class PURLoggerStandardPluginTest: XCTestCase { logger.post(["aaa": "2"], tag: "buffered.c") logger.post(["aaa": "3"], tag: "buffered.d") - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") logger.shutdown() expectation(forNotification: Notification.Name.PURBufferedOutputDidStart.rawValue, object: nil, handler: nil) @@ -134,7 +134,7 @@ class PURLoggerStandardPluginTest: XCTestCase { logger.post(["aaa": "5"], tag: "buffered.c") // stay in buffer logger.post(["aaa": "6"], tag: "buffered.c") // stay in buffer - let logStorageContent = testLogStorage.description + let logStorageContent = String(describing: testLogStorage) XCTAssertTrue(logStorageContent.contains("[unbuffered|zzz:###]")) XCTAssertTrue(logStorageContent.contains("{buffered.c|aaa:1}")) XCTAssertTrue(logStorageContent.contains("{buffered.c|aaa:2}")) @@ -149,7 +149,7 @@ class PURLoggerStandardPluginTest: XCTestCase { expectation(forNotification: Notification.Name.PURBufferedOutputDidStart.rawValue, object: nil, handler: nil) waitForExpectations(timeout: 1.0, handler: nil) - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") expectation(forNotification: Notification.Name.PURBufferedOutputDidSuccessWriteChunk.rawValue, object: nil, handler: nil) @@ -157,12 +157,12 @@ class PURLoggerStandardPluginTest: XCTestCase { logger.post(["aaa": "2"], tag: "buffered.e") logger.post(["aaa": "3"], tag: "buffered.f") - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") // wait flush interval(2sec) ... waitForExpectations(timeout: 3.0, handler: nil) - let logStorageContent = testLogStorage.description + let logStorageContent = String(describing: testLogStorage) XCTAssertTrue(logStorageContent.contains("{buffered.e|aaa:1}")) XCTAssertTrue(logStorageContent.contains("{buffered.e|aaa:2}")) XCTAssertTrue(logStorageContent.contains("{buffered.f|aaa:3}")) @@ -172,7 +172,7 @@ class PURLoggerStandardPluginTest: XCTestCase { expectation(forNotification: Notification.Name.PURBufferedOutputDidStart.rawValue, object: nil, handler: nil) waitForExpectations(timeout: 1.0, handler: nil) - XCTAssertEqual(testLogStorage.description, "") + XCTAssertEqual(String(describing: testLogStorage), "") expectation(forNotification: Notification.Name.PURBufferedOutputDidTryWriteChunk.rawValue, object: nil, handler: nil) @@ -183,21 +183,21 @@ class PURLoggerStandardPluginTest: XCTestCase { logger.post(["aaa": "5"], tag: "failure") waitForExpectations(timeout: 1.0, handler: nil) - XCTAssertEqual(testLogStorage.description, "[error]") + XCTAssertEqual(String(describing: testLogStorage), "[error]") expectation(forNotification: Notification.Name.PURBufferedOutputDidTryWriteChunk.rawValue, object: nil, handler: nil) // scheduled after 2sec waitForExpectations(timeout: 3.0, handler: nil) - XCTAssertEqual(testLogStorage.description, "[error][error]") + XCTAssertEqual(String(describing: testLogStorage), "[error][error]") expectation(forNotification: Notification.Name.PURBufferedOutputDidTryWriteChunk.rawValue, object: nil, handler: nil) // scheduled after 4sec waitForExpectations(timeout: 5.0, handler: nil) - XCTAssertEqual(testLogStorage.description, "[error][error][error]") + XCTAssertEqual(String(describing: testLogStorage), "[error][error][error]") expectation(forNotification: Notification.Name.PURBufferedOutputDidTryWriteChunk.rawValue, object: nil, handler: nil) // scheduled after 8sec waitForExpectations(timeout: 9.0, handler: nil) - XCTAssertEqual(testLogStorage.description, "[error][error][error][error]") + XCTAssertEqual(String(describing: testLogStorage), "[error][error][error][error]") } }