Skip to content

[ST-NNNN] Tag-based test execution filtering#3239

Open
gmedori wants to merge 4 commits intoswiftlang:mainfrom
gmedori:tag-based-test-execution-filtering-proposal
Open

[ST-NNNN] Tag-based test execution filtering#3239
gmedori wants to merge 4 commits intoswiftlang:mainfrom
gmedori:tag-based-test-execution-filtering-proposal

Conversation

@gmedori
Copy link
Copy Markdown

@gmedori gmedori commented Apr 13, 2026

For convenience, here's a link to the implementation of the feature described in this proposal: swiftlang/swift-testing#1531


## Future Directions

N/A
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider whether there are other aspects of tests on which devs may want to filter?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah fair point! I actually wrote this a little while ago to address an open github issue and am just putting up the PR now, and I didn't stop to think about future directions. Lemme give it a little thought.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added some thoughts in 61e2f4b


The example above would behave as though the string `tag:uiTest` were passed as a regular expression, omitting the escaping backslash in the final regular expression.

> **Note**: Most shells treat the backslash character `\` as a special character used for escaping. In order for the application to receive it, the argument needs to either be wrapped in quotes like `'tag\:uiTest'`, or the backslash itself needs to be escaped, `tag\\:uiTest`.
Copy link
Copy Markdown
Contributor

@grynspan grynspan Apr 13, 2026

Choose a reason for hiding this comment

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

Should we just make it a policy that \ escapes the next character? If not, consider adding some discussion in this area to Alternatives Considered.

Or, if that's impractical or undesirable, should we document how to write \: verbatim (i.e. we probably also need to allow escaping \ itself)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Personally I think that if we want to make that a policy, the policy should exist at SPM level for every command. I'm not sure it's useful to have a policy that only applies to swift testing. Probably skews impractical IMO. Think this is something we want to pursue anyway?

Or, if that's impractical or undesirable, should we document how to write : verbatim (i.e. we probably also need to allow escaping \ itself)?

Do you mean in the usage description of the --skip and --filter options?


## Integration with Supporting Tools

If a codebase has test functions or suites that contain the string `tag:`, then any filtering/skipping arguments that begin with `tag:` behave differently with this proposal. They are treated as tags rather than regular expressions.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This discussion might belong in Source Compatibility rather than this section because it doesn't really affect e.g. VS Code or Xcode integrations.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah I read through that last night and think I agree.

Copy link
Copy Markdown
Author

@gmedori gmedori Apr 13, 2026

Choose a reason for hiding this comment

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

I moved this discussion to Source Compatibility and added some clearer thoughts around tool integrations in 9005487


### Handling Raw Identifiers

As of [SE-0451](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0451-escaped-identifiers.md), Swift has raw identifiers which means the following is valid Swift:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should also consider what needs to happen (if anything different) if the tag itself is a raw identifier (unless anything else in Swift Testing prohibits that, which I don't know off the top of my head):

@Test(.tags(.`some tag with spaces`))
func `my test`() { ... }

I think I would expect to write swift test --skip 'tag:some tag with spaces' here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Then there's an open question about whether or not developers should specify backticks (which also affect shell processing).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ha, yep that complicates things. I think the most correct answer here is to write it as @allevato put it. Involving backticks opens the command up to different interpretations in different shells, where as single-quoting is relatively universal, even going back to shells like sh and csh.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added some more discussion around this scenario in 9005487

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a parallel, when using raw identifiers in the -module-alias or -module-abi-name command line flags of the compiler, you don't need to include the backticks: you'd write -module-abi-name 'foo bar', not -module-abi-name '`foo bar`'. So I think it's reasonable to have the same policy here.

In other words, the backticks are required to delimit the identifier in source code (and they also appear in the mangling of the symbol for compatibility reasons), but it's reasonable to drop them elsewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't have an opinion either way, but we should be clear about it. (And if the developer does type the backticks, does that make it wrong?)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants