Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
38 changes: 37 additions & 1 deletion Sources/Testing/ABI/ABI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ extension ABI {
/// The current supported ABI version (ignoring any experimental versions.)
typealias CurrentVersion = v0

/// The highest supported ABI version (including any experimental versions.)
/// The highest defined and supported ABI version (including any experimental
/// versions.)
typealias HighestVersion = v6_3

#if !hasFeature(Embedded)
Expand Down Expand Up @@ -93,6 +94,33 @@ extension ABI {
#endif
}

/// The value of the environment variable flag which enables experimental event
/// stream fields, if any.
private let _shouldIncludeExperimentalFlags = Environment.flag(named: "SWT_EXPERIMENTAL_EVENT_STREAM_FIELDS_ENABLED")

extension ABI.Version {
/// Whether or not experimental fields should be included when using this
/// ABI version.
///
/// The value of this property is `true` if any of the following conditions
/// are satisfied:
///
/// - The version number is less than 6.3. This is to preserve compatibility
/// with existing clients before the inclusion of experimental fields became
/// opt-in starting in 6.3.
/// - The version number is greater than or equal to 6.3 and the environment
/// variable flag `SWT_EXPERIMENTAL_EVENT_STREAM_FIELDS_ENABLED` is set to a
/// true value.
/// - The version number is greater than or equal to that of ``ABI/ExperimentalVersion``.
///
/// Otherwise, the value of this property is `false`.
static var includesExperimentalFields: Bool {
versionNumber < ABI.v6_3.versionNumber
|| (versionNumber >= ABI.v6_3.versionNumber && _shouldIncludeExperimentalFlags == true)
|| versionNumber >= ABI.ExperimentalVersion.versionNumber
}
}

// MARK: - Concrete ABI versions

extension ABI {
Expand Down Expand Up @@ -125,6 +153,14 @@ extension ABI {
VersionNumber(6, 3)
}
}

/// A namespace and type representing the ABI version whose symbols are
/// considered experimental.
enum ExperimentalVersion: Sendable, Version {
static var versionNumber: VersionNumber {
VersionNumber(99, 0)
}
}
}

/// A namespace for ABI version 0 symbols.
Expand Down
8 changes: 6 additions & 2 deletions Sources/Testing/ABI/Encoded/ABI.EncodedEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ extension ABI {
instant = EncodedInstant(encoding: event.instant)
self.messages = messages.map(EncodedMessage.init)
testID = event.testID.map(EncodedTest.ID.init)
if eventContext.test?.isParameterized == true {
_testCase = eventContext.testCase.map(EncodedTestCase.init)

// Experimental fields
if V.includesExperimentalFields {
if eventContext.test?.isParameterized == true {
_testCase = eventContext.testCase.map(EncodedTestCase.init)
}
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions Sources/Testing/ABI/Encoded/ABI.EncodedIssue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ extension ABI {
isFailure = issue.isFailure
}

// Experimental
if let backtrace = issue.sourceContext.backtrace {
_backtrace = EncodedBacktrace(encoding: backtrace, in: eventContext)
}
if let error = issue.error {
_error = EncodedError(encoding: error, in: eventContext)
// Experimental fields
if V.includesExperimentalFields {
if let backtrace = issue.sourceContext.backtrace {
_backtrace = EncodedBacktrace(encoding: backtrace, in: eventContext)
}
if let error = issue.error {
_error = EncodedError(encoding: error, in: eventContext)
}
}
}
}
Expand Down
17 changes: 7 additions & 10 deletions Sources/Testing/ABI/Encoded/ABI.EncodedTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,26 @@ extension ABI {
/// The tags associated with the test.
///
/// - Warning: Tags are not yet part of the JSON schema.
///
/// @Metadata {
/// @Available("Swift Testing ABI", introduced: 6.3)
/// }
var _tags: [String]?

init(encoding test: borrowing Test) {
if test.isSuite {
kind = .suite
} else {
kind = .function
let testIsParameterized = test.isParameterized
isParameterized = testIsParameterized
if testIsParameterized {
_testCases = test.uncheckedTestCases?.map(EncodedTestCase.init(encoding:))
}
isParameterized = test.isParameterized
}
name = test.name
displayName = test.displayName
sourceLocation = test.sourceLocation
id = ID(encoding: test.id)

if V.versionNumber >= ABI.v6_3.versionNumber {
// Experimental fields
if V.includesExperimentalFields {
if isParameterized == true {
_testCases = test.uncheckedTestCases?.map(EncodedTestCase.init(encoding:))
}

let tags = test.tags
if !tags.isEmpty {
_tags = tags.map(String.init(describing:))
Expand Down
4 changes: 2 additions & 2 deletions Sources/Testing/ABI/EntryPoints/EntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha
// Check for experimental console output flag
if Environment.flag(named: "SWT_ENABLE_EXPERIMENTAL_CONSOLE_OUTPUT") == true {
// Use experimental AdvancedConsoleOutputRecorder
var advancedOptions = Event.AdvancedConsoleOutputRecorder<ABI.HighestVersion>.Options()
var advancedOptions = Event.AdvancedConsoleOutputRecorder<ABI.ExperimentalVersion>.Options()
advancedOptions.base = .for(.stderr)

let eventRecorder = Event.AdvancedConsoleOutputRecorder<ABI.HighestVersion>(options: advancedOptions) { string in
let eventRecorder = Event.AdvancedConsoleOutputRecorder<ABI.ExperimentalVersion>(options: advancedOptions) { string in
try? FileHandle.stderr.write(string)
}

Expand Down
7 changes: 3 additions & 4 deletions Sources/Testing/ExitTests/ExitTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,9 @@ extension ABI {
/// The ABI version to use for encoding and decoding events sent over the back
/// channel.
///
/// The back channel always uses the latest ABI version (even if experimental)
/// since both the producer and consumer use this exact version of the testing
/// library.
fileprivate typealias BackChannelVersion = v6_3
/// The back channel always uses the experimental ABI version since both the
/// producer and consumer use this exact version of the testing library.
fileprivate typealias BackChannelVersion = ExperimentalVersion
}

@_spi(ForToolsIntegrationOnly)
Expand Down
2 changes: 1 addition & 1 deletion Tests/TestingTests/SwiftPMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ struct SwiftPMTests {
}
#expect(testRecords.count == 1)
for testRecord in testRecords {
if version.versionNumber >= ABI.v6_3.versionNumber {
if version.versionNumber < ABI.v6_3.versionNumber || version.versionNumber >= ABI.ExperimentalVersion.versionNumber {
#expect(testRecord._tags != nil)
} else {
#expect(testRecord._tags == nil)
Expand Down