Closed MarioJ94 closed 1 year ago
I had a similar issues, and here is what i do
I use a custom sourcery, installed directly using Homebrew
brew install sourcery
In my mockfile
, i add at the top:
sourceryCommand: sourcery
sourceryTemplate: null
Now it is using the latest sourcery
I execute 2 sed
commands that updates the generated code to be @unchecked Sendable
Here is the snippet of code I use to generate my mocks
mint run swiftymocky autoimport
mint run swiftymocky generate
find . -type f -name Mock.generated.swift -exec sed -i '' "s/Mock {/Mock, @unchecked Sendable {/g" {} \;
find . -type f -name Mock.generated.swift -exec sed -i '' "s/enum MethodType {/enum MethodType: @unchecked Sendable {/g" {} \;
Hope this helps!
Hi @choulepoka! Thanks for the response! First of all, mock generation is now working thanks to your recommendations!
Let me explain what we had: We have two Mockfile files, the main Mockfile for the app for the .pbxproj ([...]/app) and another for the Package ([...]/app/Packages/PackageName). In our main (app) Mockfile we have
sourceryCommand: null
sourceryTemplate: null
This makes it use Sourcery v1.6.0 when generating the app mocks, which is the dependency we are including in our Podfile for the tests target
def unit_testing_pods
pod 'SwiftyMocky', '4.1.0'
pod 'Sourcery', '1.6.0'
end
On the other hand, in our Package's Mockfile we had...
sourceryCommand: mint run sourcery
sourceryTemplate: null
... which forced the usage of Sourcery 1.9.2 since it always checks for last version. Changing it to sourceryCommand: sourcery
makes it use Sourcery 1.8.2 because it is the one I have globally linked.
🌱 Installed mint packages:
Sourcery
- 1.6.0
- 1.8.2 *
- 1.9.0
- 1.9.1
- 1.9.2
Changing it to 1.6.0 (the one used for the app's Mockfile) makes it fail, which I will try to understand at some point.
Running at: /Users/userName/Workspace/Repositories/repoName/app/Packages/PackageName
Using template from SwiftPM
Processing mock: PackageNameTests ...
Using sourcery command: sourcery
❌ Error: ShellOut encountered an error
Status code: 134
Message: "dyld[76332]: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib
Referenced from: <B097698B-C1F6-34E5-8843-A28955C3ECFA> /Users/userName/.mint/packages/github.com_krzysztofzablocki_Sourcery/build/1.6.0/sourcery
Reason: tried: '/Users/userName/.mint/packages/github.com_krzysztofzablocki_Sourcery/build/1.6.0/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/Users/userName/.mint/packages/github.com_krzysztofzablocki_Sourcery/build/1.6.0/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@rpath/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/Users/userName/.mint/packages/github.com_krzysztofzablocki_Sourcery/build/1.6.0/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/Users/userName/.mint/packages/github.com_krzysztofzablocki_Sourcery/build/1.6.0/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/usr/local/lib/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/usr/lib/lib_InternalSwiftSyntaxParser.dylib' (no such file, not in dyld cache)
/bin/bash: line 1: 76332 Abort trap: 6 sourcery --config "/Users/userName/Workspace/Repositories/repoName/app/Packages/PackageNameTests/.mocky5FCB09FA-7382-47FC-A33B-3552795AD436/.config.yml.tmp""
Output: ""
But now that I take a look at the Mockfile format explained here https://github.com/MakeAWishFoundation/SwiftyMocky/blob/master/guides/Mockfile.md, I guess that (since we have both the Package and the app code in the same repository) we should just have a single Mockfile with the different Mock configurations.
I will take this day and the next to check if everything works properly before marking this as closed to ensure I only needed to define the Mockfile properly without having to perform any other command.
Thanks @choulepoka !!!
Using the autoimport seems to include some imports. With those imports, latest version of Sourcery v1.9.2 seems able to generate the mocks, so there is no need to change the Mockfile from sourceryCommand: mint run sourcery
to sourceryCommand: sourcery
, although we sometimes got some errors, re-running it would make it work.
With that said, as you suggested, we will use the local sourcery version because we think using the local version helps with stability. Thank you very much for your help!
We are experiencing an issue when generating the mocks for one of our Swift Packages.
Our current project is a workspace with several .pbxproj (main and pods) and also some packages added through SPM.
It began when we added the usage of actors. We just deprecated support of iOS 12 and started using async await. When we generate the mocks only with that, the process is completed modifying the code related to the protocols' methods changed to be async.
We also decided to start using actors. It seems to be working fine when an actor object is defined inside the main .pbxproj source files, but when an actor object is defined in the code inside the Package, it throws the following error:
As you can see, the message talks about an undefined SwiftActor.
Also, I would like to point out that we have noticed that the Sourcery version used when generating the Package's code mocks does not match the version that the pod is supposed to be using. We are using the SwiftyMocky pod with version 4.1.0, which is supposed to use Sourcery v1.6.0 if I am not mistaken, but when running the generate command for the package, the Sourcery version displayed in the logs is 1.9.2 (just adding this information in case it is relevant).
We are happy with finding a solution about the SwiftActor issue. Is this some kind of limitation or maybe we have something wrong?