Skip to content

Commit abd2d37

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

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed

Documentation/ABI/JSON.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,26 @@ 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> ::= "." <chacters> | <tag> ; 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+
} ;
175+
176+
<characters> ::= "" | <characters> <character>
177+
<chacter> ::= <letter> | <digit>
178+
<letter> ::= 'a' | 'b' | 'c' | ... | 'z' | 'A' | 'B' | ... | 'Z'
179+
<digit> ::= '0' | '1' | '2' | ... | '9'
164180
```
165181

166182
<!--

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: 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.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 == testTimeLimit)
433+
}
434+
410435
}
411436
let eventRecords = decodedRecords.compactMap { record in
412437
if case let .event(event) = record.kind {

0 commit comments

Comments
 (0)