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

[Infra] Add GHA workflow #227

Merged
merged 5 commits into from
Jan 29, 2024
Merged

[Infra] Add GHA workflow #227

merged 5 commits into from
Jan 29, 2024

Conversation

ncooke3
Copy link
Member

@ncooke3 ncooke3 commented Jan 27, 2024

  • Add a GHA workflow file to build and test for SPM and CocoaPods.
  • The test targets do not build at HEAD for SPM so I needed to make changes to get them building.
  • The test targets do not pass at HEAD for SPM so I needed to make changes to get them passing.

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal of the affected tests was to assert conditions where promises should resolve to nil. But, by using then, they were all failing because the then {} block was trying to assert NSNull == nil which is false.

When .then {} is used on a Swift promises, nil will get turned into bridged into NSNull:

  1. When then is called with a nil promise, line 35 will convert it to NSNull.
    func then<Result>(
    on queue: DispatchQueue = .promises,
    _ work: @escaping Then<Promise<Result>>
    ) -> Promise<Result> {
    let promise = Promise<Result>(objCPromise.__onQueue(queue, then: { objCValue in
    guard let value = Promise<Value>.asValue(objCValue) else {
  2. When Promise<Value>.asValue(nil) is called, nil is bridged to NSNull.
    /// Converts `AnyObject` to generic `Value`, or `nil` if the conversion is not possible.
    static func asValue(_ value: AnyObject?) -> Value? {
    // Swift nil becomes NSNull during bridging.
    return (value as? Value) ?? NSNull() as AnyObject as? Value
    }

I added a unit test in Promise+ThenTests.swift to assert the above behavior.

@ykjchen
Copy link
Collaborator

ykjchen commented Jan 29, 2024

Thanks for the contribution and commentary.

@ykjchen ykjchen merged commit 5031732 into google:master Jan 29, 2024
10 checks passed
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