Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add withKnownIssue comments to known Issues #1014

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aroben
Copy link

@aroben aroben commented Mar 11, 2025

Add withKnownIssue comments to known Issues

Motivation:

The Comment passed to withKnownIssue() is currently only used when a known issue does not occur. When a known issue does occur, it is marked isKnown but does not contain any record of the withKnownIssue() comment, making it harder to understand why the issue was considered to be known, especially if there are multiple nested withKnownIssue() calls.

Modifications:

When an issue is marked "known" by a withKnownIssue() call, the recorded issue will now have multiple comments in its comments array:

  1. The comment passed to withKnownIssue(), if any
  2. The Issue's own comment(s)

If the issue is recorded within multiple nested withKnownIssue() calls, only the comment of the innermost matching call is added to the Issue.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@grynspan grynspan added bug Something isn't working issue-handling Related to Issue handling within the testing library labels Mar 11, 2025
@grynspan grynspan added this to the Swift 6.2 milestone Mar 11, 2025
@aroben
Copy link
Author

aroben commented Mar 11, 2025

@swift-ci test

### Motivation:

The Comment passed to withKnownIssue() is currently only used when a
known issue does not occur. When a known issue does occur, it is marked
isKnown but does not contain any record of the withKnownIssue() comment,
making it harder to understand why the issue was considered to be known,
especially if there are multiple nested withKnownIssue() calls.

### Modifications:

When an issue is marked "known" by a `withKnownIssue()` call, the
recorded issue will now have multiple comments in its `comments` array:

1. The comment passed to `withKnownIssue()`, if any
2. The Issue's own comment(s)

If the issue is recorded within multiple nested `withKnownIssue()`
calls, only the comment of the innermost matching call is added to the
Issue.

### Checklist:

- [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should be updated.
@aroben aroben force-pushed the known-issue-comments branch from cf99d11 to c6cbd3d Compare March 11, 2025 18:17
@aroben
Copy link
Author

aroben commented Mar 11, 2025

@swift-ci test

2 similar comments
@aroben
Copy link
Author

aroben commented Mar 11, 2025

@swift-ci test

@aroben
Copy link
Author

aroben commented Mar 11, 2025

@swift-ci test

/// current task.
///
/// If there is no call to `withKnownIssue()` executing on the current task,
/// the value of this property is `nil`.
@TaskLocal
static var currentKnownIssueMatcher: KnownIssueMatcher?
static var currentKnownIssueContext: KnownIssueContext?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task local could probably now be relocated to the new KnownIssueContext type and be renamed current.

precondition(!isKnown)
isKnown = true
if let comment {
comments.insert(comment, at: 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be useful and important for us to propagate the comment from withKnownIssue (if any) to the issue in a way that allows distinguishing it from the issue's original comments (if it had any). If we don't, then clients who wish to display the issue might conflate the two categories of comments, which may be confusing to end users. We don't have a mechanism right now to distinguish the "original" comments from these, so I think it may be worthwhile to add a new field to Issue to support this, and to generally contain any other relevant details about the issue having been marked as "known". (If we had such a property, the current isKnown property could be derived from it.)

I'm not quite sure why this is inserting comment into the array at index 0, but if the reason is so that clients could find it and assume the first comment was the known issue comment, that feels fragile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working issue-handling Related to Issue handling within the testing library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants