@@ -46,33 +46,26 @@ public class TestHarness<T: Reader> {
4646 ///
4747 public let writer : T . WriterType
4848
49- ///
50- /// Instance of a Reader to use for validating the results of the test.
51- ///
52- public var reader : T {
53- return _reader. reader
54- }
55-
5649 ///
5750 /// Boxed version of the reader so it can be stored.
5851 ///
59- private let _reader : _AnyReaderBox < T >
52+ private let reader : _AnyReaderBox < T >
6053
6154 ///
6255 /// Initialize a test harness with the specified writer that is under test and a reader to search for the entry so it can be validated.
6356 ///
6457 public init ( writer: T . WriterType , reader: T ) {
6558 self . writer = writer
66- self . _reader = _AnyReaderBox ( reader)
59+ self . reader = _AnyReaderBox ( reader)
6760 }
6861
6962 ///
7063 /// Executes test block (that must contain a call one of TraceLogs log functions) and validates the results.
7164 ///
72- public func testLog( for level: LogLevel , tag tagOrNil: String ? = nil , message messageOrNil: String ? = nil , _ file: String = #file, _ function: String = #function, _ line: Int = #line,
65+ public func testLog( for level: LogLevel , tag tagOrNil: String ? = nil , message messageOrNil: String ? = nil , file: String = #file, function: String = #function, line: Int = #line,
7366 testBlock: ( String , String , String , String , Int ) -> Void , validationBlock: ( _ writer: T . WriterType , _ result: LogEntry ? , _ expected: LogEntry ) -> Void ) {
7467
75- self . _testLog ( for: level, tag: tagOrNil, message: messageOrNil, file, function, line, testBlock: { ( timestamp, level, tag, message, runtimeContext, staticContext) in
68+ self . _testLog ( for: level, tag: tagOrNil, message: messageOrNil, file: file , function: function , line : line, testBlock: { ( timestamp, level, tag, message, runtimeContext, staticContext) in
7669
7770 testBlock ( tag, message, file, function, line)
7871
@@ -82,10 +75,10 @@ public class TestHarness<T: Reader> {
8275 ///
8376 /// Calls the writer directly with the given LogLevel and validates the results.
8477 ///
85- public func testLog( for level: LogLevel , tag tagOrNil: String ? = nil , message messageOrNil: String ? = nil , _ file: String = #file, _ function: String = #function, _ line: Int = #line,
78+ public func testLog( for level: LogLevel , tag tagOrNil: String ? = nil , message messageOrNil: String ? = nil , file: String = #file, function: String = #function, line: Int = #line,
8679 validationBlock: ( _ writer: T . WriterType , _ result: LogEntry ? , _ expected: LogEntry ) -> Void ) {
8780
88- self . _testLog ( for: level, tag: tagOrNil, message: messageOrNil, file, function, line, testBlock: { ( timestamp, level, tag, message, runtimeContext, staticContext) in
81+ self . _testLog ( for: level, tag: tagOrNil, message: messageOrNil, file: file , function: function , line : line, testBlock: { ( timestamp, level, tag, message, runtimeContext, staticContext) in
8982
9083 /// Execute the test
9184 self . writer. log ( timestamp, level: level, tag: tag, message: message, runtimeContext: runtimeContext, staticContext: staticContext)
@@ -96,7 +89,7 @@ public class TestHarness<T: Reader> {
9689 ///
9790 /// Test a TraceLog log message to a writer.
9891 ///
99- private func _testLog( for level: LogLevel , tag tagOrNil: String ? = nil , message messageOrNil: String ? = nil , _ file: String = #file, _ function: String = #function, _ line: Int = #line,
92+ private func _testLog( for level: LogLevel , tag tagOrNil: String ? = nil , message messageOrNil: String ? = nil , file: String = #file, function: String = #function, line: Int = #line,
10093 testBlock: ( Double , LogLevel , String , String , RuntimeContext , StaticContext ) -> Void , validationBlock: ( _ writer: T . WriterType , _ result: LogEntry ? , _ expected: LogEntry ) -> Void ) {
10194
10295 /// This is the time in microseconds since the epoch UTC to match the journals time stamps.
@@ -111,7 +104,7 @@ public class TestHarness<T: Reader> {
111104 /// Execute the test
112105 testBlock ( timestamp, level, tag, message, runtimeContext, staticContext)
113106
114- let result = self . _reader . logEntry ( for: writer, timestamp: timestamp, level: level, tag: tag, message: message, runtimeContext: runtimeContext, staticContext: staticContext)
107+ let result = self . reader . logEntry ( for: self . writer, timestamp: timestamp, level: level, tag: tag, message: message, runtimeContext: runtimeContext, staticContext: staticContext)
115108
116109 let expected = LogEntry ( timestamp: timestamp, level: level, message: message, tag: tag, file: staticContext. file, function: staticContext. function, line: staticContext. line, processName: runtimeContext. processName, processIdentifier: runtimeContext. processIdentifier, threadIdentifier: Int ( runtimeContext. threadIdentifier) )
117110
@@ -177,10 +170,6 @@ private class _AnyReaderBox<ConcreteReader: Reader>: _AnyReaderBase<ConcreteRead
177170/// Private boxing class base for use in storing our Reader which has an associated type.
178171///
179172private class _AnyReaderBase < T: Writer > : Reader {
180- init ( ) {
181- guard type ( of: self ) != _AnyReaderBase. self
182- else { fatalError ( " Cannot initialize, must be subclass " ) }
183- }
184173
185174 func logEntry( for writer: T , timestamp: Double , level: LogLevel , tag: String , message: String , runtimeContext: RuntimeContext , staticContext: StaticContext ) -> LogEntry ? {
186175 fatalError ( " Must override " )
@@ -218,6 +207,14 @@ private struct TestRuntimeContext: RuntimeContext {
218207 let process = ProcessInfo . processInfo
219208 self . processName = process. processName
220209 self . processIdentifier = Int ( process. processIdentifier)
221- self . threadIdentifier = threadIdentifier
210+
211+ #if os(iOS) || os(macOS) || os(watchOS) || os(tvOS)
212+ var threadID : UInt64 = 0
213+
214+ pthread_threadid_np ( pthread_self ( ) , & threadID)
215+ self . threadIdentifier = threadID
216+ #else // FIXME: Linux does not support the pthread_threadid_np function, gettid in s syscall must be used.
217+ self . threadIdentifier = 0
218+ #endif
222219 }
223220}
0 commit comments