Skip to content

Commit 957cb3a

Browse files
author
Maarten Engels
committed
Review preparation
1 parent 9001899 commit 957cb3a

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

proposals/testing/0013-issue-severity-warning.md

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Test Issue Severity
22

3-
* Proposal: [ST-XXXX](XXXX-issue-severity-warning.md)
4-
* Authors: [Suzy Ratcliff](https://github.com/suzannaratcliff)
5-
* Review Manager: TBD
6-
* Status: **Pitched**
7-
* Implementation: [swiftlang/swift-testing#1075](https://github.com/swiftlang/swift-testing/pull/1075)
8-
* Review: ([pitch](https://forums.swift.org/t/pitch-test-issue-warnings/79285))
3+
- Proposal: [ST-0013](0013-issue-severity-warning.md)
4+
- Authors: [Suzy Ratcliff](https://github.com/suzannaratcliff)
5+
- Review Manager: [Maarten Engels](https://github.com/maartene)
6+
- Status: **Awaiting Review**
7+
- Implementation: [swiftlang/swift-testing#1075](https://github.com/swiftlang/swift-testing/pull/1075)
8+
- Review: ([pitch](https://forums.swift.org/t/pitch-test-issue-warnings/79285))
99

1010
## Introduction
1111

@@ -17,20 +17,21 @@ Currently, when an issue arises during a test, the only possible outcome is to m
1717

1818
### Use Cases
1919

20-
- Warning about a Percentage Discrepancy in Image Comparison:
21-
- Scenario: When comparing two images to assess their similarity, a warning can be triggered if there's a 95% pixel match, while a test failure is set at a 90% similarity threshold.
22-
- Reason: In practices like snapshot testing, minor changes (such as a timestamp) might cause a discrepancy. Setting a 90% match as a pass ensures test integrity. However, a warning at 95% alerts testers that, although the images aren't identical, the test has passed, which may warrant further investigation.
20+
- Warning about a Percentage Discrepancy in Image Comparison:
21+
- Scenario: When comparing two images to assess their similarity, a warning can be triggered if there's a 95% pixel match, while a test failure is set at a 90% similarity threshold.
22+
- Reason: In practices like snapshot testing, minor changes (such as a timestamp) might cause a discrepancy. Setting a 90% match as a pass ensures test integrity. However, a warning at 95% alerts testers that, although the images aren't identical, the test has passed, which may warrant further investigation.
2323
- Warning for Duplicate Argument Inputs in Tests:
24-
- Scenario: In a test library, issue a warning if a user inputs the same argument twice, rather than flagging an error.
25-
- Reason: Although passing the same argument twice might not be typical, some users may have valid reasons for doing so. Thus, a warning suffices, allowing flexibility without compromising the test's execution.
24+
- Scenario: In a test library, issue a warning if a user inputs the same argument twice, rather than flagging an error.
25+
- Reason: Although passing the same argument twice might not be typical, some users may have valid reasons for doing so. Thus, a warning suffices, allowing flexibility without compromising the test's execution.
2626
- Warning for Recoverable Unexpected Events:
27-
- Scenario: During an integration test where data is retrieved from a server, a warning can be issued if the primary server is down, prompting a switch to an alternative server. Usually mocking is the solution for this but may not test everything needed for an integration test.
28-
- Reason: Since server downtime might happen and can be beyond the tester's control, issuing a warning rather than a failure helps in debugging and understanding potential issues without impacting the test's overall success.
27+
- Scenario: During an integration test where data is retrieved from a server, a warning can be issued if the primary server is down, prompting a switch to an alternative server. Usually mocking is the solution for this but may not test everything needed for an integration test.
28+
- Reason: Since server downtime might happen and can be beyond the tester's control, issuing a warning rather than a failure helps in debugging and understanding potential issues without impacting the test's overall success.
2929
- Warning for a retry during setup for a test:
30-
- Scenario: During test setup part of your code may be configured to retry, it would be nice to notify in the results that a retry happened
31-
- Reason: This makes sense to be a warning and not a failure because if the retry succeeds the test may still verify the code correctly
30+
- Scenario: During test setup part of your code may be configured to retry, it would be nice to notify in the results that a retry happened
31+
- Reason: This makes sense to be a warning and not a failure because if the retry succeeds the test may still verify the code correctly
3232

3333
## Proposed solution
34+
3435
We propose introducing a new property on `Issue` in Swift Testing called `severity`, that represents if an issue is a `warning` or an `error`.
3536
The default Issue severity will still be `error` and users can set the severity when they record an issue.
3637

@@ -47,7 +48,7 @@ The `Severity` enum:
4748
```swift
4849
extension Issue {
4950
// ...
50-
public enum Severity: Codable, Comparable, CustomStringConvertible, Sendable {
51+
public enum Severity: Codable, Comparable, CustomStringConvertible, Sendable {
5152
/// The severity level for an issue which should be noted but is not
5253
/// necessarily an error.
5354
///
@@ -66,13 +67,15 @@ extension Issue {
6667
```
6768

6869
### Recording Non-Failing Issues
70+
6971
To enable test authors to log non-failing issues without affecting test results, we provide a method for recording such issues:
7072

7173
```swift
7274
Issue.record("My comment", severity: .warning)
7375
```
7476

7577
Here is the `Issue.record` method definition with severity as a parameter.
78+
7679
```swift
7780
/// Record an issue when a running test fails unexpectedly.
7881
///
@@ -92,13 +95,14 @@ Here is the `Issue.record` method definition with severity as a parameter.
9295
severity: Severity = .error,
9396
sourceLocation: SourceLocation = #_sourceLocation
9497
) -> Self
95-
98+
9699
// ...
97100
```
98101

99102
### Issue Type Enhancements
100103

101104
The Issue type is enhanced with two new properties to better handle and report issues:
105+
102106
- `severity`: This property allows access to the specific severity level of an issue, enabling more precise handling of test results.
103107

104108
```swift
@@ -112,7 +116,9 @@ public var severity: Severity { get set }
112116
}
113117

114118
```
119+
115120
- `isFailure`: A boolean property to determine if an issue results in a test failure, thereby helping in result aggregation and reporting.
121+
116122
```swift
117123
extension Issue {
118124
// ...
@@ -132,6 +138,7 @@ extension Issue {
132138
```
133139

134140
Example usage of `severity` and `isFailure`:
141+
135142
```swift
136143
// ...
137144
withKnownIssue {
@@ -147,7 +154,7 @@ This revision aims to clarify the functionality and usage of the `Severity` enum
147154

148155
### Integration with supporting tools
149156

150-
Issue severity will be in the event stream output when a `issueRecorded` event occurs. This will be a breaking change because some tools may assume that all `issueRecorded` events are failing. Due to this we will be bumping the event stream version and v1 will maintain it's behavior and not output any events for non failing issues. We will also be adding `isFailure` to the issue so that clients will know if the issue should be treated as a failure.
157+
Issue severity will be in the event stream output when a `issueRecorded` event occurs. This will be a breaking change because some tools may assume that all `issueRecorded` events are failing. Due to this we will be bumping the event stream version and v1 will maintain it's behavior and not output any events for non failing issues. We will also be adding `isFailure` to the issue so that clients will know if the issue should be treated as a failure.
151158

152159
The JSON event stream ABI will be amended correspondingly:
153160

@@ -198,7 +205,7 @@ For more details on how to checkout a branch for a package refer to this: https:
198205
- Naming of `isFailure` vs. `isFailing`: We evaluated whether to name the property `isFailing` instead of `isFailure`. The decision to use `isFailure` was made to adhere to naming conventions and ensure clarity and consistency within the API.
199206

200207
- Severity-Only Checking: We deliberated not exposing `isFailure` and relying solely on `severity` checks. However, this was rejected because it would require test authors to overhaul their code should we introduce additional severity levels in the future. By providing `isFailure`, we offer a straightforward way to determine test outcome impact, complementing the severity feature.
201-
- Naming `Severity.error` `Severity.failure` instead because this will always be a failing issue and test authors often think of test failures. Error and warning match build naming conventions and XCTest severity naming convention.
208+
- Naming `Severity.error` `Severity.failure` instead because this will always be a failing issue and test authors often think of test failures. Error and warning match build naming conventions and XCTest severity naming convention.
202209

203210
## Future directions
204211

0 commit comments

Comments
 (0)