File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,7 @@ extension TestMetrics.FullKey: Hashable {
143
143
144
144
extension TestMetrics {
145
145
// ==== ------------------------------------------------------------------------------------------------------------
146
+
146
147
// MARK: Counter
147
148
148
149
/// Assert that the passed in `metric` is a ``TestCounter`` and return it for further executing assertions.
@@ -174,12 +175,14 @@ extension TestMetrics {
174
175
}
175
176
176
177
// ==== ------------------------------------------------------------------------------------------------------------
178
+
177
179
// MARK: Gauge
178
180
179
181
/// Assert that the passed in `metric` is a ``TestRecorder`` and return it for further executing assertions.
180
182
public func expectGauge( _ metric: Gauge ) throws -> TestRecorder {
181
183
return try self . expectRecorder ( metric)
182
184
}
185
+
183
186
/// Locate a ``TestRecorder`` created by the ``TestMetrics`` factory identified by the passed in ``label`` and ``dimensions``, and return it for further executing assertions.
184
187
///
185
188
/// - Parameters:
@@ -192,6 +195,7 @@ extension TestMetrics {
192
195
}
193
196
194
197
// ==== ------------------------------------------------------------------------------------------------------------
198
+
195
199
// MARK: Recorder
196
200
197
201
/// Assert that the passed in `metric` is a ``TestRecorder`` and return it for further executing assertions.
@@ -223,6 +227,7 @@ extension TestMetrics {
223
227
}
224
228
225
229
// ==== ------------------------------------------------------------------------------------------------------------
230
+
226
231
// MARK: Timer
227
232
228
233
/// Assert that the passed in `metric` is a ``TestTimer`` and return it for further executing assertions.
Original file line number Diff line number Diff line change @@ -188,7 +188,9 @@ public enum SystemMetrics {
188
188
189
189
#if os(Linux)
190
190
internal static func linuxSystemMetrics( ) -> SystemMetrics . Data ? {
191
- class CFile {
191
+ /// Minimal file reading implementation so we don't have to depend on Foundation.
192
+ /// Designed only for the narrow use case of this library, reading `/proc/self/stat`.
193
+ final class CFile {
192
194
let path : String
193
195
194
196
private var file : UnsafeMutablePointer < FILE > ?
@@ -221,7 +223,7 @@ public enum SystemMetrics {
221
223
return nil
222
224
}
223
225
#if compiler(>=5.1)
224
- let buff : [ CChar ] = Array ( unsafeUninitializedCapacity: 1024 ) { ptr, size in
226
+ var buff : [ CChar ] = Array ( unsafeUninitializedCapacity: 1024 ) { ptr, size in
225
227
guard fgets ( ptr. baseAddress, Int32 ( ptr. count) , f) != nil else {
226
228
if feof ( f) != 0 {
227
229
size = 0
@@ -230,9 +232,10 @@ public enum SystemMetrics {
230
232
preconditionFailure ( " Error reading line " )
231
233
}
232
234
}
233
- size = strlen ( ptr. baseAddress!)
235
+ size = strlen ( ptr. baseAddress!) + 1 // the string + NULL to terminate it
234
236
}
235
237
if buff. isEmpty { return nil }
238
+ buff [ buff. index ( before: buff. endIndex) ] = 0 // ensure the string is null-terminated
236
239
return String ( cString: buff)
237
240
#else
238
241
var buff = [ CChar] ( repeating: 0 , count: 1024 )
You can’t perform that action at this time.
0 commit comments