Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Testing support #96

Merged
merged 11 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "fixes" an unrelated issue that cropped up in beta 3. Seems that self.now is a detected data race. We could consider a better fix, but this is at least functionally the same as on main.

}
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
Loading