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

Fix to avoid using global actors as default values #269

Merged
merged 4 commits into from
Oct 31, 2024

Conversation

sidepelican
Copy link
Collaborator

Fixes #171 .

This PR includes two changes:

  1. Fix for cases where any annotated existential types cannot find a default mock value.

Base

/// @mockable
protocol SomeProtocol { }

/// @mockable
protocol UseSomeProtocol {
    func foo() -> any SomeProtocol
}

Before

class UseSomeProtocolMock: UseSomeProtocol {
    ...
    func foo()  -> any SomeProtocol {
        fooCallCount += 1
        if let fooHandler = fooHandler {
            return fooHandler()
        }
        fatalError("fooHandler returns can't have a default value thus its handler must be set")
    }
}

After

class UseSomeProtocolMock: UseSomeProtocol {
    ...
    func foo()  -> any SomeProtocol {
        fooCallCount += 1
        if let fooHandler = fooHandler {
            return fooHandler()
        }
        return SomeProtocolMock() 
    }
}
  1. The mock is may have a global actor doesn't provide a default value

Fix #171. Calling a function with a globalActor from a mock is very complicated, so it is easier to give up the default value.

@sidepelican sidepelican requested review from uhooi and fummicc1 October 28, 2024 03:28
Copy link
Collaborator

@fummicc1 fummicc1 left a comment

Choose a reason for hiding this comment

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

Thank you so much! Implementation is nice. Just to confirm, I added some comments.

# Conflicts:
#	Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift
Copy link
Collaborator

@fummicc1 fummicc1 left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@sidepelican sidepelican merged commit 56d8697 into uber:master Oct 31, 2024
3 checks passed
@sidepelican sidepelican deleted the globalactor_defaultval branch October 31, 2024 02:24
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.

Actor annotated protocols don't work
2 participants