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

Generating mocks for protocols exposed from a Swift Package #1152

Open
Velin92 opened this issue Mar 16, 2023 · 6 comments
Open

Generating mocks for protocols exposed from a Swift Package #1152

Velin92 opened this issue Mar 16, 2023 · 6 comments

Comments

@Velin92
Copy link

Velin92 commented Mar 16, 2023

Hello!

I would like to generate mocks for a protocols that are not in my codebase, but are exposed from the codebase of a Swift Package.

How may I be able to generate those mocks for such protocols in my codebase?
Since I am not able to extend a protocol with AutoMockable or // sourcery: AutoMockable, and since also they do not belong directly in my codebase and not get scanned.

@Velin92
Copy link
Author

Velin92 commented May 12, 2023

Hello no news on this so far?

@krzysztofzablocki
Copy link
Owner

You need to get at least definition scanned, you can add conformance in your own project code

@Velin92
Copy link
Author

Velin92 commented May 13, 2023

You need to get at least definition scanned, you can add conformance in your own project code

How may I achieve this?
Since the it's an SPM the definition is not really in project, how can I set the .yml configuration to scan the SPM package code?

@krzysztofzablocki
Copy link
Owner

You'd need to use the spm cache

@Velin92
Copy link
Author

Velin92 commented May 24, 2023

You'd need to use the spm cache

I tried to use the swiftpm cache in the config file like this:

sources:
  - ../../ElementX
  - ~/Library/Caches/org.swift.swiftpm/
templates:
  - AutoMockable.stencil
output:
  ../../ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
args:
  automMockableTestableImports: []
  autoMockableImports: [Combine, Foundation, MatrixRustSDK, AnalyticsEvents]

However it's still trying to access my folder locally instead of accessing it from the user folde, in fact the script fails saying:
'/Users/mauroromito/Documents/Xworkspace/element-x-ios/Tools/Sourcery/~/Library/Caches/org.swift.swiftpm' does not exist or is not readable.

Of course since the sourcery script should also work across multiple collaborators and on the CI, I can't use multiple ../ to reach the user folder.

How would I achieve that with the .yml configuration?

@markst
Copy link
Contributor

markst commented Apr 2, 2024

@Velin92 you might want to consider using a build tool plugin like I've mentioned in here https://www.polpiella.dev/sourcery-swift-package-command-plugin

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

No branches or pull requests

3 participants