Skip to content

Commit 46c32f1

Browse files
committed
Augment JSON ABI
Add tags, bug and timeLimit traits to the test ABI JSON data.
1 parent 98430f2 commit 46c32f1

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

Documentation/ABI/JSON.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,23 @@ 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
164+
161165
}
162166
163167
<test-id> ::= <string> ; an opaque string representing the test case
168+
169+
<tags> ::= <string> ; a string representation of a tag
170+
171+
<bug> ::= {
172+
["url": <string>,] ; the bug url
173+
["id": <string>,] ; the bug id
174+
"title": <string> ; the human readable bug title
175+
} ;
176+
164177
```
165178

166179
<!--

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

Lines changed: 22 additions & 5 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
@@ -74,9 +74,13 @@ extension ABI {
7474
var isParameterized: Bool?
7575

7676
/// The tags associated with the test.
77-
///
78-
/// - Warning: Tags are not yet part of the JSON schema.
79-
var _tags: [String]?
77+
var tags: [String]?
78+
79+
// The bugs associated with the test.
80+
var bugs: [Bug]?
81+
82+
/// The time limits associated with the test.
83+
var timeLimit: Int?
8084

8185
init(encoding test: borrowing Test) {
8286
if test.isSuite {
@@ -95,10 +99,23 @@ extension ABI {
9599
if isParameterized == true {
96100
_testCases = test.uncheckedTestCases?.map(EncodedTestCase.init(encoding:))
97101
}
102+
}
98103

104+
if V.versionNumber >= ABI.v6_3.versionNumber {
99105
let tags = test.tags
100106
if !tags.isEmpty {
101-
_tags = tags.map(String.init(describing:))
107+
self.tags = tags.map(String.init(describing:))
108+
}
109+
// From version 6.3 onwards, bugs are included as an experimental
110+
// field.
111+
let bugs = test.traits.compactMap { $0 as? Bug }
112+
if !bugs.isEmpty {
113+
self.bugs = bugs
114+
}
115+
if #available(_clockAPI , *) {
116+
if let seconds = test.timeLimit?.components.seconds {
117+
self.timeLimit = Int(seconds)
118+
}
102119
}
103120
}
104121
}

Tests/TestingTests/SwiftPMTests.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,18 @@ 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(60)),
389+
.timeLimit(Swift.Duration.seconds(testTimeLimit)),
390+
arguments: expectedArgs as [String]
391+
) {arg1 in}
383392
let eventContext = Event.Context(test: test, testCase: nil, configuration: nil)
384393

385394
configuration.handleEvent(Event(.testDiscovered, testID: test.id, testCaseID: nil), in: eventContext)
@@ -403,10 +412,21 @@ struct SwiftPMTests {
403412
#expect(testRecords.count == 1)
404413
for testRecord in testRecords {
405414
if version.includesExperimentalFields {
406-
#expect(testRecord._tags != nil)
415+
let actualTestCases = testRecord._testCases
416+
let testCases = try #require(actualTestCases)
417+
#expect(testCases.count == expectedArgs.count)
407418
} else {
408-
#expect(testRecord._tags == nil)
419+
#expect(testRecord._testCases == nil)
409420
}
421+
422+
if version.versionNumber >= ABI.v6_3.versionNumber {
423+
#expect(testRecord.tags != nil)
424+
let bugs = try #require(testRecord.bugs)
425+
#expect(bugs.count == 2)
426+
let timeLimit = try #require(testRecord.timeLimit)
427+
#expect(timeLimit == testTimeLimit)
428+
}
429+
410430
}
411431
let eventRecords = decodedRecords.compactMap { record in
412432
if case let .event(event) = record.kind {

0 commit comments

Comments
 (0)