Skip to content

Commit b3bda79

Browse files
committed
Augment JSON ABI
Add tags, bug and timeLimit traits to the test ABI JSON data.
1 parent af7a094 commit b3bda79

File tree

4 files changed

+72
-12
lines changed

4 files changed

+72
-12
lines changed

Documentation/ABI/JSON.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,21 @@ additional `"testCases"` field describing the individual test cases.
157157
["displayName": <string>,] ; the user-supplied custom display name
158158
"sourceLocation": <source-location>, ; where the test is defined
159159
"id": <test-id>,
160-
"isParameterized": <bool> ; is this a parameterized test function or not?
160+
"isParameterized": <bool>, ; is this a parameterized test function or not?
161+
["tags": <array:tag>,] ; the tags associated with this test function
162+
["bugs": <array:bug>,] ; the bugs associated with this test function
163+
["timeLimit": <number>] ; the time limit associated with this test function
161164
}
162165
163166
<test-id> ::= <string> ; an opaque string representing the test case
167+
168+
<tag> ::= "." <string> ; a string representation of a tag
169+
170+
<bug> ::= {
171+
["url": <string>,] ; the bug URL
172+
["id": <string>,] ; the bug id
173+
["title": <string>] ; the human readable bug title
174+
} ;
164175
```
165176

166177
<!--

Sources/Testing/ABI/Encoded/ABI.EncodedTest.swift

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// This source file is part of the Swift.org open source project
33
//
4-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
4+
// Copyright (c) 2024-2025 Apple Inc. and the Swift project authors
55
// Licensed under Apache License v2.0 with Runtime Library Exception
66
//
77
// See https://swift.org/LICENSE.txt for license information
@@ -75,8 +75,24 @@ extension ABI {
7575

7676
/// The tags associated with the test.
7777
///
78-
/// - Warning: Tags are not yet part of the JSON schema.
79-
var _tags: [String]?
78+
/// @Metadata {
79+
/// @Available(Swift, introduced: 6.3)
80+
/// }
81+
var tags: Set<Tag>?
82+
83+
/// The bugs associated with the test.
84+
///
85+
/// @Metadata {
86+
/// @Available(Swift, introduced: 6.3)
87+
/// }
88+
var bugs: [Bug]?
89+
90+
/// The time limits associated with the test.
91+
///
92+
/// @Metadata {
93+
/// @Available(Swift, introduced: 6.3)
94+
/// }
95+
var timeLimit: Double?
8096

8197
init(encoding test: borrowing Test) {
8298
if test.isSuite {
@@ -95,10 +111,18 @@ extension ABI {
95111
if isParameterized == true {
96112
_testCases = test.uncheckedTestCases?.map(EncodedTestCase.init(encoding:))
97113
}
114+
}
98115

99-
let tags = test.tags
100-
if !tags.isEmpty {
101-
_tags = tags.map(String.init(describing:))
116+
if V.versionNumber >= ABI.v6_3.versionNumber {
117+
self.tags = test.tags
118+
// From version 6.3 onwards, bugs are included as an experimental
119+
// field.
120+
let bugs = test.traits.compactMap { $0 as? Bug }
121+
if !bugs.isEmpty {
122+
self.bugs = bugs
123+
}
124+
if #available(_clockAPI , *) {
125+
self.timeLimit = test.timeLimit.map(TimeValue.init).map(Double.init)
102126
}
103127
}
104128
}

Sources/Testing/Traits/Tags/Tag.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ extension Tag: Codable, CodingKeyRepresentable {
9494
}
9595

9696
/// This instance represented as a string, suitable for encoding.
97-
private var _codableStringValue: String {
97+
package var _codableStringValue: String {
9898
switch kind {
9999
case let .staticMember(name):
100-
".\(name)"
100+
"\(name)"
101101
}
102102
}
103103

Tests/TestingTests/SwiftPMTests.swift

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,19 @@ struct SwiftPMTests {
377377
defer {
378378
_ = remove(temporaryFilePath)
379379
}
380+
let testTimeLimit = 3
381+
let expectedArgs = ["argument1", "argument2"]
380382
do {
381383
let configuration = try configurationForEntryPoint(withArguments: ["PATH", outputArgumentName, temporaryFilePath, versionArgumentName, "\(version.versionNumber)"])
382-
let test = Test(.tags(.blue)) {}
384+
let test = Test(
385+
.tags(.blue),
386+
.bug("https://my.defect.com/1234"),
387+
.bug("other defect"),
388+
.timeLimit(Swift.Duration.seconds(testTimeLimit + 100)),
389+
.timeLimit(Swift.Duration.seconds(testTimeLimit)),
390+
.timeLimit(Swift.Duration.seconds(testTimeLimit + 10)),
391+
arguments: expectedArgs as [String]
392+
) {arg1 in}
383393
let eventContext = Event.Context(test: test, testCase: nil, configuration: nil)
384394

385395
configuration.handleEvent(Event(.testDiscovered, testID: test.id, testCaseID: nil), in: eventContext)
@@ -403,10 +413,25 @@ struct SwiftPMTests {
403413
#expect(testRecords.count == 1)
404414
for testRecord in testRecords {
405415
if version.includesExperimentalFields {
406-
#expect(testRecord._tags != nil)
416+
let actualTestCases = testRecord._testCases
417+
let testCases = try #require(actualTestCases)
418+
#expect(testCases.count == expectedArgs.count)
407419
} else {
408-
#expect(testRecord._tags == nil)
420+
#expect(testRecord._testCases == nil)
409421
}
422+
423+
if version.versionNumber >= ABI.v6_3.versionNumber {
424+
let testTags = try #require(testRecord.tags)
425+
#expect(testTags.count >= 1)
426+
for tag in testTags {
427+
#expect(!tag._codableStringValue.starts(with: "."))
428+
}
429+
let bugs = try #require(testRecord.bugs)
430+
#expect(bugs.count == 2)
431+
let timeLimit = try #require(testRecord.timeLimit)
432+
#expect(timeLimit == Double(testTimeLimit))
433+
}
434+
410435
}
411436
let eventRecords = decodedRecords.compactMap { record in
412437
if case let .event(event) = record.kind {

0 commit comments

Comments
 (0)