Skip to content

Commit 08f09c1

Browse files
authored
Assert more with multiple trailing closures (#3)
* Assert more with multiple trailing closures * Update Deprecations.swift * fix * bump * wip
1 parent c92720e commit 08f09c1

23 files changed

+463
-269
lines changed

Package.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"kind" : "remoteSourceControl",
66
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
77
"state" : {
8-
"revision" : "696b86a6d151578bca7c1a2a3ed419a5f834d40f",
9-
"version" : "1.13.0"
8+
"revision" : "506b6052384d8e97a4bb16fe8680325351c23c64",
9+
"version" : "1.14.0"
1010
}
1111
},
1212
{

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let package = Package(
1818
],
1919
dependencies: [
2020
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
21-
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.13.0"),
21+
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.14.0"),
2222
],
2323
targets: [
2424
.target(

README.md

+29-9
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func testStringify() {
5858
"""
5959
#stringify(a + b)
6060
"""
61-
} matches: {
61+
} expansion: {
6262
"""
6363
(a + b, "a + b")
6464
"""
@@ -86,14 +86,14 @@ assertMacro(["stringify": StringifyMacro.self], record: true) {
8686
"""
8787
#stringify(a + b)
8888
"""
89-
} matches: {
89+
} expansion: {
9090
"""
9191
(a + b, "a + b")
9292
"""
9393
}
9494
```
9595
96-
Now when you run the test again the freshest expanded macro will be written to the `matches`
96+
Now when you run the test again the freshest expanded macro will be written to the `expansion`
9797
trailing closure.
9898

9999
If you're writing many tests for a macro, you can avoid the repetitive work of specifying the macros
@@ -115,7 +115,7 @@ class StringifyMacroTests: XCTestCase {
115115
"""
116116
#stringify(a + b)
117117
"""
118-
} matches: {
118+
} expansion: {
119119
"""
120120
(a + b, "a + b")
121121
"""
@@ -142,27 +142,47 @@ override func invokeTest() {
142142
Macro Testing can also test diagnostics, such as warnings, errors, notes, and fix-its. When a macro
143143
expansion emits a diagnostic, it will render inline in the test. For example, a macro that adds
144144
completion handler functions to async functions may emit an error and fix-it when it is applied to a
145-
non-async function. The resulting macro test will fully capture this information:
145+
non-async function. The resulting macro test will fully capture this information, including where
146+
the diagnostics are emitted, how the fix-its are applied, and how the final macro expands:
146147

147148
```swift
148149
func testNonAsyncFunctionDiagnostic() {
149150
assertMacro {
150151
"""
151152
@AddCompletionHandler
152-
func f(a: Int, for b: String, _ value: Double) -> String {
153+
func f(a: Int, for b: String) -> String {
153154
return b
154-
}
155+
}
155156
"""
156-
} matches: {
157+
} diagnostics: {
157158
"""
158159
@AddCompletionHandler
159-
func f(a: Int, for b: String, _ value: Double) -> String {
160+
func f(a: Int, for b: String) -> String {
160161
┬───
161162
╰─ 🛑 can only add a completion-handler variant to an 'async' function
162163
✏️ add 'async'
163164
return b
164165
}
165166
"""
167+
} fixes: {
168+
"""
169+
@AddCompletionHandler
170+
func f(a: Int, for b: String) async -> String {
171+
return b
172+
}
173+
"""
174+
} expansion: {
175+
"""
176+
func f(a: Int, for b: String) async -> String {
177+
return b
178+
}
179+
180+
func f(a: Int, for b: String, completionHandler: @escaping (String) -> Void) {
181+
Task {
182+
completionHandler(await f(a: a, for: b, value))
183+
}
184+
}
185+
"""
166186
}
167187
}
168188
```

0 commit comments

Comments
 (0)