|
12 | 12 | ///
|
13 | 13 | /// To add this trait to a test, use one of the following functions:
|
14 | 14 | ///
|
15 |
| -/// - ``Trait/bug(_:_:)-2u8j9`` |
16 |
| -/// - ``Trait/bug(_:_:)-7mo2w`` |
| 15 | +/// - ``Trait/bug(_:_:)`` |
| 16 | +/// - ``Trait/bug(_:id:_:)-10yf5`` |
| 17 | +/// - ``Trait/bug(_:id:_:)-3vtpl`` |
17 | 18 | public struct Bug {
|
18 |
| - /// The identifier of this bug in the associated bug-tracking system. |
| 19 | + /// A URL linking to more information about the bug, if available. |
| 20 | + /// |
| 21 | + /// The value of this property represents a URL conforming to |
| 22 | + /// [RFC 3986](https://www.ietf.org/rfc/rfc3986.txt). |
| 23 | + public var url: String? |
| 24 | + |
| 25 | + /// A unique identifier in this bug's associated bug-tracking system, if |
| 26 | + /// available. |
19 | 27 | ///
|
20 | 28 | /// For more information on how the testing library interprets bug
|
21 | 29 | /// identifiers, see <doc:BugIdentifiers>.
|
22 |
| - public var identifier: String |
| 30 | + public var id: String? |
23 | 31 |
|
24 |
| - /// An optional, user-specified comment describing this trait. |
25 |
| - public var comment: Comment? |
| 32 | + /// The human-readable title of the bug, if specified by the test author. |
| 33 | + public var title: Comment? |
26 | 34 | }
|
27 | 35 |
|
28 |
| -// MARK: - Equatable, Hashable, Comparable |
| 36 | +// MARK: - Equatable, Hashable |
29 | 37 |
|
30 |
| -extension Bug: Equatable, Hashable, Comparable { |
| 38 | +extension Bug: Equatable, Hashable { |
31 | 39 | public static func ==(lhs: Self, rhs: Self) -> Bool {
|
32 |
| - lhs.identifier == rhs.identifier |
| 40 | + lhs.url == rhs.url && lhs.id == rhs.id |
33 | 41 | }
|
34 | 42 |
|
35 | 43 | public func hash(into hasher: inout Hasher) {
|
36 |
| - hasher.combine(identifier) |
37 |
| - } |
38 |
| - |
39 |
| - public static func <(lhs: Self, rhs: Self) -> Bool { |
40 |
| - lhs.identifier < rhs.identifier |
| 44 | + hasher.combine(url) |
| 45 | + hasher.combine(id) |
41 | 46 | }
|
42 | 47 | }
|
43 | 48 |
|
44 | 49 | // MARK: - Codable
|
45 | 50 |
|
46 |
| -extension Bug: Codable { |
47 |
| - /// A temporary explicit implementation of this type's coding keys enumeration |
48 |
| - /// to support the refactored form of `Bug` from [#412](https://github.com/apple/swift-testing/pull/412). |
49 |
| - private enum _CodingKeys: String, CodingKey { |
50 |
| - // Existing properties. |
51 |
| - case identifier = "identifier" |
52 |
| - case comment = "comment" |
53 |
| - |
54 |
| - // Proposed new properties. |
55 |
| - case id = "id" |
56 |
| - case url = "url" |
57 |
| - case title = "title" |
58 |
| - } |
59 |
| - |
60 |
| - public func encode(to encoder: any Encoder) throws { |
61 |
| - var container = encoder.container(keyedBy: _CodingKeys.self) |
62 |
| - |
63 |
| - try container.encode(identifier, forKey: .identifier) |
64 |
| - try container.encodeIfPresent(comment, forKey: .comment) |
65 |
| - |
66 |
| - // Temporary compatibility shims to support the refactored form of Bug from |
67 |
| - // https://github.com/apple/swift-testing/pull/412 . |
68 |
| - if identifier.contains(":") { |
69 |
| - try container.encode(identifier, forKey: .url) |
70 |
| - } else { |
71 |
| - try container.encode(identifier, forKey: .id) |
72 |
| - } |
73 |
| - try container.encodeIfPresent(comment, forKey: .title) |
74 |
| - } |
75 |
| - |
76 |
| - public init(from decoder: any Decoder) throws { |
77 |
| - let container = try decoder.container(keyedBy: _CodingKeys.self) |
78 |
| - identifier = try container.decodeIfPresent(String.self, forKey: .identifier) |
79 |
| - // Temporary compatibility shims to support the refactored form of Bug |
80 |
| - // from https://github.com/apple/swift-testing/pull/412 . |
81 |
| - ?? container.decodeIfPresent(String.self, forKey: .id) |
82 |
| - ?? container.decode(String.self, forKey: .url) |
83 |
| - comment = try container.decodeIfPresent(Comment.self, forKey: .comment) |
84 |
| - ?? container.decodeIfPresent(Comment.self, forKey: .title) |
85 |
| - } |
86 |
| -} |
| 51 | +extension Bug: Codable {} |
87 | 52 |
|
88 | 53 | // MARK: - Trait, TestTrait, SuiteTrait
|
89 | 54 |
|
90 | 55 | extension Bug: TestTrait, SuiteTrait {
|
91 | 56 | public var comments: [Comment] {
|
92 |
| - Array(comment) |
| 57 | + Array(title) |
93 | 58 | }
|
94 | 59 | }
|
95 | 60 |
|
96 | 61 | extension Trait where Self == Bug {
|
97 | 62 | /// Construct a bug to track with a test.
|
98 | 63 | ///
|
99 | 64 | /// - Parameters:
|
100 |
| - /// - identifier: The identifier of this bug in the associated bug-tracking |
101 |
| - /// system. For more information on how this value is interpreted, see the |
102 |
| - /// documentation for ``Bug``. |
103 |
| - /// - comment: An optional, user-specified comment describing this trait. |
| 65 | + /// - url: A URL referring to this bug in the associated bug-tracking |
| 66 | + /// system. |
| 67 | + /// - title: Optionally, the human-readable title of the bug. |
| 68 | + /// |
| 69 | + /// - Returns: An instance of ``Bug`` representing the specified bug. |
| 70 | + public static func bug(_ url: _const String, _ title: Comment? = nil) -> Self { |
| 71 | + Self(url: url, title: title) |
| 72 | + } |
| 73 | + |
| 74 | + /// Construct a bug to track with a test. |
| 75 | + /// |
| 76 | + /// - Parameters: |
| 77 | + /// - url: A URL referring to this bug in the associated bug-tracking |
| 78 | + /// system. |
| 79 | + /// - id: The unique identifier of this bug in its associated bug-tracking |
| 80 | + /// system. |
| 81 | + /// - title: Optionally, the human-readable title of the bug. |
104 | 82 | ///
|
105 | 83 | /// - Returns: An instance of ``Bug`` representing the specified bug.
|
106 |
| - public static func bug(_ identifier: String, _ comment: Comment? = nil) -> Self { |
107 |
| - Self(identifier: identifier, comment: comment) |
| 84 | + public static func bug(_ url: _const String? = nil, id: some Numeric, _ title: Comment? = nil) -> Self { |
| 85 | + Self(url: url, id: String(describing: id), title: title) |
108 | 86 | }
|
109 | 87 |
|
110 | 88 | /// Construct a bug to track with a test.
|
111 | 89 | ///
|
112 | 90 | /// - Parameters:
|
113 |
| - /// - identifier: The identifier of this bug in the associated bug-tracking |
114 |
| - /// system. For more information on how this value is interpreted, see the |
115 |
| - /// documentation for ``Bug``. |
116 |
| - /// - comment: An optional, user-specified comment describing this trait. |
| 91 | + /// - url: A URL referring to this bug in the associated bug-tracking |
| 92 | + /// system. |
| 93 | + /// - id: The unique identifier of this bug in its associated bug-tracking |
| 94 | + /// system. |
| 95 | + /// - title: Optionally, the human-readable title of the bug. |
117 | 96 | ///
|
118 | 97 | /// - Returns: An instance of ``Bug`` representing the specified bug.
|
119 |
| - public static func bug(_ identifier: some Numeric, _ comment: Comment? = nil) -> Self { |
120 |
| - Self(identifier: String(describing: identifier), comment: comment) |
| 98 | + public static func bug(_ url: _const String? = nil, id: _const String, _ title: Comment? = nil) -> Self { |
| 99 | + Self(url: url, id: id, title: title) |
121 | 100 | }
|
122 | 101 | }
|
123 | 102 |
|
|
0 commit comments