File tree Expand file tree Collapse file tree 2 files changed +386
-1
lines changed
Expand file tree Collapse file tree 2 files changed +386
-1
lines changed Original file line number Diff line number Diff line change @@ -67,3 +67,28 @@ internal func osLog(
6767 }
6868 bufferMemory. deallocate ( )
6969}
70+
71+ /// A test helper that constructs a byte buffer and a format string from an
72+ /// instance of `OSLogMessage` using the same logic as the function `osLog`,
73+ /// and applies a given `assertion` to the constructed format string and
74+ /// byte buffer. This function should be used only in tests.
75+ /// - Parameters:
76+ /// - message: An instance of `OSLogMessage` created from string interpolation
77+ /// - assertion: A closure that takes a format string and a pointer to a
78+ /// byte buffer and asserts a condition.
79+ public // @testable
80+ func _checkFormatStringAndBuffer(
81+ _ message: OSLogMessage ,
82+ with assertion: ( String , UnsafeBufferPointer < UInt8 > ) -> Void
83+ ) {
84+ let bufferSize = message. bufferSize
85+ let bufferMemory = UnsafeMutablePointer< UInt8> . allocate( capacity: bufferSize)
86+ var builder = OSLogByteBufferBuilder ( bufferMemory)
87+ message. serializeArguments ( into: & builder)
88+
89+ assertion (
90+ message. formatString,
91+ UnsafeBufferPointer ( start: UnsafePointer ( bufferMemory) , count: bufferSize) )
92+
93+ bufferMemory. deallocate ( )
94+ }
You can’t perform that action at this time.
0 commit comments