Skip to content

Fix a crash when describing a confirmation failure with a range. #806

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 1 commit into from
Nov 4, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Nov 4, 2024

I was using relative(to:) to convert any arbitrary RangeExpression to one with an upper and lower bound, but that function may produce invalid ranges for expressions like 1... that cause crashes.

This PR switches to a different, somewhat sillier implementation that should not run into this issue.

Resolves #805.
Resolves rdar://139222774.

Checklist:

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

I was using `relative(to:)` to convert any arbitrary `RangeExpression` to one
with an upper and lower bound, but that function may produce invalid ranges for
expressions like `1...` that cause crashes.

This PR switches to a different, somewhat sillier implementation that should not
run into this issue.

Resolves #805.
@grynspan grynspan added the bug 🪲 Something isn't working label Nov 4, 2024
@grynspan grynspan added this to the Swift 6.1 milestone Nov 4, 2024
@grynspan grynspan self-assigned this Nov 4, 2024
@grynspan
Copy link
Contributor Author

grynspan commented Nov 4, 2024

@swift-ci test

@grynspan grynspan merged commit 8cb653d into main Nov 4, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/805-crash-describing-range branch November 4, 2024 22:04
grynspan added a commit that referenced this pull request Nov 11, 2024
My previous fix, #806, had the wrong logic to determine if a
confirmation's expected count as-a-`RangeExpression` had exactly one
value, so we were printing sub-optimal messages on test failures.
Specifically, this:

```swift
await confirmation(expectedCount: 1) { // transformed to 1...1
  // fail to confirm
}
```

Would report "1...1 time(s)" instead of "1 time".

### 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when a call to confirmation(expectedCount: 1...) { ... } fails
3 participants