-
Notifications
You must be signed in to change notification settings - Fork 104
Diagnose when using a non-escapable type as suite. #988
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This PR enables using non-escapable types as suites. For example: ```swift @suite struct NumberOfBeesTests: ~Escapable { @test borrowing func countBees() { ... } } ``` Non-escapable types have a number of constraints in Swift, and those constraints aren't lifted in a test target, but generally speaking a non-escapable type should be able to do all the things any other type can do _as a test suite_.
@swift-ci test |
@swift-ci test |
@swift-ci test |
stmontgomery
approved these changes
Mar 3, 2025
grynspan
added a commit
that referenced
this pull request
Mar 3, 2025
This PR introduces a custom compile-time diagnostic when attempting to use a non-escapable type as a suite. For example: ```swift @suite struct NumberOfBeesTests: ~Escapable { @test borrowing func countBees() { ... } // 🛑 Attribute 'Test' cannot be applied to a function within structure 'NumberOfBeesTests' because its conformance to 'Escapable' has been suppressed } ``` Values with non-escapable type cannot currently be initialized nor returned from a function, and we need to be able to do both in order to correctly implement the `@Test` macro. This change does not diagnose if `@Suite` is applied to such a type but does not contain any test functions, because we do compile successfully in that case and this sort of pattern remains valid: ```swift @suite struct MyTests: ~Escapable { @suite struct EndToEndTests { ... } } ``` ### 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.
grynspan
added a commit
that referenced
this pull request
Mar 3, 2025
- **Explanation**: Presents a custom diagnostic if you try to put a test function in a non-escapable type since that's not supported by the language yet. - **Scope**: Tests in non-escapable types. - **Issues**: N/A - **Original PRs**: #988 - **Risk**: Low (shouldn't be any code out there doing this since it doesn't compile.) - **Testing**: Unit test coverage is in place. - **Reviewers**: @briancroom @stmontgomery
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a custom compile-time diagnostic when attempting to use a non-escapable type as a suite. For example:
Values with non-escapable type cannot currently be initialized nor returned from a function, and we need to be able to do both in order to correctly implement the
@Test
macro.This change does not diagnose if
@Suite
is applied to such a type but does not contain any test functions, because we do compile successfully in that case and this sort of pattern remains valid:Checklist: