Skip to content

Add withKnownIssue comments to known Issues #1014

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

Merged
merged 27 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c6cbd3d
Add withKnownIssue comments to known Issues
aroben Mar 10, 2025
acdb283
KnownIssueContext.current
aroben Mar 12, 2025
08b1c3f
KnownIssueContext -> KnownIssueScope
aroben Mar 12, 2025
45f8d9f
Issue.knownIssueContext
aroben Mar 12, 2025
e2da439
Update comment
aroben Mar 12, 2025
e0251d8
Fix typo
aroben Mar 12, 2025
89b0a67
Remove KnownIssueScope.Match
aroben Mar 12, 2025
deffa29
Renames for clarity
aroben Mar 12, 2025
e6e4fd4
Update tests
aroben Mar 12, 2025
a9b3163
Fix up doc comments
aroben Mar 18, 2025
1282cab
Remove Issue.isKnown.set since this is only SPI
aroben Mar 18, 2025
0dfcff8
Preserve EncodedIssue ABI
aroben Mar 18, 2025
7cd86f6
Add ABI.EncodedKnownIssueContext
aroben Mar 24, 2025
c0e8ce7
Fix doc comments
aroben Mar 24, 2025
af08da2
Replace EncodedIssue._knownIssueContext with an extra Message
aroben Apr 7, 2025
b66a484
Remove KnownIssueContext.sourceLocation
aroben Apr 7, 2025
b9275e8
Resurrect Issue.isKnown.setter
aroben Apr 7, 2025
81fe877
Remove `withKnownIssue()` shorthand
aroben Apr 7, 2025
9192e4a
Add a test for the HumanReadableOutputRecorder change
aroben Apr 7, 2025
feb96cf
Rename KnownIssueScope.match -> matcher
aroben Apr 7, 2025
874f830
Deduplicate known issue comments for thrown errors
aroben Apr 7, 2025
6caad07
Use Locked.rawValue
aroben Apr 7, 2025
316d10c
Explain why we treat .errorCaught specially
aroben Apr 7, 2025
8567a61
Apply suggestions from code review
aroben Apr 24, 2025
1ae8633
Don't put the known issue comment in Issue.comments for thrown errors
aroben Apr 24, 2025
00ad66d
Apply suggestions from code review
aroben Apr 24, 2025
0a3a995
Incorporate review comments
aroben Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ extension Event.HumanReadableOutputRecorder {
}
additionalMessages += _formattedComments(issue.comments)
if let knownIssueComment = issue.knownIssueContext?.comment {
additionalMessages.append(_formattedComment(knownIssueComment))
if case .errorCaught = issue.kind {
// The known issue comment is already included in `issue.comments`.
} else {
additionalMessages.append(_formattedComment(knownIssueComment))
}
}

if verbosity > 0, case let .expectationFailed(expectation) = issue.kind {
Expand Down
69 changes: 58 additions & 11 deletions Tests/TestingTests/EventRecorderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,33 @@ struct EventRecorderTests {
}
}

@Test("HumanReadableOutputRecorder includes known issue comment in messages array")
func humanReadableRecorderIncludesKnownIssueCommentInMessagesArray() {
var issue = Issue(kind: .unconditional)
issue.knownIssueContext = Issue.KnownIssueContext(comment: "Known issue comment")
let event = Event(.issueRecorded(issue), testID: nil, testCaseID: nil)
let context = Event.Context(test: nil, testCase: nil, configuration: nil)

@Test(
"HumanReadableOutputRecorder includes known issue comment in messages array",
arguments: [
("recordWithoutKnownIssueComment()", ["#expect comment"]),
("recordWithKnownIssueComment()", ["#expect comment", "withKnownIssue comment"]),
("throwWithoutKnownIssueComment()", []),
("throwWithKnownIssueComment()", ["withKnownIssue comment"]),
]
)
func knownIssueComments(testName: String, expectedComments: [String]) async throws {
var configuration = Configuration()
let recorder = Event.HumanReadableOutputRecorder()
let messages = recorder.record(event, in: context)
#expect(
messages.map(\.stringValue).contains("Known issue comment")
)
let messages = Locked<[Event.HumanReadableOutputRecorder.Message]>(rawValue: [])
configuration.eventHandler = { event, context in
guard case .issueRecorded = event.kind else { return }
messages.withLock {
$0.append(contentsOf: recorder.record(event, in: context))
}
}

await runTestFunction(named: testName, in: PredictablyFailingKnownIssueTests.self, configuration: configuration)

// The first message is something along the lines of "Test foo recorded a
// known issue" and includes a source location, so is inconvenient to
// include in our expectation here.
let actualComments = messages.withLock(\.self).dropFirst().map(\.stringValue)
#expect(actualComments == expectedComments)
}
}

Expand Down Expand Up @@ -653,3 +668,35 @@ struct EventRecorderTests {
#expect(arg > 0)
}
}

@Suite(.hidden) struct PredictablyFailingKnownIssueTests {
@Test(.hidden)
func recordWithoutKnownIssueComment() {
withKnownIssue {
#expect(Bool(false), "#expect comment")
}
}

@Test(.hidden)
func recordWithKnownIssueComment() {
withKnownIssue("withKnownIssue comment") {
#expect(Bool(false), "#expect comment")
}
}

@Test(.hidden)
func throwWithoutKnownIssueComment() {
withKnownIssue {
struct TheError: Error {}
throw TheError()
}
}

@Test(.hidden)
func throwWithKnownIssueComment() {
withKnownIssue("withKnownIssue comment") {
struct TheError: Error {}
throw TheError()
}
}
}