Skip to content

Commit 8bbef19

Browse files
authored
Remove string literal tags. (#420)
As discussed [in the forums](https://forums.swift.org/t/removal-of-string-literal-tag-definitions/71667), we are removing string literal tags. This PR removes the interfaces for them. It preserves `Tag.Kind` because that may prove to be a useful abstraction in the future, e.g. if we come up with a new kind of tag that isn't a member of `Tag`. Resolves rdar://125730118. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 42fc194 commit 8bbef19

File tree

10 files changed

+49
-115
lines changed

10 files changed

+49
-115
lines changed

Sources/Testing/Testing.docc/AddingTags.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ source files, and even test targets.
2626

2727
## Add a tag
2828

29-
To add a tag to a test, use the ``Trait/tags(_:)-505n9`` trait. This trait takes
30-
a sequence of tags as its argument, and those tags are then applied to the
29+
To add a tag to a test, use the ``Trait/tags(_:)`` trait. This trait takes a
30+
sequence of tags as its argument, and those tags are then applied to the
3131
corresponding test at runtime. If any tags are applied to a test suite, then all
3232
tests in that suite inherit those tags.
3333

Sources/Testing/Testing.docc/DefiningTests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ line, supply a string literal as an argument to the `@Test` attribute:
6565
```
6666

6767
To further customize the appearance and behavior of a test function, use
68-
[traits](doc:Traits) such as ``Trait/tags(_:)-505n9``.
68+
[traits](doc:Traits) such as ``Trait/tags(_:)``.
6969

7070
### Write concurrent or throwing tests
7171

Sources/Testing/Testing.docc/OrganizingTests.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ A test function can be added to a test suite in one of two ways:
2727
The `@Suite` attribute isn't required for the testing library to recognize that
2828
a type contains test functions, but adding it allows customization of a test
2929
suite's appearance in the IDE and at the command line. If a trait such as
30-
``Trait/tags(_:)-505n9`` or ``Trait/disabled(_:fileID:filePath:line:column:)``
31-
is applied to a test suite, it's automatically inherited by the tests contained
32-
in the suite.
30+
``Trait/tags(_:)`` or ``Trait/disabled(_:fileID:filePath:line:column:)`` is
31+
applied to a test suite, it's automatically inherited by the tests contained in
32+
the suite.
3333

3434
In addition to containing test functions and any other members that a Swift type
3535
might contain, test suite types can also contain additional test suites nested
@@ -51,7 +51,7 @@ To customize a test suite's name, supply a string literal as an argument to the
5151
```
5252

5353
To further customize the appearance and behavior of a test function, use
54-
[traits](doc:Traits) such as ``Trait/tags(_:)-505n9``.
54+
[traits](doc:Traits) such as ``Trait/tags(_:)``.
5555

5656
## Test functions in test suite types
5757

Sources/Testing/Testing.docc/Traits/Trait.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors
2626

2727
### Categorizing tests
2828

29-
- ``Trait/tags(_:)-505n9``
30-
- ``Trait/tags(_:)-yg0i``
29+
- ``Trait/tags(_:)``
3130

3231
### Associating bugs
3332

Sources/Testing/Traits/Tags/Tag.List.swift

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
extension Tag {
1212
/// A type representing one or more tags applied to a test.
1313
///
14-
/// To add this trait to a test, use one of the following functions:
15-
///
16-
/// - ``Trait/tags(_:)-505n9``
17-
/// - ``Trait/tags(_:)-yg0i``
14+
/// To add this trait to a test, use the ``Trait/tags(_:)`` function.
1815
public struct List {
1916
/// The list of tags contained in this instance.
2017
///
@@ -66,27 +63,4 @@ extension Trait where Self == Tag.List {
6663
public static func tags(_ tags: Tag...) -> Self {
6764
Self(tags: tags)
6865
}
69-
70-
/// Construct a list of tags to apply to a test from a list of string values.
71-
///
72-
/// - Parameters:
73-
/// - stringValues: The list of string values to convert to tags and apply
74-
/// to the test.
75-
///
76-
/// - Returns: An instance of ``Tag/List`` containing the specified string
77-
/// literals as tags.
78-
///
79-
/// This function is provided as a convenience to allow specifying tags as
80-
/// string values. To specify a mix of tags identified by symbol (such as
81-
/// `.example`) and tags identified by string value (such as `"important"`),
82-
/// use two separate calls to this function and pass symbols separately from
83-
/// string values:
84-
///
85-
/// ```swift
86-
/// @Test("Wheels spin", .tags("mechanical"), .tags(.critical))
87-
/// func wheelsSpin() {}
88-
/// ```
89-
public static func tags(_ stringValues: _const String...) -> Self {
90-
Self(tags: stringValues.map { Tag(kind: .stringLiteral($0)) })
91-
}
9266
}

Sources/Testing/Traits/Tags/Tag.swift

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
/// A type representing a tag that can be applied to a test.
1212
///
13-
/// To apply tags to a test, use one of the following functions:
14-
///
15-
/// - ``Trait/tags(_:)-505n9``
16-
/// - ``Trait/tags(_:)-yg0i``
13+
/// To apply tags to a test, use the ``Trait/tags(_:)`` function.
1714
public struct Tag: Sendable {
1815
/// An enumeration describing the various kinds of tag that can be applied to
1916
/// a test.
@@ -26,12 +23,6 @@ public struct Tag: Sendable {
2623
/// - name: The (almost) fully-qualified name of the static member. The
2724
/// leading `"Testing.Tag."` is not included as it is redundant.
2825
case staticMember(_ name: String)
29-
30-
/// The tag is a string literal declared directly in source.
31-
///
32-
/// - Parameters:
33-
/// - stringLiteral: The string literal specified by the test author.
34-
case stringLiteral(_ stringLiteral: String)
3526
}
3627

3728
/// The kind of this tag.
@@ -51,8 +42,8 @@ public struct Tag: Sendable {
5142
///
5243
/// Use this initializer when a user has provided an arbitrary string and it
5344
/// is necessary to convert it into a tag. A simple heuristic is applied such
54-
/// that the resulting instance may represent a (possibly non-existent) static
55-
/// member of ``Tag`` or may represent a string literal.
45+
/// that the resulting instance will represent a (possibly non-existent)
46+
/// static member of ``Tag``.
5647
@_spi(ForToolsIntegrationOnly)
5748
public init(userProvidedStringValue stringValue: String) {
5849
self.init(_codableStringValue: stringValue)
@@ -66,8 +57,6 @@ extension Tag: CustomStringConvertible {
6657
switch kind {
6758
case let .staticMember(name):
6859
".\(name)"
69-
case let .stringLiteral(stringLiteral):
70-
#""\#(stringLiteral)""#
7160
}
7261
}
7362
}
@@ -79,14 +68,6 @@ extension Tag: Equatable, Hashable, Comparable {
7968
switch (lhs.kind, rhs.kind) {
8069
case let (.staticMember(lhs), .staticMember(rhs)):
8170
lhs < rhs
82-
case let (.stringLiteral(lhs), .stringLiteral(rhs)):
83-
lhs < rhs
84-
85-
// (Arbitrarily) sort static members before string literals.
86-
case (.staticMember, .stringLiteral):
87-
true
88-
case (.stringLiteral, .staticMember):
89-
false
9071
}
9172
}
9273
}
@@ -102,10 +83,8 @@ extension Tag: Codable, CodingKeyRepresentable {
10283
private init(_codableStringValue stringValue: String) {
10384
if stringValue.first == "." {
10485
self.init(kind: .staticMember(String(stringValue.dropFirst())))
105-
} else if stringValue.first == #"\"# {
106-
self.init(kind: .stringLiteral(String(stringValue.dropFirst())))
10786
} else {
108-
self.init(kind: .stringLiteral(stringValue))
87+
self.init(kind: .staticMember(stringValue))
10988
}
11089
}
11190

@@ -119,12 +98,6 @@ extension Tag: Codable, CodingKeyRepresentable {
11998
switch kind {
12099
case let .staticMember(name):
121100
".\(name)"
122-
case let .stringLiteral(stringLiteral):
123-
if stringLiteral.first == "." || stringLiteral.first == #"\"# {
124-
#"\\#(stringLiteral)"#
125-
} else {
126-
stringLiteral
127-
}
128101
}
129102
}
130103

@@ -165,10 +138,7 @@ extension Tag: Codable, CodingKeyRepresentable {
165138
extension Test {
166139
/// The complete, unique set of tags associated with this test.
167140
///
168-
/// Tags are associated with tests using one of the following functions:
169-
///
170-
/// - ``Trait/tags(_:)-505n9``
171-
/// - ``Trait/tags(_:)-yg0i``
141+
/// Tags are associated with tests using the ``Trait/tags(_:)`` function.
172142
public var tags: Set<Tag> {
173143
traits.lazy
174144
.compactMap { $0 as? Tag.List }

Tests/TestingTests/MiscellaneousTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
}
3636

3737
@`Suite`(.hidden) struct `SuiteWithBackticks` {
38-
@`Test`(.hidden, .`tags`("tag")) func `testWithBackticks`() {
38+
@`Test`(.hidden, .`tags`(.namedConstant)) func `testWithBackticks`() {
3939
#`expect`(Bool(true))
4040
}
4141
}
@@ -78,9 +78,9 @@ struct SendableTests: Sendable {
7878
@Test(.hidden, arguments: FixtureData.zeroUpTo100)
7979
static func `reserved1`(`reserved2`: Int) async throws {}
8080

81-
@Suite(.hidden, .tags("tag-1"))
81+
@Suite(.hidden, .tags(.namedConstant))
8282
struct NestedSendableTests: Sendable {
83-
@Test(.hidden, .tags("tag-2"))
83+
@Test(.hidden, .tags(.anotherConstant))
8484
func succeeds() throws {}
8585

8686
@Test(.hidden)

Tests/TestingTests/PlanTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct PlanTests {
116116
]
117117

118118
var configuration = Configuration()
119-
var filter = Configuration.TestFilter(includingAnyOf: [Tag("tag-1"), Tag("tag-2")])
119+
var filter = Configuration.TestFilter(includingAnyOf: [.namedConstant, .anotherConstant])
120120
filter.includeHiddenTests = true
121121
configuration.testFilter = filter
122122

@@ -146,7 +146,7 @@ struct PlanTests {
146146
]
147147

148148
var configuration = Configuration()
149-
var filter = Configuration.TestFilter(includingAllOf: [Tag("tag-1"), Tag("tag-2")])
149+
var filter = Configuration.TestFilter(includingAllOf: [.namedConstant, .anotherConstant])
150150
filter.includeHiddenTests = true
151151
configuration.testFilter = filter
152152

@@ -176,7 +176,7 @@ struct PlanTests {
176176
]
177177

178178
var configuration = Configuration()
179-
var filter = Configuration.TestFilter(excludingAnyOf: [Tag("tag-1"), Tag("tag-2")])
179+
var filter = Configuration.TestFilter(excludingAnyOf: [.namedConstant, .anotherConstant])
180180
filter.includeHiddenTests = true
181181
configuration.testFilter = filter
182182

@@ -206,7 +206,7 @@ struct PlanTests {
206206
]
207207

208208
var configuration = Configuration()
209-
var filter = Configuration.TestFilter(excludingAllOf: [Tag("tag-1"), Tag("tag-2")])
209+
var filter = Configuration.TestFilter(excludingAllOf: [.namedConstant, .anotherConstant])
210210
filter.includeHiddenTests = true
211211
configuration.testFilter = filter
212212

@@ -356,7 +356,7 @@ struct PlanTests {
356356
var configuration = Configuration()
357357
let selection = [testA.id]
358358
var testFilter = Configuration.TestFilter(including: selection)
359-
testFilter.combine(with: .init(includingAnyOf: [Tag("tag-2")]), using: .or)
359+
testFilter.combine(with: .init(includingAnyOf: [.anotherConstant]), using: .or)
360360
testFilter.includeHiddenTests = true
361361
configuration.testFilter = testFilter
362362

Tests/TestingTests/Traits/ParallelizationTraitTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1212

13-
@Suite("Parallelization Trait Tests", .tags("trait"))
13+
@Suite("Parallelization Trait Tests", .tags(.traitRelated))
1414
struct ParallelizationTraitTests {
1515
@Test(".serialized trait is recursively applied")
1616
func serializedTrait() async {

0 commit comments

Comments
 (0)