File tree Expand file tree Collapse file tree 4 files changed +70
-3
lines changed
_TestingInternals/include Expand file tree Collapse file tree 4 files changed +70
-3
lines changed Original file line number Diff line number Diff line change @@ -142,9 +142,20 @@ let package = Package(
142142 exclude: [ " CMakeLists.txt " , " Testing.swiftcrossimport " ] ,
143143 cxxSettings: . packageSettings,
144144 swiftSettings: . packageSettings + . enableLibraryEvolution( ) ,
145- linkerSettings: [
146- . linkedLibrary( " execinfo " , . when( platforms: [ . custom( " freebsd " ) , . openbsd] ) )
147- ]
145+ linkerSettings: {
146+ var result = [ LinkerSetting] ( )
147+ result += [
148+ . linkedLibrary( " execinfo " , . when( platforms: [ . custom( " freebsd " ) , . openbsd] ) )
149+ ]
150+ #if compiler(>=6.3)
151+ result += [
152+ . linkedFramework( " _TestingInterop " , . whenApple( ) ) ,
153+ . linkedLibrary( " _TestingInterop " , . whenApple( false ) ) ,
154+ ]
155+ #endif
156+
157+ return result
158+ } ( )
148159 ) ,
149160 . testTarget(
150161 name: " TestingTests " ,
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ add_library(Testing
3131 Attachments/Attachment.swift
3232 Events/Clock.swift
3333 Events/Event.swift
34+ Events/Event+FallbackHandler.swift
3435 Events/Recorder/Event.AdvancedConsoleOutputRecorder.swift
3536 Events/Recorder/Event.ConsoleOutputRecorder.swift
3637 Events/Recorder/Event.HumanReadableOutputRecorder.swift
Original file line number Diff line number Diff line change 1+ //
2+ // This source file is part of the Swift.org open source project
3+ //
4+ // Copyright (c) 2025 Apple Inc. and the Swift project authors
5+ // Licensed under Apache License v2.0 with Runtime Library Exception
6+ //
7+ // See https://swift.org/LICENSE.txt for license information
8+ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+ //
10+
11+ private import _TestingInternals
12+
13+ extension Event {
14+ /// Post this event to the currently-installed fallback event handler.
15+ ///
16+ /// - Parameters:
17+ /// - context: The context associated with this event.
18+ ///
19+ /// - Returns: Whether or not the fallback event handler was invoked. If the
20+ /// currently-installed handler belongs to the testing library, returns
21+ /// `false`.
22+ borrowing func postToFallbackHandler( in context: borrowing Context ) -> Bool {
23+ #if canImport(_TestingInterop)
24+ guard let fallbackEventHandler = _swift_testing_getFallbackEventHandler ( ) else {
25+ return false
26+ }
27+
28+ // Encode the event as JSON and pass it to the handler.
29+ let encodeAndInvoke = ABI . CurrentVersion. eventHandler ( encodeAsJSONLines: false ) {
30+ recordJSON in
31+ fallbackEventHandler (
32+ String ( describing: ABI . CurrentVersion. versionNumber) ,
33+ recordJSON. baseAddress!,
34+ recordJSON. count,
35+ nil
36+ )
37+ }
38+ encodeAndInvoke ( self , context)
39+ return true
40+ #else
41+ return false
42+ #endif
43+ }
44+ }
Original file line number Diff line number Diff line change @@ -180,6 +180,17 @@ static int swt_setfdflags(int fd, int flags) {
180180}
181181#endif
182182
183+ #if !SWT_NO_INTEROP
184+
185+ typedef void (* FallbackEventHandler )(const char * recordJSONSchemaVersionNumber ,
186+ const void * recordJSONBaseAddress ,
187+ long recordJSONByteCount ,
188+ const void * _Nullable reserved );
189+
190+ FallbackEventHandler _Nullable _swift_testing_getFallbackEventHandler ();
191+
192+ #endif
193+
183194SWT_ASSUME_NONNULL_END
184195
185196#endif
You can’t perform that action at this time.
0 commit comments