Skip to content

Commit 2ed7ff2

Browse files
committed
Mark image attachments as unavailable on non-Darwin/non-Windows.
This PR explicitly marks the image attachments API bits in the core Swift Testing library as unavailable on e.g. Linux. Developers who attempt to use this API on Linux will get diagnostics such as: > 🛑 'AttachableImageFormat' is unavailable: Image attachments are not available on this platform.
1 parent 0a2fb6b commit 2ed7ff2

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

Sources/Testing/Attachments/Images/AttachableImageFormat.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
/// @Metadata {
3232
/// @Available(Swift, introduced: 6.3)
3333
/// }
34+
#if !(SWT_TARGET_OS_APPLE || os(Windows))
35+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
36+
#endif
3437
@available(_uttypesAPI, *)
3538
public struct AttachableImageFormat: Sendable {
3639
/// An enumeration describing the various kinds of image format that can be
@@ -77,6 +80,9 @@ public struct AttachableImageFormat: Sendable {
7780

7881
// MARK: -
7982

83+
#if !(SWT_TARGET_OS_APPLE || os(Windows))
84+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
85+
#endif
8086
@available(_uttypesAPI, *)
8187
extension AttachableImageFormat {
8288
/// The PNG image format.

Sources/Testing/Attachments/Images/Attachment+_AttachableAsImage.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11+
#if !(SWT_TARGET_OS_APPLE || os(Windows))
12+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
13+
#endif
1114
@available(_uttypesAPI, *)
1215
extension Attachment {
1316
/// Initialize an instance of this type that encloses the given image.
@@ -101,6 +104,9 @@ extension Attachment {
101104
// MARK: -
102105

103106
@_spi(Experimental) // STOP: not part of ST-0014
107+
#if !(SWT_TARGET_OS_APPLE || os(Windows))
108+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
109+
#endif
104110
@available(_uttypesAPI, *)
105111
extension Attachment where AttachableValue: AttachableWrapper, AttachableValue.Wrapped: _AttachableAsImage {
106112
/// The image format to use when encoding the represented image.

Sources/Testing/Attachments/Images/ImageAttachmentError.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
private import _TestingInternals
1212

1313
/// A type representing an error that can occur when attaching an image.
14+
#if !(SWT_TARGET_OS_APPLE || os(Windows))
15+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
16+
#endif
1417
package enum ImageAttachmentError: Error {
1518
#if SWT_TARGET_OS_APPLE
1619
/// The image could not be converted to an instance of `CGImage`.
@@ -39,6 +42,9 @@ package enum ImageAttachmentError: Error {
3942
#endif
4043
}
4144

45+
#if !(SWT_TARGET_OS_APPLE || os(Windows))
46+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
47+
#endif
4248
extension ImageAttachmentError: CustomStringConvertible {
4349
package var description: String {
4450
#if SWT_TARGET_OS_APPLE

Sources/Testing/Attachments/Images/_AttachableAsImage.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
/// A future Swift Evolution proposal will promote this protocol to API so
1919
/// that we don't need to underscore its name.
2020
/// }
21+
#if !(SWT_TARGET_OS_APPLE || os(Windows))
22+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
23+
#endif
2124
@available(_uttypesAPI, *)
2225
public protocol _AttachableAsImage: SendableMetatype {
2326
/// Make a copy of this instance to pass to an attachment.

Sources/Testing/Attachments/Images/_AttachableImageWrapper.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
/// @Comment {
2121
/// | Windows | [`HBITMAP`](https://learn.microsoft.com/en-us/windows/win32/gdi/bitmaps), [`HICON`](https://learn.microsoft.com/en-us/windows/win32/menurc/icons), [`IWICBitmapSource`](https://learn.microsoft.com/en-us/windows/win32/api/wincodec/nn-wincodec-iwicbitmapsource) (including its subclasses declared by Windows Imaging Component) |
2222
/// }
23+
#if !(SWT_TARGET_OS_APPLE || os(Windows))
24+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
25+
#endif
2326
@available(_uttypesAPI, *)
2427
public final class _AttachableImageWrapper<Image>: Sendable where Image: _AttachableAsImage {
2528
/// The underlying image.
@@ -38,6 +41,9 @@ public final class _AttachableImageWrapper<Image>: Sendable where Image: _Attach
3841
}
3942
}
4043

44+
#if !(SWT_TARGET_OS_APPLE || os(Windows))
45+
@available(*, unavailable, message: "Image attachments are not available on this platform.")
46+
#endif
4147
@available(_uttypesAPI, *)
4248
extension _AttachableImageWrapper {
4349
public var wrappedValue: Image {

0 commit comments

Comments
 (0)