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

Some methods not working correctly in Type object #1397

Open
darkside999 opened this issue Jan 9, 2025 · 0 comments
Open

Some methods not working correctly in Type object #1397

darkside999 opened this issue Jan 9, 2025 · 0 comments

Comments

@darkside999
Copy link

We use SwiftyMocky for generating Mocks from protocols and we also migrate our project to Swift 6.

Currently we use Sourcery 2.0.2 and it works fine with SwiftyMocky. But after upgrading version of Sourcery to 2.2.6 we have encountered with crash of SwiftyMocky and we decided to make our own version of Mock.swifttemplate for SwiftyMocky where crash was fixed and we added some improvements to it having some adaption to Swift 6.

But we found out that methods allMethods and allVariables from Type from SourceryRuntime generates methods from extensions that don't related with methods of current type. For example:

Protocols to generate in one file:

// sourcery: AutoMockable
// sourcery: ObjcProtocol
@MainActor @objc public protocol AlertPresentingViewInput: AlertPresenting {

	func showAlert(_ alertController: UIAlertController)

}

// sourcery: AutoMockable
@MainActor @objc public protocol AlertPresenting {

	func showAlert(withMessage message: String)

}

Some extension of View that doesn't related with AlertPresentingViewInput in other file:

extension View {

	func styledForTradingPanel(fillColor: Color, cornerRadius: Double) -> some View {
		// code
	}

}

When we generating with Sourcery 2.0.2 we have such methods in mock class:

@MainActor @objc
open class AlertPresentingViewInputMock: NSObject, AlertPresentingViewInput, Mock {
	
	// ... mock code

	open func showAlert(_ alertController: UIAlertController) {
		// mock code
	}

	open func showAlert(withMessage message: String) {
		// mock code
	}

	// ... mock code
}

When we generating with Sourcery 2.2.6 we have such methods in mock class:

@MainActor @objc
open class AlertPresentingViewInputMock: NSObject, AlertPresentingViewInput, Mock {
	
	// ... mock code

	open func showAlert(_ alertController: UIAlertController) {
		// mock code
	}

	open func showAlert(withMessage message: String) {
		// mock code
	}

	open func styledForTradingPanel(fillColor: Color, cornerRadius: Double) -> some View {
 		// mock code
	}
	
	// ... mock code

}

Of course, we have found workaround for this in our template file filtering such methods by definedInTypeName?.name property of Method class but we want you to pay attention on this problem as well.

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

1 participant