diff --git a/Package.swift b/Package.swift index dc481a163..a6f7c6f36 100644 --- a/Package.swift +++ b/Package.swift @@ -90,6 +90,7 @@ let package = Package( targets: [ "_Testing_AppKit", "_Testing_CoreGraphics", + "_Testing_CoreImage", ] ) ] @@ -137,6 +138,7 @@ let package = Package( "Testing", "_Testing_AppKit", "_Testing_CoreGraphics", + "_Testing_CoreImage", "_Testing_Foundation", "MemorySafeTestingTests", ], @@ -218,6 +220,15 @@ let package = Package( path: "Sources/Overlays/_Testing_CoreGraphics", swiftSettings: .packageSettings + .enableLibraryEvolution() ), + .target( + name: "_Testing_CoreImage", + dependencies: [ + "Testing", + "_Testing_CoreGraphics", + ], + path: "Sources/Overlays/_Testing_CoreImage", + swiftSettings: .packageSettings + .enableLibraryEvolution() + ), .target( name: "_Testing_Foundation", dependencies: [ diff --git a/Sources/Overlays/_Testing_AppKit/ReexportTesting.swift b/Sources/Overlays/_Testing_AppKit/ReexportTesting.swift index 3716f1f01..ce80a70d9 100644 --- a/Sources/Overlays/_Testing_AppKit/ReexportTesting.swift +++ b/Sources/Overlays/_Testing_AppKit/ReexportTesting.swift @@ -8,5 +8,5 @@ // See https://swift.org/CONTRIBUTORS.txt for Swift project authors // -@_exported public import Testing -@_exported public import _Testing_CoreGraphics +@_exported @_spi(Experimental) @_spi(ForToolsIntegrationOnly) public import Testing +@_exported @_spi(Experimental) @_spi(ForToolsIntegrationOnly) public import _Testing_CoreGraphics diff --git a/Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift b/Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift index 08c94823c..a3d04e2c8 100644 --- a/Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift +++ b/Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift @@ -24,6 +24,7 @@ private import ImageIO /// be attached to a test: /// /// - [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage) +/// - [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage) /// - [`NSImage`](https://developer.apple.com/documentation/appkit/nsimage) /// (macOS) /// diff --git a/Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift b/Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift index 6c9a76dd5..e2315197d 100644 --- a/Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift +++ b/Sources/Overlays/_Testing_CoreGraphics/Attachments/Attachment+AttachableAsCGImage.swift @@ -36,6 +36,7 @@ extension Attachment { /// ``AttachableAsCGImage`` protocol and can be attached to a test: /// /// - [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage) + /// - [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage) /// - [`NSImage`](https://developer.apple.com/documentation/appkit/nsimage) /// (macOS) /// @@ -82,6 +83,7 @@ extension Attachment { /// ``AttachableAsCGImage`` protocol and can be attached to a test: /// /// - [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage) + /// - [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage) /// - [`NSImage`](https://developer.apple.com/documentation/appkit/nsimage) /// (macOS) /// diff --git a/Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageWrapper.swift b/Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageWrapper.swift index f61b17e7d..8c47e1c99 100644 --- a/Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageWrapper.swift +++ b/Sources/Overlays/_Testing_CoreGraphics/Attachments/_AttachableImageWrapper.swift @@ -47,6 +47,7 @@ import UniformTypeIdentifiers /// to the ``AttachableAsCGImage`` protocol and can be attached to a test: /// /// - [`CGImage`](https://developer.apple.com/documentation/coregraphics/cgimage) +/// - [`CIImage`](https://developer.apple.com/documentation/coreimage/ciimage) /// - [`NSImage`](https://developer.apple.com/documentation/appkit/nsimage) /// (macOS) @_spi(Experimental) diff --git a/Sources/Overlays/_Testing_CoreImage/Attachments/CIImage+AttachableAsCGImage.swift b/Sources/Overlays/_Testing_CoreImage/Attachments/CIImage+AttachableAsCGImage.swift new file mode 100644 index 000000000..b066b3e3f --- /dev/null +++ b/Sources/Overlays/_Testing_CoreImage/Attachments/CIImage+AttachableAsCGImage.swift @@ -0,0 +1,31 @@ +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2024 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 +// See https://swift.org/CONTRIBUTORS.txt for Swift project authors +// + +#if SWT_TARGET_OS_APPLE && canImport(CoreImage) +public import CoreImage +@_spi(Experimental) public import _Testing_CoreGraphics + +@_spi(Experimental) +extension CIImage: AttachableAsCGImage { + public var attachableCGImage: CGImage { + get throws { + guard let result = CIContext().createCGImage(self, from: extent) else { + throw ImageAttachmentError.couldNotCreateCGImage + } + return result + } + } + + public func _makeCopyForAttachment() -> Self { + // CIImage is documented as thread-safe, but does not conform to Sendable. + self + } +} +#endif diff --git a/Sources/Overlays/_Testing_CoreImage/ReexportTesting.swift b/Sources/Overlays/_Testing_CoreImage/ReexportTesting.swift new file mode 100644 index 000000000..ce80a70d9 --- /dev/null +++ b/Sources/Overlays/_Testing_CoreImage/ReexportTesting.swift @@ -0,0 +1,12 @@ +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2024 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 +// See https://swift.org/CONTRIBUTORS.txt for Swift project authors +// + +@_exported @_spi(Experimental) @_spi(ForToolsIntegrationOnly) public import Testing +@_exported @_spi(Experimental) @_spi(ForToolsIntegrationOnly) public import _Testing_CoreGraphics diff --git a/Tests/TestingTests/AttachmentTests.swift b/Tests/TestingTests/AttachmentTests.swift index 4b16d98ea..3a12cc68d 100644 --- a/Tests/TestingTests/AttachmentTests.swift +++ b/Tests/TestingTests/AttachmentTests.swift @@ -22,6 +22,10 @@ import _Testing_Foundation import CoreGraphics @_spi(Experimental) import _Testing_CoreGraphics #endif +#if canImport(CoreImage) +import CoreImage +@_spi(Experimental) import _Testing_CoreImage +#endif #if canImport(UniformTypeIdentifiers) import UniformTypeIdentifiers #endif @@ -582,6 +586,18 @@ extension AttachmentTests { } #endif +#if canImport(CoreImage) + @available(_uttypesAPI, *) + @Test func attachCIImage() throws { + let image = CIImage(cgImage: try Self.cgImage.get()) + let attachment = Attachment(image, named: "diamond.jpg") + #expect(attachment.attachableValue === image) + try attachment.attachableValue.withUnsafeBytes(for: attachment) { buffer in + #expect(buffer.count > 32) + } + } +#endif + #if canImport(AppKit) static var nsImage: NSImage { get throws {