Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Documentation/ABI/JSON.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,23 @@ additional `"testCases"` field describing the individual test cases.
["displayName": <string>,] ; the user-supplied custom display name
"sourceLocation": <source-location>, ; where the test is defined
"id": <test-id>,
"isParameterized": <bool> ; is this a parameterized test function or not?
"isParameterized": <bool>, ; is this a parameterized test function or not?
["tags": <array:tag>,] ; the tags associated with this test function
["bugs": <array:bug>,] ; the bugs associated with this test function
["timeLimit": <number>] ; the time limit associated with this test function

}

<test-id> ::= <string> ; an opaque string representing the test case

<tags> ::= <string> ; a string representation of a tag

<bug> ::= {
["url": <string>,] ; the bug url
["id": <string>,] ; the bug id
"title": <string> ; the human readable bug title
} ;

```

<!--
Expand Down
27 changes: 22 additions & 5 deletions Sources/Testing/ABI/Encoded/ABI.EncodedTest.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Copyright (c) 2024-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -74,9 +74,13 @@ extension ABI {
var isParameterized: Bool?

/// The tags associated with the test.
///
/// - Warning: Tags are not yet part of the JSON schema.
var _tags: [String]?
var tags: [String]?

// The bugs associated with the test.
var bugs: [Bug]?

/// The time limits associated with the test.
var timeLimit: Int?

init(encoding test: borrowing Test) {
if test.isSuite {
Expand All @@ -95,10 +99,23 @@ extension ABI {
if isParameterized == true {
_testCases = test.uncheckedTestCases?.map(EncodedTestCase.init(encoding:))
}
}

if V.versionNumber >= ABI.v6_3.versionNumber {
let tags = test.tags
if !tags.isEmpty {
_tags = tags.map(String.init(describing:))
self.tags = tags.map(String.init(describing:))
}
// From version 6.3 onwards, bugs are included as an experimental
// field.
let bugs = test.traits.compactMap { $0 as? Bug }
if !bugs.isEmpty {
self.bugs = bugs
}
if #available(_clockAPI , *) {
if let seconds = test.timeLimit?.components.seconds {
self.timeLimit = Int(seconds)
}
}
}
}
Expand Down
26 changes: 23 additions & 3 deletions Tests/TestingTests/SwiftPMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,18 @@ struct SwiftPMTests {
defer {
_ = remove(temporaryFilePath)
}
let testTimeLimit = 3
let expectedArgs = ["argument1", "argument2"]
do {
let configuration = try configurationForEntryPoint(withArguments: ["PATH", outputArgumentName, temporaryFilePath, versionArgumentName, "\(version.versionNumber)"])
let test = Test(.tags(.blue)) {}
let test = Test(
.tags(.blue),
.bug("https://my.defect.com/1234"),
.bug("other defect"),
.timeLimit(Swift.Duration.seconds(60)),
.timeLimit(Swift.Duration.seconds(testTimeLimit)),
arguments: expectedArgs as [String]
) {arg1 in}
let eventContext = Event.Context(test: test, testCase: nil, configuration: nil)

configuration.handleEvent(Event(.testDiscovered, testID: test.id, testCaseID: nil), in: eventContext)
Expand All @@ -403,10 +412,21 @@ struct SwiftPMTests {
#expect(testRecords.count == 1)
for testRecord in testRecords {
if version.includesExperimentalFields {
#expect(testRecord._tags != nil)
let actualTestCases = testRecord._testCases
let testCases = try #require(actualTestCases)
#expect(testCases.count == expectedArgs.count)
} else {
#expect(testRecord._tags == nil)
#expect(testRecord._testCases == nil)
}

if version.versionNumber >= ABI.v6_3.versionNumber {
#expect(testRecord.tags != nil)
let bugs = try #require(testRecord.bugs)
#expect(bugs.count == 2)
let timeLimit = try #require(testRecord.timeLimit)
#expect(timeLimit == testTimeLimit)
}

}
let eventRecords = decodedRecords.compactMap { record in
if case let .event(event) = record.kind {
Expand Down
Loading