This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlakyTests: XCTestCase { | |
struct FlakySuite { | |
let testCase: XCTestCase | |
let selectors: [Selector] | |
} | |
let suites: [FlakySuite] = [ | |
FlakySuite( | |
testCase: CrashContextProviderTests(), | |
selectors: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSObject { | |
var __methods: [Selector] { | |
var methodCount: UInt32 = 0 | |
guard | |
let methodList = class_copyMethodList(type(of: self), &methodCount), | |
methodCount != 0 | |
else { return [] } | |
return (0 ..< Int(methodCount)) | |
.compactMap({ method_getName(methodList[$0]) }) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Framer | |
func testGenerateColors() { | |
struct CC { | |
let name: String | |
let color: UIColor | |
} | |
let colors: [CC] = [ | |
CC(name: "systemRed", color: UIColor.systemRed), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension XCTestCase { | |
func benchmark(_ label: String, iterations: Int = 100, block: () throws -> Void) rethrows { | |
var measures: [TimeInterval] = [] | |
let warmUp = iterations / 10 | |
for i in (0..<iterations) { | |
let start = Date() | |
try block() | |
if i >= warmUp { // only measure after it is warmed-up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"\/Users\/maciek.grzybowski\/Products\/dd-sdk-ios\/Sources\/Datadog\/Core\/Attributes\/UserInfo.swift" : { | |
"key.diagnostic_stage" : "source.diagnostic.stage.swift.parse", | |
"key.length" : 999, | |
"key.offset" : 0, | |
"key.substructure" : [ | |
{ | |
"key.accessibility" : "source.lang.swift.accessibility.internal", | |
"key.annotated_decl" : "<Declaration>internal class UserInfoProvider<\/Declaration>", | |
"key.attributes" : [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PlaygroundSupport | |
let url = URL(string: "https://picsum.photos/200/300")! | |
private extension URLSession { | |
/// Method under test | |
func urlRequest(with url: URL) -> URLRequest { | |
return URLRequest( | |
url: url, | |
cachePolicy: configuration.requestCachePolicy, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - UIViewController.viewDidLoad() swizzling | |
class ViewDidLoadSwizzler: MethodSwizzler< | |
@convention(c) (UIViewController, Selector) -> Void, // <- Swizzle from | |
@convention(block) (UIViewController) -> Void // <- Swizzle to | |
> { | |
init() throws { | |
try super.init(selector: #selector(UIViewController.viewDidLoad), inClass: UIViewController.self) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class Locker {} | |
private let locker = Locker() | |
internal class Method { | |
static func `for`(selector: Selector, inClass `class`: AnyClass) -> Method? { | |
objc_sync_enter(locker) | |
if let existingSwizzling = existingSwizzlings[hash(class, selector]) { | |
return existingSwizzlings | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/** | |
Container for storing many delegates and calling an operation on all at once. | |
Uses weak references to store delegates. | |
*/ | |
public final class MulticastDelegate<T> { | |
private var delegates: [WeakDelegate] = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func test_givenTask_whenExecuted_itUpdatesStatusInSpecificOrder() { | |
let task = Task() | |
let mockDelegate = MockTaskStatusDelegate() | |
task.statusDelegate = mockDelegate | |
let downloadingExpectation = self.expectation(description: "status changes to .downloading") | |
let processingExpectation = self.expectation(description: "status changes to .processing") | |
let finishedExpectation = self.expectation(description: "status changes to .finished") | |
mockDelegate.didCall_taskDidChangeStatus = { (_, status) in |
NewerOlder