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 Implementation #6

Merged
merged 12 commits into from
Nov 22, 2024
Merged

Swift Testing Implementation #6

merged 12 commits into from
Nov 22, 2024

Conversation

ethan-vanheerden
Copy link
Collaborator

This PR introduces a Swift Testing-based solution for TestableCombinePublishers.

  1. It creates a new SwiftTestingTestableCombinePublishers target which mimics the existingTestableCombinePublishers target, but with no usage of the XCTest library.
    • This new target was created so that clients explicitly need to opt into the Swift Testing version - as XCTest and Swift Testing can have undefined behavior when they are used in the same test suite.
  2. I also created a new TestableCombinePublishersUtility target which houses shared logic between the XCTest and Swift Testing implementations - i.e. AutomaticallyEquatable

The only different between the XCTest and Swift Testing implementation is that the Swift Testing implementation utilizes async/await:

TestableCombinePublishers

SwiftTestingTestableCombinePublishers

func testExpectEquatableValue() {
        ["cool"]
            .publisher
            .expect("cool")
            .waitForExpectations(timeout: 1)
}
@Test func expectEquatableValue() async {
        await ["cool"]
            .publisher
            .expect("cool")
            .waitForExpectations(timeout: 1)
}

@ethan-vanheerden ethan-vanheerden marked this pull request as draft November 15, 2024 20:07
Copy link
Owner

@albertbori albertbori left a comment

Choose a reason for hiding this comment

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

Hey Ethan! Thanks a ton for taking a stab at this. It looks really good. I left a handful of comments for tidying things up. Can't wait to get this merged!

Edit: I'm also curious if there's opportunity here to reshape the expectation API by utilizing Combine Publisher's value parameter, which returns an async sequence of elements from the publisher. The reason I didn't do this originally is because I didn't have a timeout mechanism. Now that we do, assuming that ["cool"].publisher.value supports cooperative cancellation, we may be able to reshape the expectation code.

Regardless, I think we can explore that later as part of a new major version. You're on the right track here with this PR.

@ethan-vanheerden ethan-vanheerden marked this pull request as ready for review November 19, 2024 21:05
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Owner

@albertbori albertbori left a comment

Choose a reason for hiding this comment

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

Looks great! Fantastic work!

@ethan-vanheerden ethan-vanheerden merged commit fad93ca into main Nov 22, 2024
1 check passed
@ethan-vanheerden ethan-vanheerden deleted the swift-testing branch November 25, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants