Skip to content

Commit a8162be

Browse files
committed
Merge branch 'main' into jgrynspan/third-party-testing-library-discovery
2 parents ef03958 + 9e0b757 commit a8162be

56 files changed

Lines changed: 463 additions & 243 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.

.github/workflows/automerge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
jobs:
1919
create_merge_pr:
2020
name: Create PR to merge main into release branch
21-
uses: swiftlang/github-workflows/.github/workflows/[email protected].3
21+
uses: swiftlang/github-workflows/.github/workflows/[email protected].4
2222
with:
2323
head_branch: main
2424
base_branch: release/6.3
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Manual OpenBSD/amd64 build (7.8)
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
META_DATA_CONTENT: |
8+
{
9+
"instance-id": "iid-local01",
10+
"dsmode": "local"
11+
}
12+
USER_DATA_CONTENT: |
13+
#cloud-config
14+
timezone: UTC
15+
write_files:
16+
- content: |
17+
set -ex
18+
function atexit {
19+
echo 1 > /tmp/result
20+
tar cvf /dev/sd1c -C /tmp result
21+
halt -p;
22+
}
23+
trap atexit EXIT
24+
printf '\033\143'
25+
export PATH=/usr/local/bin:$PATH
26+
mount /dev/sd3c /mnt
27+
cp -r /mnt/repo /home/repo/
28+
cd /home/repo/
29+
swift test
30+
echo $? > /tmp/result
31+
tar cvf /dev/sd1c -C /tmp result
32+
halt -p
33+
path: /etc/rc.local
34+
permissions: '0755'
35+
36+
jobs:
37+
openbsd:
38+
name: OpenBSD
39+
runs-on: ubuntu-latest
40+
timeout-minutes: 30
41+
container:
42+
image: ghcr.io/3405691582/openbsd-swift-amd64:7.8
43+
env:
44+
CPU: "4"
45+
MEM: "16G"
46+
KVM: "-enable-kvm"
47+
options: --device /dev/kvm
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v5
51+
52+
- name: Write cloud-init files
53+
run: |
54+
echo "$META_DATA_CONTENT" > /usr/local/share/cidata/meta-data
55+
echo "$USER_DATA_CONTENT" > /usr/local/share/cidata/user-data
56+
57+
- name: Prepare cloud-init
58+
run: |
59+
cp -r $GITHUB_WORKSPACE /usr/local/share/cidata/repo/ && \
60+
cat /usr/local/share/cidata/meta-data && \
61+
cat /usr/local/share/cidata/user-data && \
62+
ls /usr/local/share/cidata
63+
64+
- name: Run
65+
run: /usr/local/bin/cmd.sh
66+
67+
- name: Report
68+
run: |
69+
ls -l /usr/local/share/tape && \
70+
exit $(cat /usr/local/share/tape/result)

