2022-10-31 06:17:48 -07:00
|
|
|
//
|
|
|
|
// XCAsyncTestCase.swift
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// credits: https://betterprogramming.pub/async-setup-and-teardown-in-xctestcase-dc7a2cdb9fb
|
|
|
|
//
|
|
|
|
///
|
|
|
|
/// A subclass of ``XCTestCase`` that supports async setup and teardown.
|
|
|
|
///
|
|
|
|
import Foundation
|
|
|
|
import XCTest
|
|
|
|
|
2022-10-31 16:17:05 -07:00
|
|
|
extension XCTestCase {
|
2022-11-23 10:05:49 -08:00
|
|
|
static func wait(asyncBlock: @escaping (() async throws -> Void)) {
|
2022-10-31 06:17:48 -07:00
|
|
|
let semaphore = DispatchSemaphore(value: 0)
|
|
|
|
Task.init {
|
|
|
|
try await asyncBlock()
|
|
|
|
semaphore.signal()
|
|
|
|
}
|
|
|
|
semaphore.wait()
|
|
|
|
}
|
2022-11-23 10:05:49 -08:00
|
|
|
|
|
|
|
func wait(asyncBlock: @escaping (() async throws -> Void)) {
|
|
|
|
XCTestCase.wait(asyncBlock: asyncBlock)
|
|
|
|
}
|
2022-10-31 06:17:48 -07:00
|
|
|
}
|