[Pitch] List Swift Testing tags with swift test list --tags

Hello everyone,

swift test --filter tag:<name> can already run Swift Testing tests by tag, but there is no way to see which tags a package uses. I'd like to propose swift test list --tags, which prints the unique tags used by a package's Swift Testing tests. The full proposal is below.

Original issue: Add support for listing all test tags · Issue #8889 · swiftlang/swift-package-manager · GitHub
Implementation (prototype): Add `--tags` option to list Swift Testing tags by letsgobjones · Pull Request #10563 · swiftlang/swift-package-manager · GitHub
Related: tag filtering in Swift Testing, Add ability to filter/skip by tags using a special `tag:` prefix by gmedori · Pull Request #1531 · swiftlang/swift-testing · GitHub

I'd especially like feedback on:

  1. Should this list only the tags (--tags), tests together with their tags (--include-tags), or both?
  2. Is --tags the right flag name?
  3. Is it correct to show a suite's tags on the suite and not on the tests inside it?
  4. If you work in a package with many tags, how do you find them today?

P.S. This is my first pitch. I'm part of the Swift Mentorship Program for 2026, and I'm grateful for my mentor's guidance. I'd also love to try this on real packages, so if you have one that uses a lot of tags, please share it here.


List Swift Testing Tags

Introduction

swift test can run Swift Testing tests by tag, but it cannot show which tags a package uses. This proposal adds swift test list --tags, which prints the unique tags used by a package's Swift Testing tests.

Motivation

Swift Testing lets you attach tags to tests and suites:

extension Tag {
    @Tag static var slow: Self
}

@Test(.tags(.slow)) func importLargeFile() { ... }

swift test --filter tag:slow then runs only the tests with that tag. Using this requires knowing which tags exist. Today, swift test list prints test names only, so the only way to discover the tags of an unfamiliar package is to read its test sources. In a large package, where tags are declared in one place and applied in many, this is slow.

Proposed solution

Add a --tags flag to swift test list. It prints the unique tags used by the package's Swift Testing tests, sorted, one per line:

$ swift test list --tags
integration
slow
smoke

swift test list without --tags is unchanged.

Detailed design

Command line

swift test list --tags is a new Boolean flag on the existing list subcommand.

How tags are found

SwiftPM already runs each Swift Testing test product with --list-tests. With --tags, it also passes --event-stream-output-path with a temporary file, one file per test product, because each test binary truncates its output file.

The event stream contains a record of kind test for every discovered test and suite. Since Swift 6.4, these records include a tags field. SwiftPM reads the tags of every test record, combines them across all test products, removes duplicates, sorts them, and prints them. The temporary files are removed afterwards. No change to Swift Testing is required.

Behavior

  • A suite's tags appear on the suite's record and are listed as written. They are not copied onto the tests inside the suite.
  • XCTest has no tags, so XCTest tests are skipped.
  • If there are no tests, no tags, or the toolchain's Swift Testing does not report tags, the command prints nothing and exits successfully. This matches swift test list for a package with no tests.

Security

The command runs the same test binaries that swift test list already runs, and writes temporary files that are removed afterwards. There is no other impact on security, safety, or privacy.

Impact on existing packages

None. This is a new opt-in flag, and existing commands are unchanged.

Alternatives considered

A different flag name

--list-tags is an alternative. It repeats the word "list" that is already in swift test list, so this proposal uses --tags.

Listing tests together with their tags

A different design would list each test along with its tags, using a flag such as --include-tags. One possible format, for discussion only:

$ swift test list --include-tags
MyTests.SuiteA/one()    slow
MyTests.three()         slow, smoke
MyTests.untagged()

This answers a different question ("which tests have this tag?"). It also raises design questions that this proposal does not try to settle: whether a test should be shown with its suite's tags, and what machine-readable format scripts should consume. It is left to the community to decide whether it should be added, or added instead of --tags.

Future directions

If tests and tags are listed together, a --format option (for example --format json) would give scripts a stable, machine-readable output.

1 Like

I replied to your GitHub PR. We will want a PR on Swift Testing that does the enumeration; a change in SwiftPM can then be made that is minimal (just adds the flag to forward.)

Please also open a PR in the swift-evolution repo containing your .md file based on the Swift Testing proposal template. (If you have done so already, please add a link to it here.)

Thanks!

Thanks, @grynspan. That makes sense, and it matches how swift test list
already works for Swift Testing, so I'll rework this so that Swift Testing does
the enumeration and SwiftPM only forwards the flag.

Two questions so I get the shape right:

  1. On the Swift Testing side, would you like --list-tests to accept
    --include-tags and print each test with its tags, as you suggested? Or
    should there also be a mode that prints only the unique tags?
  2. I'll move the proposal to the Swift Testing template and open a PR against
    swift-evolution under proposals/testing/. Should it be a draft PR until
    the design settles?

I'll drop --format, since as you say, including tags is separate from the
output format. I'll post the swift-evolution PR link here once it's up.

I don't think a separate tags-only output is valuable here for humans to read, and automated systems can already consume the JSON output. But it is up to you to make the case for whatever you propose.

The Testing Workgroup is likely going to ignore a draft proposal on the assumption you're not ready for us to review it. Whether or not your PR is a draft should therefore depend on whether or not you consider it ready for review.

I would strongly recommend you do not use an LLM to author your entire proposal, by the way. The LLM will excel at describing the implementation details of your PRs, but those are not important to the proposal process. We want to know why you're proposing a change, the public interface of the change, and how the proposed change will benefit the Swift ecosystem.

1 Like

Understood.

When I resubmit I will describe how it will benefit the Swift community and ecosystem in more detail. I thought it had to be more "technical", so my apologies on that.

I appreciate the feedback.
And thank you for answering my other questions too. :folded_hands:

1 Like

I definitely think the feature is worthwhile overall. IMO it should support both listing the unique tags standalone and listing the tags associated with each test. The former could be via a new subcommand like swift test list tags, and for the latter, I like the --include-tags flag on swift test list that you suggested in the Alternatives Considered. I think it would make the proposal more well-rounded to cover both use cases.

I agree with @grynspan that the implementation of this feature should involve Swift Testing, and it would likely be more efficient to expose specific hooks for querying this info.

1 Like

Hi @letsgobjones

Thanks for drafting this proposal!

My main question is: how/where would you use this information in this format? What use cases are you looking at?