Skip to content

Commit 301f3f9

Browse files
committed
Merge branch 'main' into jgrynspan/162-redesign-value-capture
2 parents 4a5f7e5 + 8500bd0 commit 301f3f9

File tree

155 files changed

+6792
-1226
lines changed

Some content is hidden

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

155 files changed

+6792
-1226
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
blank_issues_enabled: true
1010
contact_links:
1111
- name: 🌐 Discuss an idea
12-
url: https://forums.swift.org/c/related-projects/swift-testing
12+
url: https://forums.swift.org/c/development/swift-testing/103
1313
about: >
1414
Share an idea with the Swift Testing community.
1515
- name: 📄 Formally propose a change
@@ -18,10 +18,10 @@ contact_links:
1818
Formally propose an addition, removal, or change to the APIs or features
1919
of Swift Testing.
2020
- name: 🙋 Ask a question
21-
url: https://forums.swift.org/c/related-projects/swift-testing
21+
url: https://forums.swift.org/c/swift-users/15
2222
about: >
23-
Ask a question about or get help with Swift Testing. Beginner questions
24-
welcome!
23+
Ask a question or get help by starting a new Forum topic with the 'swift-testing' tag.
24+
Beginner questions welcome!
2525
- name: 🪲 Report an issue with Swift Package Manager
2626
url: https://github.com/swiftlang/swift-package-manager/issues/new/choose
2727
about: >

CODEOWNERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#
22
# This source file is part of the Swift.org open source project
33
#
4-
# Copyright (c) 2023 Apple Inc. and the Swift project authors
4+
# Copyright (c) 2023–2025 Apple Inc. and the Swift project authors
55
# Licensed under Apache License v2.0 with Runtime Library Exception
66
#
77
# See https://swift.org/LICENSE.txt for license information
88
# See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
#
1010

11-
* @stmontgomery @grynspan @briancroom @suzannaratcliff
11+
* @stmontgomery @grynspan @briancroom @suzannaratcliff @jerryjrchen

CONTRIBUTING.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ and install a toolchain.
4848

4949
#### Installing a toolchain
5050

