Skip to content

Commit e37e7cf

Browse files
committed
wip
1 parent 2f3ac95 commit e37e7cf

File tree

5 files changed

+74
-55
lines changed

5 files changed

+74
-55
lines changed

README.md

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,75 @@
44
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fpointfreeco%2Fxctest-dynamic-overlay%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/pointfreeco/xctest-dynamic-overlay)
55
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fpointfreeco%2Fxctest-dynamic-overlay%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/pointfreeco/xctest-dynamic-overlay)
66

7-
Report issues in your application and library code as Xcode runtime warnings, test failures, and
8-
more.
7+
Report issues in your application and library code as Xcode runtime warnings, breakpoints,
8+
assertions, and do so in a testable manner.
99

1010
## Overview
1111

12-
Swift Issue Reporting lets you generate your own "purple" Xcode runtime warnings in application and
13-
library code:
12+
This library provides robust tools for reporting issues in your application with a customizable
13+
degree of granularity and severity. In its most basic for you use the unified
14+
[`reportIssue`](<doc:reportIssue(_:fileID:filePath:line:column:)>) function anywhere in your
15+
application to flag an issue with your code, such as a code path that you think should never be
16+
executed:
1417

15-
[![](todo://image-of-runtime-warnings)]
16-
17-
Further, if one of these runtime warnings is emitted from a unit test, it will automatically be
18-
recorded as a test failure:
18+
```swift
19+
guard let lastItem = items.last
20+
else {
21+
reportIssue("'items' should never be empty.")
22+
return
23+
}
24+
25+
```
1926

20-
[![](todo://image-of-test-failure)]
27+
By default, [`reportIssue`](<doc:reportIssue(_:fileID:filePath:line:column:)>) will trigger an
28+
unobtrusive, purple runtime warning when running your app in Xcode (simulator and device):
2129

22-
And so the benefits are twofold: reporting issues will help you catch bugs during debug _and_ test
23-
sessions.
30+
![A purple runtime warning in Xcode showing that an issue has been reported.](runtime-warning)
2431

25-
While this is incredibly useful on its own, it only scratches the library's surface. This
26-
functionality is built on top of a highly flexible issue reporting system that can be used in a
27-
variety of ways.
32+
This provides a very visible way to see when an issue has occured in your application without
33+
stopping the app's execution and interrupting your workflow.
2834

29-
### Custom issue reporting
35+
The [`reportIssue`](<doc:reportIssue(_:fileID:filePath:line:column:)>) tool can also be customized
36+
to allow for other ways of reporting issues. It can be configured to trigger a breakpoint if you
37+
want to do some debugging when an issue is reported, or a precondition or fatal error if you want
38+
to truly stop execution. And you can create your own custom issue reporter to send issues to OSLog
39+
or an external server.
3040

31-
<!-- TODO -->
41+
Further, when running your code in a testing context (both XCTest and Swift's native Testing
42+
framework), all reported issues become _test failures_. This helps you get test coverage that
43+
problematic code paths are not executed, and makes it possible to build testing tools for libraries
44+
that ship in the same target as the library itself.
3245

33-
### Custom test helpers
46+
// TODO: test failure image
3447

35-
<!-- TODO -->
48+
// TODO: link to get started article
3649

3750
## Case studies
3851

3952
There are many popular libraries out there using Swift Issue Reporting. To name a few:
4053

4154
<!-- TODO: Order? -->
42-
43-
* [**The Composable Architecture**](https://github.com/pointfreeco/swift-composable-architecture)
44-
comes with powerful testing tools that support both Swift Testing and XCTest out of the box
45-
thanks to Swift Issue Reporting. In addition, the library is heavily instrumented with issue
46-
reporting to help developers catch bugs in their code early.
55+
<!-- TODO: Rewrite for SwiftUI Navigation if Swift Issue Reporting is released first -->
4756

4857
* [**Perception**](https://github.com/pointfreeco/swift-perception) is a back-port of Swift's
4958
Observation framework that can be deployed all the way back to the iOS 13 generation of devices.
5059
It provides a special SwiftUI view that can observe changes to objects annotated with the macro,
5160
and uses Swift Issue Reporting to warn developers when this view is missing.
5261

53-
<!-- TODO: Rewrite for SwiftUI Navigation if Swift Issue Reporting is released first -->
54-
55-
* [**Swift Navigation**](https://github.com/pointfreeco/swiftui-navigation) provides concise
56-
domain modeling tools for UI frameworks including SwiftUI, UIKit, and more; and it uses Swift
57-
Issue Reporting to raise runtime warnings when APIs are used in unexpected ways.
58-
5962
* [**Swift Dependencies**](https://github.com/pointfreeco/swift-dependencies) is a general purpose
6063
dependency injection tool inspired by SwiftUI's environment. It uses Swift Issue Reporting to
6164
notify users when they haven't asserted against how a dependency is used. This forces each test
6265
to explicitly declare its dependencies, and when a new dependency is introduced to a feature,
6366
existing tests will fail until they account for it.
6467

65-
* [**Swift Snapshot Testing**](https://github.com/pointfreeco/swift-snapshot-testing) provides
66-
test helpers that can automatically record failures to disk, or inline into tests when possible.
67-
These helpers are powered by Swift Issue Reporting and are automatically supported in both
68-
Swift Testing and XCTest.
68+
* [**Swift Navigation**](https://github.com/pointfreeco/swiftui-navigation) provides concise
69+
domain modeling tools for UI frameworks including SwiftUI, UIKit, and more; and it uses Swift
70+
Issue Reporting to raise runtime warnings when APIs are used in unexpected ways.
6971

70-
* [**Swift Macro Testing**](https://github.com/pointfreeco/swift-macro-testing) builds upon
71-
[Swift Snapshot Testing](https://github.com/pointfreeco/swift-snapshot-testing), but
72-
specifically for macros. It uses the same issue reporting mechanism to provide test helpers to
73-
both Swift Testing and XCTest.
72+
* [**The Composable Architecture**](https://github.com/pointfreeco/swift-composable-architecture)
73+
comes with powerful testing tools that support both Swift Testing and XCTest out of the box
74+
thanks to Swift Issue Reporting. In addition, the library is heavily instrumented with issue
75+
reporting to help developers catch bugs in their code early.
7476

7577
* [**Swift Custom Dump**](https://github.com/pointfreeco/swift-custom-dump) is an improved version
7678
of Swift's `dump` function, and a whole lot more. It provides well-formatted dumps of data types

Sources/IssueReporting/Documentation.docc/Extensions/Unimplemented.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-34tpp``
1+
# ``IssueReporting/unimplemented(_:placeholder:fileID:filePath:function:line:column:)-3hygi``
22

33
## Topics
44

@@ -7,7 +7,7 @@
77
- ``unimplemented(_:fileID:filePath:function:line:column:)-2ae22``
88
- ``unimplemented(_:fileID:filePath:function:line:column:)-1hsov``
99
- ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-6ts5j``
10-
- ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-3hygi``
10+
- ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-34tpp``
1111

1212
### Structures
1313

Sources/IssueReporting/Documentation.docc/IssueReporting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ``IssueReporting``
22

33
Report issues in your application and library code as Xcode runtime warnings, breakpoints,
4-
assertions, and more.
4+
assertions, and do so in a testable manner.
55

66
## Overview
77

@@ -72,4 +72,4 @@ that ship in the same target as the library itself.
7272

7373
### Unimplemented
7474

75-
- ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-34tpp``
75+
- ``unimplemented(_:placeholder:fileID:filePath:function:line:column:)-3hygi``

Sources/IssueReporting/ReportIssue.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
/// Report an issue.
22
///
3-
/// A generalized version of Swift Testing's [`Issue.record`][Issue.record] that emits "purple"
4-
/// warnings to Xcode at runtime and logs fault-level messages to the console.
3+
/// Invoking this function has two different behaviors depending on the context:
54
///
6-
/// During test runs, the issue will be sent to Swift Testing's [`Issue.record`][Issue.record] _or_
7-
/// XCTest's [`XCTFail`][XCTFail] accordingly, which means you can use it to drive custom assertion
8-
/// helpers that you want to work in both Swift Testing and XCTest.
5+
/// * When running your code in a non-testing context, this method will loop over the
6+
/// collection of issue reports registered and invoke them. The default issue reporter for the
7+
/// library is ``IssueReporter/runtimeWarning``, which emits a purple, runtime warning in Xcode:
8+
///
9+
/// ![A purple runtime warning in Xcode showing that an issue has been reported.](https://pointfreeco-blog.s3.amazonaws.com/posts/0147-issue-reporting/runtime-warning.png)
10+
///
11+
/// But you can there are also [other issue reports](<doc:GettingStarted#Issue-reporters>) you
12+
/// can use, and you can create your own.
13+
///
14+
/// * When running your app in tests (both XCTest and Swift's native Testing framework), it will
15+
/// emit a test failure. This allows you to get test coverage on your reported issues, both expected
16+
/// and unexpected ones.
917
///
1018
/// [Issue.record]: https://developer.apple.com/documentation/testing/issue/record(_:sourcelocation:)
1119
/// [XCTFail]: https://developer.apple.com/documentation/xctest/1500970-xctfail/
@@ -68,15 +76,8 @@ public func reportIssue(
6876

6977
/// Report a caught error.
7078
///
71-
/// A generalized version of Swift Testing's [`Issue.record`][Issue.record] that emits "purple"
72-
/// warnings to Xcode at runtime and logs fault-level messages to the console.
73-
///
74-
/// During test runs, the issue will be sent to Swift Testing's [`Issue.record`][Issue.record] _or_
75-
/// XCTest's [`XCTFail`][XCTFail] accordingly, which means you can use it to drive custom assertion
76-
/// helpers that you want to work in both Swift Testing and XCTest.
77-
///
78-
/// [Issue.record]: https://developer.apple.com/documentation/testing/issue/record(_:_:sourcelocation:)
79-
/// [XCTFail]: https://developer.apple.com/documentation/xctest/1500970-xctfail/
79+
/// This function behaves similarly to ``reportIssue(_:fileID:filePath:line:column:)``, but for
80+
/// reporting errors.
8081
///
8182
/// - Parameters:
8283
/// - error: The error that caused the issue.

Sources/IssueReporting/Unimplemented.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/// Returns a closure that reports an issue when invoked.
22
///
3+
/// Useful for creating closures that need to be overridden by users of your API, and if it is
4+
/// ever invoked without being overridden an issue will be reported. See
5+
/// <doc:GettingStarted#Unimplemented-closures> for more information.
6+
///
37
/// - Parameters:
48
/// - description: An optional description of the unimplemented closure.
59
/// - placeholder: A placeholder value returned from the closure when left unimplemented.
@@ -34,6 +38,10 @@ public func unimplemented<each Argument, Result>(
3438

3539
/// Returns a throwing closure that reports an issue and throws an error when invoked.
3640
///
41+
/// Useful for creating closures that need to be overridden by users of your API, and if it is
42+
/// ever invoked without being overridden an issue will be reported. See
43+
/// <doc:GettingStarted#Unimplemented-closures> for more information.
44+
///
3745
/// - Parameters:
3846
/// - description: An optional description of the unimplemented closure.
3947
/// - fileID: The fileID.
@@ -67,6 +75,10 @@ public func unimplemented<each Argument, Result>(
6775

6876
/// Returns an asynchronous closure that reports an issue when invoked.
6977
///
78+
/// Useful for creating closures that need to be overridden by users of your API, and if it is
79+
/// ever invoked without being overridden an issue will be reported. See
80+
/// <doc:GettingStarted#Unimplemented-closures> for more information.
81+
///
7082
/// - Parameters:
7183
/// - description: An optional description of the unimplemented closure.
7284
/// - placeholder: A placeholder value returned from the closure when left unimplemented.
@@ -101,6 +113,10 @@ public func unimplemented<each Argument, Result>(
101113

102114
/// Returns a throwing, asynchronous closure that reports an issue and throws an error when invoked.
103115
///
116+
/// Useful for creating closures that need to be overridden by users of your API, and if it is
117+
/// ever invoked without being overridden an issue will be reported. See
118+
/// <doc:GettingStarted#Unimplemented-closures> for more information.
119+
///
104120
/// - Parameters:
105121
/// - description: An optional description of the unimplemented closure.
106122
/// - fileID: The fileID.

0 commit comments

Comments
 (0)