Skip to content
New issue

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

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

Already on GitHub? # to your account

AutoMockable does not generate valid swift code for static protocol extensions methods #1335

Closed
MontakOleg opened this issue May 22, 2024 · 0 comments · Fixed by #1336
Closed
Milestone

Comments

@MontakOleg
Copy link
Contributor

Given

// sourcery: AutoMockable
protocol SomeProtocol {
    static func thisIsOk()
}

extension SomeProtocol {
    static func thisIsDoesNotCompile() {}
}

Generates:

class SomeProtocolMock: SomeProtocol {



    static func reset()
    {
         //MARK: - thisIsOk
        thisIsOkVoidCallsCount = 0
        thisIsOkVoidClosure = nil


         //MARK: - thisIsDoesNotCompile
        thisIsDoesNotCompileVoidCallsCount = 0 //  ❌ Cannot find 'thisIsDoesNotCompileVoidCallsCount' in scope
        thisIsDoesNotCompileVoidClosure = nil //  ❌ Cannot find 'thisIsDoesNotCompileVoidClosure' in scope


    }

    //MARK: - thisIsOk

    static var thisIsOkVoidCallsCount = 0
    static var thisIsOkVoidCalled: Bool {
        return thisIsOkVoidCallsCount > 0
    }
    static var thisIsOkVoidClosure: (() -> Void)?

    static func thisIsOk() {
        thisIsOkVoidCallsCount += 1
        thisIsOkVoidClosure?()
    }


}
MontakOleg added a commit to MontakOleg/Sourcery that referenced this issue May 22, 2024
- don't generate invalid code (see
krzysztofzablocki#1335)
- use type's access level for generated reset() function
@art-divin art-divin modified the milestone: 2.2.5 Jun 5, 2024
art-divin pushed a commit that referenced this issue Jun 22, 2024
- don't generate invalid code (see
#1335)
- use type's access level for generated reset() function
art-divin added a commit that referenced this issue Jun 22, 2024
commit 33f948a
Author: MontakOleg <oleg.montak@gmail.com>
Date:   Sat Jun 22 15:38:14 2024 +0300

    AutoMockable: fix generating static reset func (#1336)

    - don't generate invalid code (see
    #1335)
    - use type's access level for generated reset() function

commit 2f8fc64
Author: art-divin <art-divin@users.noreply.github.com>
Date:   Wed Jun 19 18:58:34 2024 +0000

    Update Docs

commit 7153768
Author: Ruslan A <r.alikhamov@gmail.com>
Date:   Wed Jun 19 22:50:18 2024 +0400

    Fix associatedtype generics (#1345)

    * Preliminary associatedtype support

    * Implemented associatedtype support with generic requirements

    * Fixed failing test

    * Squashed commit of the following:

    commit 9d01e6f
    Author: Ruslan A <r.alikhamov@gmail.com>
    Date:   Fri Jun 14 20:06:41 2024 +0400

        Improved concurrency support in SwiftTemplate caching (#1344)

    * Removed test code

    * Removed comment

    * Updated Linux classes

    * update internal boilerplate code.

    * Updated generated code

    * Removed warnings

    * Updated expected file

    * Updated expected file

    * Adjusted protocol type for Linux

    * Removed protocol composition due to Swift compiler crash under Linux
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants