Skip to content

Error when generateMock: true conflicts with user-defined mock method#214

Merged
dfed merged 6 commits intomainfrom
dfed--error-on-generate-mock-with-user-mock
Apr 5, 2026
Merged

Error when generateMock: true conflicts with user-defined mock method#214
dfed merged 6 commits intomainfrom
dfed--error-on-generate-mock-with-user-mock

Conversation

@dfed
Copy link
Copy Markdown
Owner

@dfed dfed commented Apr 5, 2026

Summary

  • When an @Instantiable type has both generateMock: true and a hand-written mock() method, the macro now emits a compile-time error with a fix-it to remove generateMock: true.
  • Previously this was silently handled at the tool level (skipping generation). Now it's caught early with a clear diagnostic.
  • Applies to both concrete type declarations and extension-based @Instantiable types.

Test plan

  • producesDiagnostic_whenGenerateMockIsTrueAndUserDefinedMockExists — single-argument attribute, fix-it removes entire argument clause
  • producesDiagnostic_whenGenerateMockIsTrueAndUserDefinedMockExistsWithOtherArguments — multi-argument attribute, fix-it removes only generateMock: true
  • mockMethodConflictsWithGenerateMock_description_mentionsBothGenerateMockAndMockMethod
  • mockMethodConflictsWithGenerateMock_fixIt_mentionsRemovingGenerateMock
  • Full test suite passes (709 tests)
  • SwiftFormat clean

🤖 Generated with Claude Code

dfed and others added 2 commits April 4, 2026 19:56
When an @INSTANTIABLE type has both `generateMock: true` and a
hand-written `mock()` method, emit a macro diagnostic with a fix-it
that removes `generateMock: true` from the attribute.

Previously this was silently handled at the tool level by skipping
generation. Now it's caught at compile time with a clear error.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.94%. Comparing base (6dd6df9) to head (a669587).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #214   +/-   ##
=======================================
  Coverage   99.94%   99.94%           
=======================================
  Files          40       40           
  Lines        5601     5648   +47     
=======================================
+ Hits         5598     5645   +47     
  Misses          3        3           
Files with missing lines Coverage Δ
...s/SafeDICore/Errors/FixableInstantiableError.swift 100.00% <100.00%> (ø)
...ources/SafeDIMacros/Macros/InstantiableMacro.swift 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dfed dfed marked this pull request as ready for review April 5, 2026 03:35
dfed and others added 2 commits April 4, 2026 20:41
The method is only called when generateMockValue is true, which
guarantees arguments exist. The guard was dead code that hurt coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add @mainactor to multi-argument test so the rewriter visits a
non-matching attribute, covering the else branch. Also add a negative
test confirming no diagnostic when generateMock is not set.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dfed dfed merged commit a1c24df into main Apr 5, 2026
19 checks passed
@dfed dfed deleted the dfed--error-on-generate-mock-with-user-mock branch April 5, 2026 04:13
@dfed dfed restored the dfed--error-on-generate-mock-with-user-mock branch April 5, 2026 04:13
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

Successfully merging this pull request may close these issues.

1 participant