-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllms.txt
More file actions
51 lines (40 loc) · 3.07 KB
/
Copy pathllms.txt
File metadata and controls
51 lines (40 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# swift-mockable
> A Swift macro (`@Mockable`) that generates protocol mocks with call tracking, argument capture, and configurable handlers for testing. MIT licensed, supports Swift 5.9+/6.2+.
swift-mockable provides a single `@Mockable` macro that you attach to any Swift protocol. It generates a `<ProtocolName>Mock` class wrapped in `#if DEBUG` (by default — the `condition:` argument selects a custom flag or removes the guard) with:
- `<method>CallCount` / `<method>CallArgs` / `<method>Handler` for every method
- `_<property>` backing storage and protocol-conforming computed properties
- `subscript<suffix>CallCount` / `CallArgs` / `Handler` / `SetHandler` for subscripts
- `initCallCount` / `initCallArgs` for `init` requirements (recording `required init`; lock-backed on `Sendable`/`actor` mocks)
- `resetMock()` to clear all tracking state
## Key Features
- Sync, async, throws, rethrows methods
- Typed throws (`throws(MyError)`, SE-0413) on methods, properties, and subscripts (`throws(Never)` is mocked as non-throwing; `throws(any Error)` like untyped `throws`)
- Get-only, get-set, and optional properties
- Effectful read-only properties (`get async` / `get throws`) mocked with handlers
- Get-only and get-set subscripts (including effectful `get async` / `get throws` subscripts)
- Variadic parameters (captured as arrays)
- `@autoclosure` parameters (evaluated once per call, recorded by value)
- Non-escaping closure parameters (forwarded to the handler, excluded from `CallArgs`)
- `inout` parameters with write-back support
- Generic methods (type-erased to `Any`)
- Associated types (uses default type or `Any`)
- Overloaded methods (unique suffixes auto-generated)
- Initializer requirements (`init(...)`) as recording `required init` (including `Sendable`/`actor` mocks)
- Static methods and properties
- `Sendable` protocol support (`@unchecked Sendable` + `MockableLock`)
- `Actor` protocol support (actor mock with `nonisolated` helpers)
- `@MainActor` protocol support
- Protocol inheritance (child mock inherits parent mock)
- `#if` / `#elseif` / `#else` conditional compilation
- Configurable compilation condition for the generated mock (`@Mockable(condition:)` — `.debug` default, `.custom("MOCKING")` / `.custom("DEBUG || UITESTS")`, or `.always`)
## Requirements
- Swift 5.9, 5.10, 6.2+
- macOS 10.15+ / iOS 13+ / tvOS 13+ / watchOS 6+ / visionOS 1+ / macCatalyst 13+
- MIT License
## Documentation
- [Full documentation for LLMs](https://yysskk.github.io/swift-mockable/llms-full.txt): Complete installation, usage, naming conventions, and advanced features in a single file
- [Getting Started](https://yysskk.github.io/swift-mockable/documentation/mockable/gettingstarted): Installation and basic usage
- [Advanced Usage](https://yysskk.github.io/swift-mockable/documentation/mockable/advancedusage): Naming rules, generics, inout, Sendable, Actor, inheritance
## Optional
- [GitHub Repository](https://github.com/yysskk/swift-mockable): Source code, issues, contributions
- [API Reference](https://yysskk.github.io/swift-mockable/documentation/mockable): DocC-generated API documentation