Skip to content

Introduce 'MarkerTrait' to unify the representation of boolean test attributes #1123

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

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

Conversation

stmontgomery
Copy link
Contributor

This introduces a utility type named MarkerTrait which acts as a generic "marker" trait representing a boolean attribute of a test, and uses it to replace the .hidden trait and Test.isSynthesized property.

Motivation:

Currently the testing library has an internal-only trait named .hidden, of type HiddenTrait, which is used in the project's own unit tests to represent fixture/example tests and suites. Separately, it also has a stored, boolean property on Test named isSynthesized which is meant for debugging purposes to keep track of suites which were synthesized during planning and didn't have a @Suite attribute.

Conceptually, both of these can be thought of as boolean attributes of a test/suite. A given Test instance is either hidden or not, and either synthesized or not. There's an opportunity to simplify the modeling by representing them both as a trait, which would make adding future boolean test attributes more straightforward. Plus, for isSynthesized specifically, doing this would eliminate a stored property on every Test instance.

Modifications:

  • Add MarkerTrait type and use it reimplement .hidden.
  • Remove the Test.isSynthesized stored property and replace it with a new .synthesized marker trait.
  • Only include the synthesized trait in debug builds (guarded by #if DEBUG) to avoid needless overhead in release builds where this information isn't used.
  • Add a Test.containsTrait() utility function for checking whether a test contains some (equatable) trait.

Checklist:

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

@stmontgomery stmontgomery added this to the Swift 6.x milestone May 22, 2025
@stmontgomery stmontgomery self-assigned this May 22, 2025
@stmontgomery stmontgomery added the enhancement New feature or request label May 22, 2025
@stmontgomery stmontgomery added the performance 🏎️ Performance issues label May 22, 2025
@stmontgomery stmontgomery added the traits Issues and PRs related to the trait subsystem or built-in traits label May 22, 2025
@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@grynspan
Copy link
Contributor

I see where you're going with this, but it may make it harder to support Embedded Swift by relying even more on existentials.

There is also a performance cost to this change that we should be careful to measure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance 🏎️ Performance issues traits Issues and PRs related to the trait subsystem or built-in traits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants