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
13 changes: 12 additions & 1 deletion Documentation/ABI/JSON.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,21 @@ 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
<tag> ::= "." <string> ; a string representation of a tag
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore (blocking): Update to reflect actual behaviour

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the "." from the definition please! Even if it's mandated, this wouldn't be syntactically correct.

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

<!--
Expand Down
36 changes: 30 additions & 6 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 @@ -75,8 +75,24 @@ extension ABI {

/// The tags associated with the test.
///
/// - Warning: Tags are not yet part of the JSON schema.
var _tags: [String]?
/// @Metadata {
/// @Available(Swift, introduced: 6.3)
/// }
var tags: Set<Tag>?

/// The bugs associated with the test.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.3)
/// }
var bugs: [Bug]?

/// The time limits associated with the test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The time limits associated with the test.
/// The time limits associated with the test.
///
/// @Metadata {
/// @Available(Swift, introduced: 6.3)
/// }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

///
/// @Metadata {
/// @Available(Swift, introduced: 6.3)
/// }
var timeLimit: Double?

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

let tags = test.tags
if !tags.isEmpty {
_tags = tags.map(String.init(describing:))
if V.versionNumber >= ABI.v6_3.versionNumber {
self.tags = test.tags
// 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 , *) {
self.timeLimit = test.timeLimit.map(TimeValue.init).map(Double.init)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Testing/Traits/Tags/Tag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ extension Tag: Codable, CodingKeyRepresentable {
}

/// This instance represented as a string, suitable for encoding.
private var _codableStringValue: String {
package var _codableStringValue: String {
switch kind {
case let .staticMember(name):
".\(name)"
"\(name)"
}
}

Expand Down
31 changes: 28 additions & 3 deletions Tests/TestingTests/SwiftPMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,19 @@ 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(testTimeLimit + 100)),
.timeLimit(Swift.Duration.seconds(testTimeLimit)),
.timeLimit(Swift.Duration.seconds(testTimeLimit + 10)),
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 +413,25 @@ 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 {
let testTags = try #require(testRecord.tags)
#expect(testTags.count >= 1)
for tag in testTags {
#expect(!tag._codableStringValue.starts(with: "."))
}
let bugs = try #require(testRecord.bugs)
#expect(bugs.count == 2)
let timeLimit = try #require(testRecord.timeLimit)
#expect(timeLimit == Double(testTimeLimit))
}

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