From 1cc00ac55d25fee99a2465fd764244d04ae9d638 Mon Sep 17 00:00:00 2001 From: Vitalii Budnik Date: Thu, 1 Aug 2024 15:03:26 +0300 Subject: [PATCH] chore: add unchecked Sendable conformance to AutoMockable --- Templates/Templates/AutoMockable.stencil | 6 ++++- Templates/Tests/Context/AutoMockable.swift | 12 +++++++++ .../Generated/AutoMockable.generated.swift | 26 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Templates/Templates/AutoMockable.stencil b/Templates/Templates/AutoMockable.stencil index e0758f7b3..e4d0dbaf0 100755 --- a/Templates/Templates/AutoMockable.stencil +++ b/Templates/Templates/AutoMockable.stencil @@ -369,8 +369,12 @@ import {{ import }} {% endif %} {%- endmacro %} +{% macro extractRequiredProtocolConformance type -%} + {% if type.based.Sendable %}, @unchecked Sendable{% endif %} +{%- endmacro %} + {% for type in types.protocols where type.based.AutoMockable or type|annotated:"AutoMockable" %}{% if type.name != "AutoMockable" %} -{% call accessLevel type.accessLevel %}class {{ type.name }}Mock{% set generics %}{% call extractProtocolCompositionFromAssociatedTypes type %}{% endset %}{{ generics | replace:",>",">"}}: {{ type.name }} {%- set requirements -%}{% call extractProtocolRequirementsFromType type %}{%- endset -%} {{ requirements|replace:",{","{"|replace:"{"," {" }} +{% call accessLevel type.accessLevel %}class {{ type.name }}Mock{% set generics %}{% call extractProtocolCompositionFromAssociatedTypes type %}{% endset %}{{ generics | replace:",>",">"}}: {{ type.name }}{% call extractRequiredProtocolConformance type %} {%- set requirements -%}{% call extractProtocolRequirementsFromType type %}{%- endset -%} {{ requirements|replace:",{","{"|replace:"{"," {" }} {% for associatedType in type.associatedTypes|sortedValuesByKeys %} {% if associatedType.type.kind == nil or not associatedType.type.kind|contains:"protocol" %} typealias {{ associatedType.name }} = {% if associatedType.type != nil %}{{ associatedType.type.name }}{% elif associatedType.typeName != nil %}{{ associatedType.typeName.name }}{% else %}Any{% endif %} diff --git a/Templates/Tests/Context/AutoMockable.swift b/Templates/Tests/Context/AutoMockable.swift index 990d7730d..7feea6ecb 100644 --- a/Templates/Tests/Context/AutoMockable.swift +++ b/Templates/Tests/Context/AutoMockable.swift @@ -292,3 +292,15 @@ protocol TestProtocol { func getValue6() -> Value6 } + +// sourcery: AutoMockable +protocol SendableProtocol: Sendable { + var value: Any { get } +} + +protocol NotMockedSendableProtocol: Sendable {} + +// sourcery: AutoMockable +protocol SendableSendableProtocol: NotMockedSendableProtocol { + var value: Any { get } +} diff --git a/Templates/Tests/Generated/AutoMockable.generated.swift b/Templates/Tests/Generated/AutoMockable.generated.swift index 6218727a4..7351a71fd 100644 --- a/Templates/Tests/Generated/AutoMockable.generated.swift +++ b/Templates/Tests/Generated/AutoMockable.generated.swift @@ -1863,4 +1863,30 @@ class VariablesProtocolMock: VariablesProtocol { +} + +class SendableProtocolMock: SendableProtocol, @unchecked Sendable { + + + var value: Any { + get { return underlyingAge } + set(value) { underlyingAge = value } + } + var underlyingValue: (Any)! + + + +} + +class SendableSendableProtocolMock: SendableSendableProtocol, @unchecked Sendable { + + + var value: Any { + get { return underlyingAge } + set(value) { underlyingAge = value } + } + var underlyingValue: (Any)! + + + }