Sourcery icon indicating copy to clipboard operation
Sourcery copied to clipboard

Handle methods with variadic parameters & fixed generated code for existential parameters

Open pocketal opened this issue 1 year ago • 9 comments

1 - handle methods with variadic parameters 2 - fixed generated code for existential parameters

pocketal avatar Jan 25 '24 15:01 pocketal

This PR fixes issues https://github.com/krzysztofzablocki/Sourcery/issues/1267 https://github.com/krzysztofzablocki/Sourcery/issues/1265

rokridi avatar Jan 25 '24 15:01 rokridi

@rokridi Linux tests failed because in the modified stencil there is a call to isVariadic on type String and not a type from AST.

See the error text: SourceryRuntime/TypeName_Linux.swift:31: Fatal error: unable to lookup: isVariadic in String?

art-divin avatar Jan 25 '24 15:01 art-divin

@rokridi Linux tests failed because in the modified stencil there is a call to isVariadic on type String and not a type from AST.

See the error text: SourceryRuntime/TypeName_Linux.swift:31: Fatal error: unable to lookup: isVariadic in String?

How can I run tests locally ?

pocketal avatar Jan 26 '24 09:01 pocketal

How can I run tests locally ?

I suggest to read Stencil carefully, and check all occurrences of isVariadic , at least one of them is used against String type. It is faster and more reliable to do than if to setup a VM and dive into debugging in VSCode.

If you won't be able to deduct what's wrong, feel free to tell me, I might have a chance to check it myself later this week.

art-divin avatar Jan 26 '24 09:01 art-divin

Hey @pocketal ,

the last CI build failed with the following issue:

SourceryRuntime/TypeName_Linux.swift:31: Fatal error: unable to lookup: isImplicitlyUnwrappedOptional in String?

Please check in which case isImplicitlyUnwrappedOptional is called on String type and not AST type.

art-divin avatar Jan 26 '24 18:01 art-divin

resolves #1267 fixes #1265

@rokridi to make GitHub understand what needs to be automatically closed, keyword "resolves" or "fixes" needs to be put in front of each issue number like here 👆🏻 in the original post of the Merge Request.

Reference: https://github.blog/2013-05-14-closing-issues-via-pull-requests/

art-divin avatar Jan 26 '24 18:01 art-divin

👋🏻 @rokridi I have run tests for macOS variant, and here are my findings:

  1. Extected file (AutoMockable.expected) is outdated in your branch. Please find the instructions how to update it here.
  2. Generated code for one of the mockable protocols is not valid swift:
class StaticMethodProtocolMock: StaticMethodProtocol {



    static func reset()
    {
         //MARK: - staticFunction
        staticFunctionStringStringCallsCount = 0
        staticFunctionStringStringReceived = nil
        staticFunctionStringStringReceivedInvocations = []
        staticFunctionStringStringClosure = nil


    }

    //MARK: - staticFunction

    static var staticFunctionStringStringCallsCount = 0
    static var staticFunctionStringStringCalled: Bool {
        return staticFunctionStringStringCallsCount > 0
    }
    static var staticFunctionStringStringReceived: (String)?
    static var staticFunctionStringStringReceivedInvocations: [(String)] = []
    static var staticFunctionStringStringReturnValue: String!
    static var staticFunctionStringStringClosure: ((String) -> String)?

    static func staticFunction(_ : String) -> String {
        staticFunctionStringStringCallsCount += 1
        staticFunctionStringStringReceived =
        staticFunctionStringStringReceivedInvocations.append()
        if let staticFunctionStringStringClosure = staticFunctionStringStringClosure {
            return staticFunctionStringStringClosure()
        } else {
            return staticFunctionStringStringReturnValue
        }
    }


}

Everything else seems to be OK within the macOS tests context! Great work! 🤝

art-divin avatar Jan 26 '24 21:01 art-divin

Hello @art-divin 👋

  1. Extected file (AutoMockable.expected) is outdated in your branch. Please find the instructions how to update it here.

When we follow the instructions to update AutoMockable.expected we only get this from the generated file:

// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT

internal extension AutoCasesEnum {
 static let count: Int = 4
 static let allCases: [AutoCasesEnum] = [
  .north,
  .south,
  .east,
  .west
 ]
}
public extension AutoCasesHasAssociatedValuesEnum {
 static let count: Int = 2
}
internal extension AutoCasesOneValueEnum {
 static let count: Int = 1
 static let allCases: [AutoCasesOneValueEnum] = [
  .one
 ]
}
  1. Generated code for one of the mockable protocols is not valid swift:

This generated mock does not compile even with latest Sourcery release.

rokridi avatar Jan 29 '24 14:01 rokridi

When we follow the instructions to update AutoMockable.expected we only get this from the generated file:

@rokridi yes, my mistake. You need to comment out all except AutoMockable assertion before following that instruction: image

art-divin avatar Jan 29 '24 15:01 art-divin

👋🏻 Hey @pocketal

Do you need any help with this PR? I could take over if you want, I am almost done with 2.1.8 release preparation at the moment, and I would love to include this fix into it.

Thanks for your contribution 👍🏻


If I would take over, I would cherry-pick your commits into a new PR and continue from there, persisting attribution.

art-divin avatar Mar 10 '24 18:03 art-divin

Hey @art-divin Sorry I was very busy these days and didn't have time to look into it. You can take over if you want. Thanks for you help 🙏

AliouSARR avatar Mar 13 '24 09:03 AliouSARR

Closing in favor of #1304

art-divin avatar Mar 19 '24 14:03 art-divin