Documentation/ABI/JSON.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,14 @@ sufficient information to display the event in a human-readable format.
219219
["testID": <test-id>,
220220
["testCase": <test-case>]]
221221
-->
222+
223+
## See Also
224+
225+
### Relevant Swift Evolution proposals
226+
227+
| Proposal Number | Summary | Swift Version | Schema Version |
228+
|:-|-|-:|-:|
229+
| [ST-0002](https://github.com/swiftlang/swift-evolution/blob/main/proposals/testing/0002-json-abi.md) | Introduced the initial version of this JSON schema. | 6.0 | `0` |
230+
| [ST-0009](https://github.com/swiftlang/swift-evolution/blob/main/proposals/testing/0009-attachments.md#integration-with-supporting-tools) | Added attachments. | 6.2 | `0` |
231+
| [ST-0013](https://github.com/swiftlang/swift-evolution/blob/main/proposals/testing/0013-issue-severity-warning.md#event-stream) | Added test issue severity. | 6.3 | `"6.3"` |
232+
| [ST-0016](https://github.com/swiftlang/swift-evolution/blob/main/proposals/testing/0016-test-cancellation.md#integration-with-supporting-tools) | Added test cancellation. | 6.3 | `"6.3"` |

Package.swift

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ let package = Package(
141141
],
142142
exclude: ["CMakeLists.txt", "Testing.swiftcrossimport"],
143143
cxxSettings: .packageSettings,
144-
swiftSettings: .packageSettings + .enableLibraryEvolution(),
144+
swiftSettings: .packageSettings + .enableLibraryEvolution() + .moduleABIName("Testing"),
145145
linkerSettings: [
146146
.linkedLibrary("execinfo", .when(platforms: [.custom("freebsd"), .openbsd]))
147147
]
@@ -189,21 +189,15 @@ let package = Package(
189189
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
190190
],
191191
exclude: ["CMakeLists.txt"],
192-
swiftSettings: .packageSettings + {
193-
var result = [PackageDescription.SwiftSetting]()
194-
192+
swiftSettings: .packageSettings + [
195193
// The only target which needs the ability to import this macro
196194
// implementation target's module is its unit test target. Users of the
197195
// macros this target implements use them via their declarations in the
198196
// Testing module. This target's module is never distributed to users,
199197
// but as an additional guard against accidental misuse, this specifies
200198
// the unit test target as the only allowable client.
201-
if buildingForDevelopment {
202-
result.append(.unsafeFlags(["-Xfrontend", "-allowable-client", "-Xfrontend", "TestingMacrosTests"]))
203-
}
204-
205-
return result
206-
}()
199+
.unsafeFlags(["-Xfrontend", "-allowable-client", "-Xfrontend", "TestingMacrosTests"]),
200+
]
207201
),
208202

209203
// "Support" targets: These targets are not meant to be used directly by
@@ -218,7 +212,7 @@ let package = Package(
218212
dependencies: ["_TestingInternals",],
219213
exclude: ["CMakeLists.txt"],
220214
cxxSettings: .packageSettings,
221-
swiftSettings: .packageSettings + .enableLibraryEvolution()
215+
swiftSettings: .packageSettings + .enableLibraryEvolution() + .moduleABIName("_TestDiscovery")
222216
),
223217
.target(
224218
// Build _TestingInterop for debugging/testing purposes only. It is
@@ -228,7 +222,7 @@ let package = Package(
228222
path: "Sources/_TestingInterop",
229223
exclude: ["CMakeLists.txt"],
230224
cxxSettings: .packageSettings,
231-
swiftSettings: .packageSettings
225+
swiftSettings: .packageSettings + .moduleABIName("_TestingInterop")
232226
),
233227

234228
// Cross-import overlays (not supported by Swift Package Manager)
@@ -240,7 +234,7 @@ let package = Package(
240234
],
241235
path: "Sources/Overlays/_Testing_AppKit",
242236
exclude: ["CMakeLists.txt"],
243-
swiftSettings: .packageSettings + .enableLibraryEvolution()
237+
swiftSettings: .packageSettings + .enableLibraryEvolution() + .moduleABIName("Testing")
244238
),
245239
.target(
246240
name: "_Testing_CoreGraphics",
@@ -249,7 +243,7 @@ let package = Package(
249243
],
250244
path: "Sources/Overlays/_Testing_CoreGraphics",
251245
exclude: ["CMakeLists.txt"],
252-
swiftSettings: .packageSettings + .enableLibraryEvolution()
246+
swiftSettings: .packageSettings + .enableLibraryEvolution() + .moduleABIName("_Testing_CoreGraphics")
253247
),
254248
.target(
255249
name: "_Testing_CoreImage",
@@ -259,7 +253,7 @@ let package = Package(
259253
],
260254
path: "Sources/Overlays/_Testing_CoreImage",
261255
exclude: ["CMakeLists.txt"],
262-
swiftSettings: .packageSettings + .enableLibraryEvolution()
256+
swiftSettings: .packageSettings + .enableLibraryEvolution() + .moduleABIName("_Testing_CoreImage")
263257
),
264258
.target(
265259
name: "_Testing_Foundation",
@@ -271,7 +265,7 @@ let package = Package(
271265
// The Foundation module only has Library Evolution enabled on Apple
272266
// platforms, and since this target's module publicly imports Foundation,
273267
// it can only enable Library Evolution itself on those platforms.
274-
swiftSettings: .packageSettings + .enableLibraryEvolution(.whenApple())
268+
swiftSettings: .packageSettings + .enableLibraryEvolution(.whenApple()) + .moduleABIName("_Testing_Foundation")
275269
),
276270
.target(
277271
name: "_Testing_UIKit",
@@ -282,7 +276,7 @@ let package = Package(
282276
],
283277
path: "Sources/Overlays/_Testing_UIKit",
284278
exclude: ["CMakeLists.txt"],
285-
swiftSettings: .packageSettings + .enableLibraryEvolution()
279+
swiftSettings: .packageSettings + .enableLibraryEvolution() + .moduleABIName("_Testing_UIKit")
286280
),
287281
.target(
288282
name: "_Testing_WinSDK",
@@ -291,7 +285,7 @@ let package = Package(
291285
],
292286
path: "Sources/Overlays/_Testing_WinSDK",
293287
exclude: ["CMakeLists.txt"],
294-
swiftSettings: .packageSettings + .enableLibraryEvolution()
288+
swiftSettings: .packageSettings + .enableLibraryEvolution() + .moduleABIName("_Testing_WinSDK")
295289
),
296290

297291
// Utility targets: These are utilities intended for use when developing
@@ -369,9 +363,9 @@ extension Array where Element == PackageDescription.SwiftSetting {
369363
static var packageSettings: Self {
370364
var result = availabilityMacroSettings
371365

372-
if buildingForDevelopment {
373-
result.append(.unsafeFlags(["-require-explicit-sendable"]))
374-
}
366+
#if compiler(>=6.3)
367+
result.append(.treatWarning("ExplicitSendable", as: .warning))
368+
#endif
375369

376370
if buildingForEmbedded {
377371
result.append(.enableExperimentalFeature("Embedded"))
@@ -391,6 +385,9 @@ extension Array where Element == PackageDescription.SwiftSetting {
391385
.enableExperimentalFeature("SymbolLinkageMarkers"),
392386
.enableExperimentalFeature("CompileTimeValuesPreview"),
393387

388+
// Enabled to allow tests to be added to ~Escapable suites.
389+
.enableExperimentalFeature("Lifetimes"),
390+
394391
.enableUpcomingFeature("InferIsolatedConformances"),
395392

396393
// When building as a package, the macro plugin always builds as an
@@ -449,6 +446,30 @@ extension Array where Element == PackageDescription.SwiftSetting {
449446

450447
return result
451448
}
449+
450+
/// Create a Swift setting which specifies the module ABI name to use when
451+
/// building the target with the specified name.
452+
///
453+
/// - Parameters:
454+
/// - targetName The name of the target for which an ABI name should be
455+
/// specified.
456+
///
457+
/// - Returns: A Swift setting that specifies the ABI name of the module of
458+
/// the target named `targetName`.
459+
///
460+
/// This function simplifies the process of specifying a custom module ABI
461+
/// name for various targets in this package. The module ABI name is given a
462+
/// suffix for all targets in this package which emit a module that is also
463+
/// included in the built-in copy of Swift Testing in Swift toolchains and
464+
/// vendor distributions. Without this, there can be runtime collisions; for
465+
/// example, on Darwin platforms (where Swift uses the Objective-C runtime),
466+
/// a non-generic Swift class type causes a warning from the runtime about
467+
/// duplicate class definitions. Specifying a distinct ABI name for each
468+
/// module related to Swift Testing loaded into a runner process avoids this
469+
/// issue.
470+
static func moduleABIName(_ targetName: String) -> Self {
471+
[.unsafeFlags(["-module-abi-name", "\(targetName)_package"])]
472+
}
452473
}
453474

454475
extension Array where Element == PackageDescription.CXXSetting {

Sources/Overlays/_Testing_AppKit/Attachments/NSImage+AttachableAsImage.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extension NSImageRep {
3636
/// @Metadata {
3737
/// @Available(Swift, introduced: 6.3)
3838
/// }
39+
@available(_uttypesAPI, *)
3940
extension NSImage: AttachableAsImage, AttachableAsCGImage {
4041
/// @Metadata {
4142
/// @Available(Swift, introduced: 6.3)
@@ -58,6 +59,10 @@ extension NSImage: AttachableAsImage, AttachableAsCGImage {
5859
return maxRepWidth ?? 1.0
5960
}
6061

62+
public func withUnsafeBytes<R>(as imageFormat: AttachableImageFormat, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
63+
try withUnsafeBytesImpl(as: imageFormat, body)
64+
}
65+
6166
public func _copyAttachableValue() -> Self {
6267
// If this image is of an NSImage subclass, we cannot reliably make a deep
6368
// copy of it because we don't know what its `init(data:)` implementation

Sources/Overlays/_Testing_AppKit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# See https://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
10+
include(ModuleABIName)
1011
add_library(_Testing_AppKit
1112
Attachments/NSImage+AttachableAsImage.swift
1213
ReexportTesting.swift)

Sources/Overlays/_Testing_CoreGraphics/Attachments/AttachableAsCGImage.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ extension AttachableAsCGImage {
7474
1.0
7575
}
7676

77-
public func withUnsafeBytes<R>(as imageFormat: AttachableImageFormat, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
77+
/// The shared implementation of ``AttachableAsImage/withUnsafeBytes(as:_:)``
78+
/// used by types that conform to ``AttachableAsCGImage``.
79+
///
80+
/// For documentation, see ``AttachableAsImage/withUnsafeBytes(as:_:)``.
81+
package func withUnsafeBytesImpl<R>(as imageFormat: AttachableImageFormat, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
7882
let data = NSMutableData()
7983

8084
// Convert the image to a CGImage.

Sources/Overlays/_Testing_CoreGraphics/Attachments/CGImage+AttachableAsImage.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ public import CoreGraphics
1414
/// @Metadata {
1515
/// @Available(Swift, introduced: 6.3)
1616
/// }
17+
@available(_uttypesAPI, *)
1718
extension CGImage: AttachableAsImage, AttachableAsCGImage {
1819
/// @Metadata {
1920
/// @Available(Swift, introduced: 6.3)
2021
/// }
2122
package var attachableCGImage: CGImage {
2223
self
2324
}
25+
26+
public func withUnsafeBytes<R>(as imageFormat: AttachableImageFormat, _ body: (UnsafeRawBufferPointer) throws -> R) throws -> R {
27+
try withUnsafeBytesImpl(as: imageFormat, body)
28+
}
2429
}
2530
#endif

Sources/Overlays/_Testing_CoreGraphics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# See https://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
if(APPLE)
10+
include(ModuleABIName)
1011
add_library(_Testing_CoreGraphics
1112
Attachments/AttachableAsCGImage.swift
1213
Attachments/_AttachableImageWrapper+AttachableWrapper.swift

0 commit comments

Comments
 (0)