Skip to content

Commit

Permalink
Swift Testing support
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Jul 10, 2024
1 parent 416d722 commit 6a04853
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", branch: "swift-testing"),
],
targets: [
.target(
name: "CombineSchedulers",
dependencies: [
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
]
),
.testTarget(
Expand Down
6 changes: 4 additions & 2 deletions Sources/CombineSchedulers/Concurrency.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(Combine)
@preconcurrency import Combine
import ConcurrencyExtras

extension Scheduler {
/// Suspends the current task for at least the given duration.
Expand Down Expand Up @@ -76,14 +77,15 @@
tolerance: SchedulerTimeType.Stride = .zero,
options: SchedulerOptions? = nil
) -> AsyncStream<SchedulerTimeType> {
AsyncStream { continuation in
@UncheckedSendable var scheduler = self
return AsyncStream { [$scheduler] continuation in
let cancellable = self.schedule(
after: self.now.advanced(by: interval),
interval: interval,
tolerance: tolerance,
options: options
) {
continuation.yield(self.now)
continuation.yield($scheduler.wrappedValue.now)
}
continuation.onTermination =
{ _ in
Expand Down
12 changes: 6 additions & 6 deletions Sources/CombineSchedulers/UnimplementedScheduler.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if canImport(Combine)
import Combine
import Foundation
import XCTestDynamicOverlay
import IssueReporting

/// A scheduler that causes the current XCTest test case to fail if it is used.
///
Expand Down Expand Up @@ -78,7 +78,7 @@
SchedulerTimeType.Stride: SchedulerTimeIntervalConvertible
{
public var minimumTolerance: SchedulerTimeType.Stride {
XCTFail(
reportIssue(
"""
\(self.prefix.isEmpty ? "" : "\(self.prefix) - ")\
An unimplemented scheduler was asked its minimum tolerance.
Expand All @@ -88,7 +88,7 @@
}

public var now: SchedulerTimeType {
XCTFail(
reportIssue(
"""
\(self.prefix.isEmpty ? "" : "\(self.prefix) - ")\
An unimplemented scheduler was asked the current time.
Expand All @@ -112,7 +112,7 @@
}

public func schedule(options _: SchedulerOptions?, _ action: () -> Void) {
XCTFail(
reportIssue(
"""
\(self.prefix.isEmpty ? "" : "\(self.prefix) - ")\
An unimplemented scheduler scheduled an action to run immediately.
Expand All @@ -127,7 +127,7 @@
options _: SchedulerOptions?,
_ action: () -> Void
) {
XCTFail(
reportIssue(
"""
\(self.prefix.isEmpty ? "" : "\(self.prefix) - ")\
An unimplemented scheduler scheduled an action to run later.
Expand All @@ -143,7 +143,7 @@
options _: SchedulerOptions?,
_ action: () -> Void
) -> Cancellable {
XCTFail(
reportIssue(
"""
\(self.prefix.isEmpty ? "" : "\(self.prefix) - ")\
An unimplemented scheduler scheduled an action to run on a timer.
Expand Down

0 comments on commit 6a04853

Please sign in to comment.