51-
1. Download a toolchain. A recent **6.0 development snapshot** toolchain is
52-
required to build the testing library. Visit
53-
[swift.org](http://swift.org/install) and download the most recent toolchain
54-
from the section titled **release/6.0** under **Development Snapshots** on
55-
the page for your platform.
51+
1. Download a toolchain. A recent **development snapshot** toolchain is required
52+
to build the testing library. Visit [swift.org](https://swift.org/install),
53+
select your platform, and download the most recent toolchain from the section
54+
titled **release/6.x** under **Development Snapshots**.
5655

5756
Be aware that development snapshot toolchains aren't intended for day-to-day
5857
development and may contain defects that affect the programs built with them.

Documentation/Porting.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ platform-specific attention.
6767
> conflicting requirements (for example, attempting to enable support for pipes
6868
> without also enabling support for file I/O.) You should be able to resolve
6969
> these issues by updating `Package.swift` and/or `CompilerSettings.cmake`.
70+
>
71+
> Don't forget to add your platform to the `BuildSettingCondition/whenApple(_:)`
72+
> function in `Package.swift`.
7073
7174
Most platform dependencies can be resolved through the use of platform-specific
7275
API. For example, Swift Testing uses the C11 standard [`timespec`](https://en.cppreference.com/w/c/chrono/timespec)

Documentation/StyleGuide.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,26 @@ to the code called by the initialization expression causing the inferred type of
7171
its property to change unknowingly, which could break clients. Properties with
7272
lower access levels may have an inferred type.
7373

74-
Exported C and C++ symbols that are exported should be given the prefix `swt_`
75-
and should otherwise be named using the same lowerCamelCase naming rules as in
76-
Swift. Use the `SWT_EXTERN` macro to ensure that symbols are consistently
77-
visible in C, C++, and Swift. For example:
74+
C and C++ symbols that are used by the testing library should be given the
75+
prefix `swt_` and should otherwise be named using the same lowerCamelCase naming
76+
rules as in Swift. Use the `SWT_EXTERN` macro to ensure that symbols are
77+
consistently visible in C, C++, and Swift. For example:
7878

7979
```c
8080
SWT_EXTERN bool swt_isDebugModeEnabled(void);
8181

8282
SWT_EXTERN void swt_setDebugModeEnabled(bool isEnabled);
8383
```
8484
85+
> [!NOTE]
86+
> If a symbol is meant to be **publicly visible** and can be called by modules
87+
> other than Swift Testing, use the prefix `swift_testing_` instead of `swt_`
88+
> for consistency with the Swift standard library:
89+
>
90+
> ```c
91+
> SWT_EXTERN void swift_testing_debugIfNeeded(void);
92+
> ```
93+
8594
C and C++ types should be given the prefix `SWT` and should otherwise be named
8695
using the same UpperCamelCase naming rules as in Swift. For example:
8796

Package.swift

Lines changed: 129 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let buildingForDevelopment = (git?.currentTag == nil)
2727
/// to change in the future.
2828
///
2929
/// - Bug: There is currently no way for us to tell if we are being asked to
30-
/// build for an Embedded Swift target at the package manifest level.
30+
/// build for an Embedded Swift target at the package manifest level.
3131
/// ([swift-syntax-#8431](https://github.com/swiftlang/swift-package-manager/issues/8431))
3232
let buildingForEmbedded: Bool = {
3333
guard let envvar = Context.environment["SWT_EMBEDDED"] else {
@@ -84,6 +84,19 @@ let package = Package(
8484
)
8585
#endif
8686

87+
result += [
88+
.library(
89+
name: "_Testing_ExperimentalImageAttachments",
90+
targets: [
91+
"_Testing_AppKit",
92+
"_Testing_CoreGraphics",
93+
"_Testing_CoreImage",
94+
"_Testing_UIKit",
95+
"_Testing_WinSDK",
96+
]
97+
)
98+
]
99+
87100
result.append(
88101
.library(
89102
name: "_TestDiscovery",
@@ -95,15 +108,16 @@ let package = Package(
95108
return result
96109
}(),
97110

98-
traits: [
99-
.trait(
100-
name: "ExperimentalExitTestValueCapture",
101-
description: "Enable experimental support for capturing values in exit tests"
102-
),
103-
],
104-
105111
dependencies: [
106-
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "602.0.0-latest"),
112+
// swift-syntax periodically publishes a new tag with a suffix of the format
113+
// "-prerelease-YYYY-MM-DD". We always want to use the most recent tag
114+
// associated with a particular Swift version, without needing to hardcode
115+
// an exact tag and manually keep it up-to-date. Specifying the suffix
116+
// "-latest" on this dependency is a workaround which causes Swift package
117+
// manager to use the lexicographically highest-sorted tag with the
118+
// specified semantic version, meaning the most recent "prerelease" tag will
119+
// always be used.
120+
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "603.0.0-latest"),
107121
],
108122

109123
targets: [
@@ -125,10 +139,32 @@ let package = Package(
125139
name: "TestingTests",
126140
dependencies: [
127141
"Testing",
142+
"_Testing_AppKit",
128143
"_Testing_CoreGraphics",
144+
"_Testing_CoreImage",
129145
"_Testing_Foundation",
146+
"_Testing_UIKit",
147+
"_Testing_WinSDK",
148+
"MemorySafeTestingTests",
130149
],
131-
swiftSettings: .packageSettings
150+
swiftSettings: .packageSettings,
151+
linkerSettings: [
152+
.linkedLibrary("util", .when(platforms: [.openbsd]))
153+
]
154+
),
155+
156+
// Use a plain `.target` instead of a `.testTarget` to avoid the unnecessary
157+
// overhead of having a separate test target for this module. Conceptually,
158+
// the content in this module is no different than content which would
159+
// typically be placed in the `TestingTests` target, except this content
160+
// needs the (module-wide) strict memory safety feature to be enabled.
161+
.target(
162+
name: "MemorySafeTestingTests",
163+
dependencies: [
164+
"Testing",
165+
],
166+
path: "Tests/_MemorySafeTestingTests",
167+
swiftSettings: .packageSettings + .strictMemorySafety
132168
),
133169
.testTarget(
134170
name: "SubexpressionShowcase",
@@ -182,12 +218,33 @@ let package = Package(
182218
),
183219

184220
// Cross-import overlays (not supported by Swift Package Manager)
221+
.target(
222+
name: "_Testing_AppKit",
223+
dependencies: [
224+
"Testing",
225+
"_Testing_CoreGraphics",
226+
],
227+
path: "Sources/Overlays/_Testing_AppKit",
228+
exclude: ["CMakeLists.txt"],
229+
swiftSettings: .packageSettings + .enableLibraryEvolution()
230+
),
185231
.target(
186232
name: "_Testing_CoreGraphics",
187233
dependencies: [
188234
"Testing",
189235
],
190236
path: "Sources/Overlays/_Testing_CoreGraphics",
237+
exclude: ["CMakeLists.txt"],
238+
swiftSettings: .packageSettings + .enableLibraryEvolution()
239+
),
240+
.target(
241+
name: "_Testing_CoreImage",
242+
dependencies: [
243+
"Testing",
244+
"_Testing_CoreGraphics",
245+
],
246+
path: "Sources/Overlays/_Testing_CoreImage",
247+
exclude: ["CMakeLists.txt"],
191248
swiftSettings: .packageSettings + .enableLibraryEvolution()
192249
),
193250
.target(
@@ -200,7 +257,26 @@ let package = Package(
200257
// The Foundation module only has Library Evolution enabled on Apple
201258
// platforms, and since this target's module publicly imports Foundation,
202259
// it can only enable Library Evolution itself on those platforms.
203-
swiftSettings: .packageSettings + .enableLibraryEvolution(applePlatformsOnly: true)
260+
swiftSettings: .packageSettings + .enableLibraryEvolution(.whenApple())
261+
),
262+
.target(
263+
name: "_Testing_UIKit",
264+
dependencies: [
265+
"Testing",
266+
"_Testing_CoreGraphics",
267+
"_Testing_CoreImage",
268+
],
269+
path: "Sources/Overlays/_Testing_UIKit",
270+
exclude: ["CMakeLists.txt"],
271+
swiftSettings: .packageSettings + .enableLibraryEvolution()
272+
),
273+
.target(
274+
name: "_Testing_WinSDK",
275+
dependencies: [
276+
"Testing",
277+
],
278+
path: "Sources/Overlays/_Testing_WinSDK",
279+
swiftSettings: .packageSettings + .enableLibraryEvolution()
204280
),
205281

206282
// Utility targets: These are utilities intended for use when developing
@@ -236,11 +312,11 @@ extension BuildSettingCondition {
236312
/// Swift.
237313
///
238314
/// - Parameters:
239-
/// - nonEmbeddedCondition: The value to return if the target is not
240-
/// Embedded Swift. If `nil`, the build condition evaluates to `false`.
315+
/// - nonEmbeddedCondition: The value to return if the target is not
316+
/// Embedded Swift. If `nil`, the build condition evaluates to `false`.
241317
///
242318
/// - Returns: A build setting condition that evaluates to `true` for Embedded
243-
/// Swift or is equal to `nonEmbeddedCondition` for non-Embedded Swift.
319+
/// Swift or is equal to `nonEmbeddedCondition` for non-Embedded Swift.
244320
static func whenEmbedded(or nonEmbeddedCondition: @autoclosure () -> Self? = nil) -> Self? {
245321
if !buildingForEmbedded {
246322
if let nonEmbeddedCondition = nonEmbeddedCondition() {
@@ -255,6 +331,21 @@ extension BuildSettingCondition {
255331
nil
256332
}
257333
}
334+
335+
/// A build setting condition representing all Apple or non-Apple platforms.
336+
///
337+
/// - Parameters:
338+
/// - isApple: Whether or not the result represents Apple platforms.
339+
///
340+
/// - Returns: A build setting condition that evaluates to `isApple` for Apple
341+
/// platforms.
342+
static func whenApple(_ isApple: Bool = true) -> Self {
343+
if isApple {
344+
.when(platforms: [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS])
345+
} else {
346+
.when(platforms: [.linux, .custom("freebsd"), .openbsd, .windows, .wasi, .android])
347+
}
348+
}
258349
}
259350

260351
extension Array where Element == PackageDescription.SwiftSetting {
@@ -296,30 +387,25 @@ extension Array where Element == PackageDescription.SwiftSetting {
296387
// new-enough toolchain.
297388
.enableExperimentalFeature("AllowUnsafeAttribute"),
298389

390+
.enableUpcomingFeature("InferIsolatedConformances"),
391+
299392
// When building as a package, the macro plugin always builds as an
300393
// executable rather than a library.
301394
.define("SWT_NO_LIBRARY_MACRO_PLUGINS"),
302395

303-
.define("SWT_TARGET_OS_APPLE", .when(platforms: [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS])),
396+
.define("SWT_TARGET_OS_APPLE", .whenApple()),
304397

305398
.define("SWT_NO_EXIT_TESTS", .whenEmbedded(or: .when(platforms: [.iOS, .watchOS, .tvOS, .visionOS, .wasi, .android]))),
306399
.define("SWT_NO_PROCESS_SPAWNING", .whenEmbedded(or: .when(platforms: [.iOS, .watchOS, .tvOS, .visionOS, .wasi, .android]))),
307-
.define("SWT_NO_SNAPSHOT_TYPES", .whenEmbedded(or: .when(platforms: [.linux, .custom("freebsd"), .openbsd, .windows, .wasi, .android]))),
400+
.define("SWT_NO_SNAPSHOT_TYPES", .whenEmbedded(or: .whenApple(false))),
308401
.define("SWT_NO_DYNAMIC_LINKING", .whenEmbedded(or: .when(platforms: [.wasi]))),
309402
.define("SWT_NO_PIPES", .whenEmbedded(or: .when(platforms: [.wasi]))),
403+
.define("SWT_NO_FOUNDATION_FILE_COORDINATION", .whenEmbedded(or: .whenApple(false))),
310404

311405
.define("SWT_NO_LEGACY_TEST_DISCOVERY", .whenEmbedded()),
312406
.define("SWT_NO_LIBDISPATCH", .whenEmbedded()),
313407
]
314408

315-
// Unconditionally enable 'ExperimentalExitTestValueCapture' when building
316-
// for development.
317-
if buildingForDevelopment {
318-
result += [
319-
.define("ExperimentalExitTestValueCapture")
320-
]
321-
}
322-
323409
return result
324410
}
325411

@@ -342,25 +428,33 @@ extension Array where Element == PackageDescription.SwiftSetting {
342428
]
343429
}
344430

345-
/// Create a Swift setting which enables Library Evolution, optionally
346-
/// constraining it to only Apple platforms.
431+
/// Create a Swift setting which enables Library Evolution.
347432
///
348433
/// - Parameters:
349-
/// - applePlatformsOnly: Whether to constrain this setting to only Apple
350-
/// platforms.
351-
static func enableLibraryEvolution(applePlatformsOnly: Bool = false) -> Self {
434+
/// - condition: A build setting condition to apply to this setting.
435+
///
436+
/// - Returns: A Swift setting that enables Library Evolution.
437+
static func enableLibraryEvolution(_ condition: BuildSettingCondition? = nil) -> Self {
352438
var result = [PackageDescription.SwiftSetting]()
353439

354440
if buildingForDevelopment {
355-
var condition: BuildSettingCondition?
356-
if applePlatformsOnly {
357-
condition = .when(platforms: [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS])
358-
}
359441
result.append(.unsafeFlags(["-enable-library-evolution"], condition))
360442
}
361443

362444
return result
363445
}
446+
447+
/// Settings necessary to enable Strict Memory Safety, introduced in
448+
/// [SE-0458: Opt-in Strict Memory Safety Checking](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0458-strict-memory-safety.md#swiftpm-integration).
449+
static var strictMemorySafety: Self {
450+
#if compiler(>=6.2)
451+
// FIXME: Adopt official `.strictMemorySafety()` condition once the minimum
452+
// supported toolchain is 6.2.
453+
[.unsafeFlags(["-strict-memory-safety"])]
454+
#else
455+
[]
456+
#endif
457+
}
364458
}
365459

366460
extension Array where Element == PackageDescription.CXXSetting {
@@ -372,9 +466,10 @@ extension Array where Element == PackageDescription.CXXSetting {
372466
result += [
373467
.define("SWT_NO_EXIT_TESTS", .whenEmbedded(or: .when(platforms: [.iOS, .watchOS, .tvOS, .visionOS, .wasi, .android]))),
374468
.define("SWT_NO_PROCESS_SPAWNING", .whenEmbedded(or: .when(platforms: [.iOS, .watchOS, .tvOS, .visionOS, .wasi, .android]))),
375-
.define("SWT_NO_SNAPSHOT_TYPES", .whenEmbedded(or: .when(platforms: [.linux, .custom("freebsd"), .openbsd, .windows, .wasi, .android]))),
469+
.define("SWT_NO_SNAPSHOT_TYPES", .whenEmbedded(or: .whenApple(false))),
376470
.define("SWT_NO_DYNAMIC_LINKING", .whenEmbedded(or: .when(platforms: [.wasi]))),
377471
.define("SWT_NO_PIPES", .whenEmbedded(or: .when(platforms: [.wasi]))),
472+
.define("SWT_NO_FOUNDATION_FILE_COORDINATION", .whenEmbedded(or: .whenApple(false))),
378473

379474
.define("SWT_NO_LEGACY_TEST_DISCOVERY", .whenEmbedded()),
380475
.define("SWT_NO_LIBDISPATCH", .whenEmbedded()),

0 commit comments

Comments
 (0)