Skip to content

Commit 6fd3dd7

Browse files
authored
Remove Bug.Relationship. (#394)
This PR removes the `Bug.Relationship` type and corresponding `relationship` property and accoutrements. We had planned to expose this information so that developers could provide finer-grained metadata about related bugs that could be surfaced in `swift test` or IDEs like VSCode. In practice, we've struggled to figure out how this information could actually be used: a tool like `swift test` doesn't have write access to a developer's bug tracking software, so it couldn't go update a bug with a comment saying "this issue has started occurring again" or something like that. We are interested in re-exposing this API or something similar in the future, but for our initial release we are removing it. ### 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 d7b0f0e commit 6fd3dd7

File tree

9 files changed

+25
-137
lines changed

9 files changed

+25
-137
lines changed

Sources/Testing/Testing.docc/AssociatingBugs.md

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ specific bugs with tests that reproduce them or verify they are fixed.
2525

2626
## Associate a bug with a test
2727

28-
To associate a bug with a test, use the ``Trait/bug(_:relationship:_:)-86mmm``
29-
or ``Trait/bug(_:relationship:_:)-3hsi5`` function. The first argument to this
30-
function is the bug's _identifier_ in its bug-tracking system:
28+
To associate a bug with a test, use the ``Trait/bug(_:_:)-2u8j9`` or
29+
``Trait/bug(_:_:)-7mo2w`` function. The first argument to this function is the
30+
bug's _identifier_ in its bug-tracking system:
3131

3232
```swift
3333
@Test("Food truck engine works", .bug("12345"), .bug(67890))
@@ -43,54 +43,12 @@ specified as a string, it must be parseable as an unsigned integer or as a URL.
4343
For more information on the formats recognized by the testing library, see
4444
<doc:BugIdentifiers>.
4545

46-
## Specify the relationship between a bug and a test
47-
48-
By default, the nature of the relationship between a bug and a test is
49-
unspecified. All the testing library knows about such relationships is that they
50-
exist.
51-
52-
It is possible to customize the relationship between a bug and a test. Doing so
53-
allows the testing library to make certain assumptions, such as that a test is
54-
expected to fail, or that a failure indicates a regression that requires
55-
attention from a developer.
56-
57-
To specify how a bug is related to a test, use the `relationship` parameter of
58-
the ``Trait/bug(_:relationship:_:)-86mmm`` or
59-
``Trait/bug(_:relationship:_:)-3hsi5`` function. For example, to indicate that a
60-
test was written to verify a previously-fixed bug, one would specify
61-
`.verifiesFix`:
62-
63-
```swift
64-
@Test("Food truck engine works", .bug("12345", relationship: .verifiesFix))
65-
func engineWorks() async {
66-
var foodTruck = FoodTruck()
67-
await foodTruck.engine.start()
68-
#expect(foodTruck.engine.isRunning)
69-
}
70-
```
71-
72-
### Kinds of relationship
73-
74-
The testing library defines several kinds of common bug/test relationship:
75-
76-
| Relationship | Use when… |
77-
|-|-|
78-
| `.uncoveredBug` | … a test run failed, uncovering the bug in question. |
79-
| `.reproducesBug` | … a bug was previously filed and the test was written to demonstrate it. |
80-
| `.verifiesFix` | … a bug has been fixed and the test shows that it no longer reproduces. |
81-
| `.failingBecauseOfBug` | … a test was previously passing, but now an unrelated bug is causing it to fail. |
82-
| `.unspecified` | … no other case accurately describes the relationship. |
83-
84-
<!-- Keep `.unspecified` as the last row above in order to imply it is a
85-
fallback. -->
86-
87-
## Adding comments to associated bugs
46+
## Add comments to associated bugs
8847

8948
A bug identifier may be insufficient to uniquely and clearly identify a bug
9049
associated with a test. Bug trackers universally provide a "title" field for
9150
bugs that is not visible to the testing library. To add a bug's title to a test,
92-
include it after the bug's identifier and (optionally) its relationship to the
93-
test:
51+
include it after the bug's identifier:
9452

9553
```swift
9654
@Test(

Sources/Testing/Testing.docc/EnablingAndDisabling.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,15 @@ func isCold() async throws { ... }
8383
```
8484

8585
If a test is disabled because of a problem for which there is a corresponding
86-
bug report, you can use the ``Trait/bug(_:relationship:_:)-86mmm`` or
87-
``Trait/bug(_:relationship:_:)-3hsi5`` function with the relationship
88-
``Bug/Relationship-swift.enum/failingBecauseOfBug``:
86+
bug report, you can use the ``Trait/bug(_:_:)-2u8j9`` or
87+
``Trait/bug(_:_:)-7mo2w`` function to show the relationship:
8988

9089
```swift
9190
@Test(
9291
"Ice cream is cold",
9392
.enabled(if: Season.current == .summer),
9493
.disabled("We ran out of sprinkles"),
95-
.bug("#12345", relationship: .failingBecauseOfBug)
94+
.bug("12345")
9695
)
9796
func isCold() async throws { ... }
9897
```

Sources/Testing/Testing.docc/Traits.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ HIDDEN: .serialized is experimental SPI pending feature review.
4646
- <doc:AssociatingBugs>
4747
- <doc:BugIdentifiers>
4848
- ``Tag()``
49-
- ``Trait/bug(_:relationship:_:)-86mmm``
50-
- ``Trait/bug(_:relationship:_:)-3hsi5``
49+
- ``Trait/bug(_:_:)-2u8j9``
50+
- ``Trait/bug(_:_:)-7mo2w``
5151

5252
### Creating custom traits
5353

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors
3131

3232
### Associating bugs
3333

34-
- ``Trait/bug(_:relationship:_:)-86mmm``
35-
- ``Trait/bug(_:relationship:_:)-3hsi5``
34+
- ``Trait/bug(_:_:)-2u8j9``
35+
- ``Trait/bug(_:_:)-7mo2w``
3636

3737
### Adding information to tests
3838
- ``Trait/comments``

Sources/Testing/Traits/Bug.swift

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,15 @@
1212
///
1313
/// To add this trait to a test, use one of the following functions:
1414
///
15-
/// - ``Trait/bug(_:relationship:_:)-86mmm``
16-
/// - ``Trait/bug(_:relationship:_:)-3hsi5``
15+
/// - ``Trait/bug(_:_:)-86mmm``
16+
/// - ``Trait/bug(_:_:)-3hsi5``
1717
public struct Bug {
1818
/// The identifier of this bug in the associated bug-tracking system.
1919
///
2020
/// For more information on how the testing library interprets bug
2121
/// identifiers, see <doc:BugIdentifiers>.
2222
public var identifier: String
2323

24-
/// An enumeration describing the relationship of a bug to a test.
25-
///
26-
/// For more information on how the testing library uses bug relationships,
27-
/// see <doc:AssociatingBugs>.
28-
public enum Relationship: Sendable {
29-
/// The relationship between the test and this bug is unspecified.
30-
///
31-
/// Use this relationship to describe a bug that is related to a test, but
32-
/// not in any specific way.
33-
case unspecified
34-
35-
/// The test uncovered this bug.
36-
///
37-
/// Use this relationship to describe a bug that was filed as a result of a
38-
/// test failing.
39-
case uncoveredBug
40-
41-
/// The test reproduces the bug.
42-
///
43-
/// Use this relationship to describe a bug that the test is able to
44-
/// reproduce consistently.
45-
case reproducesBug
46-
47-
/// The test verifies that the bug has been fixed.
48-
///
49-
/// Use this relationship when the associated test is meant to verify that
50-
/// the bug has been fixed.
51-
case verifiesFix
52-
53-
/// The test is failing because of the bug.
54-
///
55-
/// Use this relationship when the associated test is not directly related
56-
/// to the bug, but is failing because the bug has not been fixed yet.
57-
case failingBecauseOfBug
58-
}
59-
60-
/// The relationship between the bug and the associated test.
61-
///
62-
/// For more information on how the testing library uses bug relationships,
63-
/// see <doc:AssociatingBugs>.
64-
public var relationship: Relationship
65-
6624
/// An optional, user-specified comment describing this trait.
6725
public var comment: Comment?
6826
}
@@ -83,12 +41,9 @@ extension Bug: Equatable, Hashable, Comparable {
8341
}
8442
}
8543

86-
extension Bug.Relationship: Equatable, Hashable {}
87-
8844
// MARK: - Codable
8945

9046
extension Bug: Codable {}
91-
extension Bug.Relationship: Codable {}
9247

9348
// MARK: - Trait, TestTrait, SuiteTrait
9449

@@ -105,14 +60,11 @@ extension Trait where Self == Bug {
10560
/// - identifier: The identifier of this bug in the associated bug-tracking
10661
/// system. For more information on how this value is interpreted, see the
10762
/// documentation for ``Bug``.
108-
/// - relationship: The relationship between the bug and the associated
109-
/// test. The default value is
110-
/// ``Bug/Relationship-swift.enum/unspecified``.
11163
/// - comment: An optional, user-specified comment describing this trait.
11264
///
11365
/// - Returns: An instance of ``Bug`` representing the specified bug.
114-
public static func bug(_ identifier: String, relationship: Bug.Relationship = .unspecified, _ comment: Comment? = nil) -> Self {
115-
Self(identifier: identifier, relationship: relationship, comment: comment)
66+
public static func bug(_ identifier: String, _ comment: Comment? = nil) -> Self {
67+
Self(identifier: identifier, comment: comment)
11668
}
11769

11870
/// Construct a bug to track with a test.
@@ -121,14 +73,11 @@ extension Trait where Self == Bug {
12173
/// - identifier: The identifier of this bug in the associated bug-tracking
12274
/// system. For more information on how this value is interpreted, see the
12375
/// documentation for ``Bug``.
124-
/// - relationship: The relationship between the bug and the associated
125-
/// test. The default value is
126-
/// ``Bug/Relationship-swift.enum/unspecified``.
12776
/// - comment: An optional, user-specified comment describing this trait.
12877
///
12978
/// - Returns: An instance of ``Bug`` representing the specified bug.
130-
public static func bug(_ identifier: some Numeric, relationship: Bug.Relationship = .unspecified, _ comment: Comment? = nil) -> Self {
131-
Self(identifier: String(describing: identifier), relationship: relationship, comment: comment)
79+
public static func bug(_ identifier: some Numeric, _ comment: Comment? = nil) -> Self {
80+
Self(identifier: String(describing: identifier), comment: comment)
13281
}
13382
}
13483

Sources/Testing/Traits/Comment.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
/// or `@Suite` attribute. See <doc:AddingComments> for more details.
1919
///
2020
/// - Note: This type is not intended to reference bugs related to a test.
21-
/// Instead, use ``Trait/bug(_:relationship:_:)-86mmm`` or
22-
/// ``Trait/bug(_:relationship:_:)-3hsi5``.
21+
/// Instead, use ``Trait/bug(_:_:)-2u8j9`` or ``Trait/bug(_:_:)-7mo2w``.
2322
public struct Comment: RawRepresentable, Sendable {
2423
/// The single comment string contained in this instance.
2524
///
@@ -122,8 +121,7 @@ extension Trait where Self == Comment {
122121
/// comment.
123122
///
124123
/// - Note: This function is not intended to reference bugs related to a test.
125-
/// Instead, use ``Trait/bug(_:relationship:_:)-86mmm`` or
126-
/// ``Trait/bug(_:relationship:_:)-3hsi5``.
124+
/// Instead, use ``Trait/bug(_:_:)-2u8j9`` or ``Trait/bug(_:_:)-7mo2w``.
127125
public static func comment(_ comment: String) -> Self {
128126
Self(rawValue: comment, kind: .trait)
129127
}

Tests/TestingTests/EventRecorderTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ struct EventRecorderTests {
282282

283283
@Test(
284284
"JUnitXMLRecorder outputs valid XML",
285-
.bug("https://github.com/apple/swift-testing/issues/254", relationship: .verifiesFix)
285+
.bug("https://github.com/apple/swift-testing/issues/254")
286286
)
287287
func junitXMLIsValid() async throws {
288288
let stream = Stream()

Tests/TestingTests/Test.SnapshotTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct Test_SnapshotTests {
9494
#expect(snapshot.associatedBugs.first == Self.bug)
9595
}
9696

97-
private static let bug: Bug = Bug.bug(12345, relationship: .failingBecauseOfBug, "Lorem ipsum")
97+
private static let bug: Bug = Bug.bug(12345, "Lorem ipsum")
9898

9999
@available(_clockAPI, *)
100100
@Test("timeLimit property", .timeLimit(duration))

Tests/TestingTests/Traits/BugTests.swift

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct BugTests {
5757

5858
@Test("Test.associatedBugs property")
5959
func testAssociatedBugsProperty() {
60-
let test = Test(.bug(12345), .disabled(), .bug(67890), .bug(24680, relationship: .uncoveredBug), .bug(54321, relationship: .verifiesFix)) {}
60+
let test = Test(.bug(12345), .disabled(), .bug(67890), .bug(24680), .bug(54321)) {}
6161
let bugIdentifiers = test.associatedBugs
6262
#expect(bugIdentifiers.count == 4)
6363
#expect(bugIdentifiers[0].identifier == "12345")
@@ -66,32 +66,16 @@ struct BugTests {
6666
#expect(bugIdentifiers[3].identifier == "54321")
6767
}
6868

69-
@Test(".bug() with String and relationship")
70-
func bugWithStringAndRelationship() {
71-
let trait = Bug.bug("12345", relationship: .uncoveredBug)
72-
#expect((trait as Any) is Bug)
73-
#expect(trait.identifier == "12345")
74-
#expect(trait.relationship == .uncoveredBug)
75-
}
76-
77-
@Test(".bug() with number and relationship")
78-
func bugWithNumericAndRelationship() {
79-
let trait = Bug.bug(67890, relationship: .uncoveredBug)
80-
#expect((trait as Any) is Bug)
81-
#expect(trait.identifier == "67890")
82-
#expect(trait.relationship == .uncoveredBug)
83-
}
84-
8569
@Test("Bug hashing")
8670
func hashing() {
87-
let traits: Set<Bug> = [.bug(12345), .bug(12345), .bug(12345, relationship: .uncoveredBug), .bug("67890")]
71+
let traits: Set<Bug> = [.bug(12345), .bug(12345), .bug(12345), .bug("67890")]
8872
#expect(traits.count == 2)
8973
}
9074

9175
#if canImport(Foundation)
9276
@Test("Encoding/decoding")
9377
func encodingAndDecoding() throws {
94-
let original = Bug.bug(12345, relationship: .failingBecauseOfBug, "Lorem ipsum")
78+
let original = Bug.bug(12345, "Lorem ipsum")
9579
let copy = try JSON.encodeAndDecode(original)
9680
#expect(original == copy)
9781
}

0 commit comments

Comments
 (0)