This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/iOS/Example/Pods/Nimble-Snapshots/CurrentTestCaseTracker.swift
2019-07-25 19:30:14 +08:00

39 lines
1.3 KiB
Swift

import XCTest
/// Helper class providing access to the currently executing XCTestCase instance, if any
@objc public final class CurrentTestCaseTracker: NSObject, XCTestObservation {
@objc public static let shared = CurrentTestCaseTracker()
private(set) var currentTestCase: XCTestCase?
@objc public func testCaseWillStart(_ testCase: XCTestCase) {
currentTestCase = testCase
}
@objc public func testCaseDidFinish(_ testCase: XCTestCase) {
currentTestCase = nil
}
}
extension XCTestCase {
var sanitizedName: String? {
let fullName = self.name
let characterSet = CharacterSet(charactersIn: "[]+-")
#if swift(>=4)
let name = fullName.components(separatedBy: characterSet).joined()
#else
let name = (fullName ?? "").components(separatedBy: characterSet).joined()
#endif
if let quickClass = NSClassFromString("QuickSpec"), self.isKind(of: quickClass) {
let className = String(describing: type(of: self))
if let range = name.range(of: className), range.lowerBound == name.startIndex {
return name.replacingCharacters(in: range, with: "")
.trimmingCharacters(in: .whitespacesAndNewlines)
}
}
return name
}
}