Skip to content

Add ability to filter/skip by tags using a special tag: prefix#1531

Open
gmedori wants to merge 4 commits intoswiftlang:mainfrom
gmedori:goose/prefix-based-tag-filtering
Open

Add ability to filter/skip by tags using a special tag: prefix#1531
gmedori wants to merge 4 commits intoswiftlang:mainfrom
gmedori:goose/prefix-based-tag-filtering

Conversation

@gmedori
Copy link

@gmedori gmedori commented Feb 5, 2026

While Xcode has had the ability to filter based on tags, this ability has been missing from the command line. This PR introduces a special prefix you can apply to your --filter and --skip option arguments: tag:.

When prefixing your argument with tag:, rather than treating the following characters as a regular expression, it's treated as a string literal that matches exactly against your test tags. For example, suppose you define a tag in your code as follows.

extension Tag {
  @Tag static var integrationTest: Self
}

If you then add that tag to some suites or tests, you'll be able to run those tests exclusively by running:

swift test --filter tag:integrationTest

Resolves #591

CleanShot.2026-02-05.at.16.21.38.mp4

Modifications:

This PR enhances the nested testFilter function inside of configurationForEntryPoint(from:) function. The testFilter function now:

  • Processes any arguments prefixed with tag: as string literals to be interpreted as tags
  • Handles escaping the tag: prefix with the following syntax: tag\:myRegex to force the entire string to be read as a regex (as it would be normally prior to this change). This allows for filtering on test names that contain tag:.
  • Continues to process regexes as it did before this change, once all the tag-based arguments are processed.

Checklist:

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

@grynspan
Copy link
Contributor

grynspan commented Feb 6, 2026

Holding off on approval because this will also need a Swift Evolution proposal and possibly changes to Swift Package Manager. But in terms of the technical implementation, seems reasonable. :)

var nonTagFilterRegexes: [String] = []
var nonTagSkipRegexes: [String] = []

for var filter in args.filter ?? [] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest adding some more comments in the new code explaining what it's doing.

Copy link
Author

Choose a reason for hiding this comment

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

I added a bunch more comments in eab4679, I think it should be clearer now! Let me know if I've overshot, or if we need more. Still mentally calibrating the right balance 🙂


for var skip in args.skip ?? [] {
if skip.hasPrefix(tagPrefix) {
filters.append(Configuration.TestFilter(includingAnyOf: [Tag(userProvidedStringValue: String(skip.dropFirst(4)))]))
Copy link
Contributor

Choose a reason for hiding this comment

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

As above. Can we combine the code for filter and skip? Looks basically identical?

Copy link
Author

@gmedori gmedori Feb 6, 2026

Choose a reason for hiding this comment

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

I've gone and just made the testFilter nested function more comprehensive to DRY this up. It's a nested function and didn't have any doc comments before, so I left it that way, but let me know if doc comments on it would be beneficial. I think the inline comments are sufficient since it's not a publicly visible symbol and the inline comments do a decent job.

eab4679

@gmedori gmedori force-pushed the goose/prefix-based-tag-filtering branch from eab4679 to 753e7c5 Compare February 13, 2026 01:04
@grynspan grynspan added the traits Issues and PRs related to the trait subsystem or built-in traits label Feb 13, 2026
@grynspan grynspan added this to the Swift 6.4.0 (main) milestone Feb 13, 2026
@grynspan grynspan added enhancement New feature or request tools integration 🛠️ Integration of swift-testing into tools/IDEs swiftpm-integration 📦 Swift Package Manager integration labels Feb 13, 2026
@gmedori
Copy link
Author

gmedori commented Feb 13, 2026

Adding test coverage to this one before I take it out of draft status!

@gmedori gmedori changed the title Add some logic to configurationForEntryPoint(from:) to filter by tags using a special tag: prefix Add ability to filter/skip by tags using a special tag: prefix Feb 13, 2026
@gmedori gmedori force-pushed the goose/prefix-based-tag-filtering branch from 51d6a48 to 162016a Compare February 13, 2026 01:30
@gmedori gmedori marked this pull request as ready for review February 13, 2026 07:11
@gmedori
Copy link
Author

gmedori commented Feb 13, 2026

Just updated with some tests and fleshed out the PR description! The Swift Evolution proposal for this change is currently a WIP. Waiting on some folks to proofread it before I put it up because it's my very first one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request swiftpm-integration 📦 Swift Package Manager integration tools integration 🛠️ Integration of swift-testing into tools/IDEs 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.

Request for the ability to run tests in a Package with a given tag from the command line

2 participants