Skip to content

Conversation

@stmontgomery
Copy link
Contributor

This adjusts the wording of a - Note: in our Defining test functions documentation article which advises that users only import the testing library in test targets. It expands the kinds of supported targets to include "library targets meant for test targets", which is a supported use case.

Motivation:

The wording should not imply that it's never supported to vend a library which extends the testing library. There is an important distinction between libraries which are distributed to end users (e.g. those bundles within apps or alongside executables) vs. libraries intended solely to support test targets or other testing libraries.

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 (main) milestone Aug 28, 2025
@stmontgomery stmontgomery requested a review from iamleeg August 28, 2025 03:21
@stmontgomery stmontgomery self-assigned this Aug 28, 2025
@stmontgomery stmontgomery added documentation 📚 Improvements or additions to documentation enhancement New feature or request labels Aug 28, 2025
testing library into an application, library, or binary target isn't
- Note: Only import the testing library into a test target or library meant for
test targets. Importing the testing library into a target intended for
distribution such as an application, app library, or executable target isn't
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to suggestions for better phrasing @iamleeg, but I hope my intent is clear!

Copy link
Contributor

@iamleeg iamleeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!


- Note: Only import the testing library into a test target. Importing the
testing library into an application, library, or binary target isn't
- Note: Only import the testing library into a test target or library meant for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nit: would it be clearer to say "library used only in test targets"? I can see the original wording as being interpreted overly broadly (e.g. some sort of utils used in both an executable and test library)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you're going for there. I worded it this way to keep it slightly more open because it's also supported (though less common) to have one test-only library which is used exclusively by another test-only library which in turn is used by exclusively by test targets. So the guidance is really "keep the transitive closure of these libraries confined to testing contexts". It's just that I'd like this doc phrasing to read naturally. So I felt "meant for test targets" captured that well enough, without excluding that use case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This for example is valid in a library if you are building from source:

#if canImport(Testing)
public func foo(_ test: Test) {
  ...
}
#endif

@stmontgomery stmontgomery merged commit b731280 into swiftlang:main Aug 28, 2025
@stmontgomery stmontgomery deleted the defining-tests-note branch August 28, 2025 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation 📚 Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants