Skip to content

Fix how we check if a range expression covers one value. #815

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Sources/Testing/Issues/Issue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ extension Issue.Kind: CustomStringConvertible {
// bound." That's sufficient for us to determine if the range contains
// a single value.
let upperBound = expected.first { $0 > lowerBound }
if let upperBound, upperBound > lowerBound && lowerBound == upperBound - 1 {
if upperBound == nil {
return "Confirmation was confirmed \(actual.counting("time")), but expected to be confirmed \(lowerBound.counting("time"))"
}
}
Expand Down
26 changes: 25 additions & 1 deletion Tests/TestingTests/ConfirmationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,36 @@ struct ConfirmationTests {
var configuration = Configuration()
configuration.eventHandler = { event, _ in
if case let .issueRecorded(issue) = event.kind {
#expect(String(describing: issue) != "")
#expect(String(describing: issue).contains("time(s)"))
}
}

await Test {
await confirmation(expectedCount: 1...) { _ in }
await confirmation(expectedCount: 1...2) { _ in }
await confirmation(expectedCount: 1..<3) { _ in }
}.run(configuration: configuration)
}

@Test func confirmationFailureCanBeDescribedAsSingleValue() async {
var configuration = Configuration()
configuration.eventHandler = { event, _ in
if case let .issueRecorded(issue) = event.kind {
#expect(!String(describing: issue).contains("time(s)"))
}
}

await Test {
await confirmation(expectedCount: 1...1) { _ in }
await confirmation(expectedCount: 1..<2) { _ in }
await confirmation(expectedCount: Int.max...Int.max) { _ in }
#if !SWT_NO_EXIT_TESTS
await withKnownIssue("Crashes in Swift standard library (rdar://139568287)") {
await #expect(exitsWith: .success) {
await confirmation(expectedCount: Int.max...) { _ in }
}
}
#endif
}.run(configuration: configuration)
}

Expand Down