You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Under the hood `CaptureOutput` temporarily captures both streams, copies the data to a buffer and returns the output back to you, before cleaning everything back up again.
199
199
200
+
### A note on `ErrorAs` and `errcheck`
201
+
202
+
`test.ErrorAs[T]` returns the matched error so you can chain further assertions on its fields:
203
+
204
+
```go
205
+
got:= test.ErrorAs[*os.PathError](t, err)
206
+
test.Equal(t, got.Op, "open")
207
+
```
208
+
209
+
The return value is optional — discarding it is a supported pattern when you only want the type-check assertion:
210
+
211
+
```go
212
+
test.ErrorAs[*os.PathError](t, err) // pure type check, return ignored
213
+
```
214
+
215
+
If you lint with [`errcheck`] it will flag the discard because `T` is constrained to `error`. `errcheck`'s `exclude-functions` doesn't currently match generic instantiations, so the cleanest fix is a source-based exclusion in `.golangci.yml`:
216
+
217
+
```yaml
218
+
linters:
219
+
exclusions:
220
+
rules:
221
+
- source: 'test\.ErrorAs\['
222
+
linters:
223
+
- errcheck
224
+
```
225
+
200
226
### See Also
201
227
202
228
- [FollowTheProcess/snapshot] for golden file/snapshot testing 📸
@@ -205,6 +231,7 @@ Under the hood `CaptureOutput` temporarily captures both streams, copies the dat
205
231
206
232
This package was created with [copier] and the [FollowTheProcess/go_copier] project template.
0 commit comments