Skip to content

Add support for sendable conformance argument #106

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

nolinmcfarland
Copy link
Contributor

@nolinmcfarland nolinmcfarland commented Apr 27, 2025

📝 Summary

Added support for sendable conformance (.checked | .unchecked) on generated mocks. This is provided as an argument on the @Mocked macro:

  • Passing .checked (also the Default) is a no-op right now since the mock's sendability is inherited through the implementation and implicitly checked by the compiler already.
  • Passing .unchecked conforms the generated mock to @unchecked Sendable, supporting a fix for the issue described in [Feature] Support unchecked Sendable #86.

To accomplish this, this pull request:

  • Adds a new SendableConformance macro argument.
  • Defines a new MacroArgument protocol and refactors argument parsing to allow for partial arguments (ex., having sendableConformance but not compilationCondition), giving us greater flexibility for future arguments.
  • Makes @unchecked Sendable a reusable extension of InheritedTypeSyntax.
  • Adds @unchecked Sendable to the inheritance clause when .unchecked is passed in for the sendableConformance argument.
  • Updates tests and documentation.

🛠️ Type of Change

  • Bug fix (change that fixes an issue)
  • New feature (change that adds functionality)
  • Breaking change (bug fix or feature that is not backwards compatible)
  • Documentation (DocC, API docs, markdown files, templates, etc.)
  • Testing (new tests, updated tests, etc.)
  • Refactoring or code formatting (no logic changes)
  • Updating dependencies (Swift packages, Homebrew, etc.)
  • CI/CD (change to automated workflows)

🧪 How Has This Been Tested?

I replicated the scenario and error described in #86 and verified it is resolved when conforming the mock to @unchecked Sendable. Unit tests verifying the macro's expansion passed. Please see screenshots of the expansions below:

Sendable Conformance Macro Expansion
Default (.checked) default_expanded
.checked checked_expanded
.unchecked unchecked_expanded

🔗 Related PRs or Issues

✅ Checklist

  • I have added relevant tests
  • I have verified all tests pass
  • I have formatted my code using SwiftFormat
  • I have updated documentation (if needed)
  • I have added the appropriate label to my PR
  • I have read the contributing guidelines
  • I agree to follow this project's Code of Conduct

@nolinmcfarland nolinmcfarland added the enhancement New feature or request label Apr 27, 2025
@nolinmcfarland nolinmcfarland self-assigned this Apr 27, 2025
@nolinmcfarland nolinmcfarland requested review from a team, SajanShrestha11, vnguyen-fetch and pwufetch and removed request for a team April 27, 2025 18:04
@nolinmcfarland nolinmcfarland changed the title Add support for sendable conformance Add support for sendable conformance argument Apr 27, 2025
Copy link

codecov bot commented Apr 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.77%. Comparing base (3970815) to head (28fe528).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
+ Coverage   68.64%   68.77%   +0.13%     
==========================================
  Files          69       71       +2     
  Lines        4538     4557      +19     
==========================================
+ Hits         3115     3134      +19     
  Misses       1423     1423              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Support unchecked Sendable
1 participant