Skip to content

Commit 404f121

Browse files
authored
Update documentation to explain misconfigurations of SWT_ conditions. (#772)
This PR was supposed to be part of #769, but I must have blown away a local commit because it didn't make it into that PR. This PR updates Porting.md to explain when a developer might encounter an error due to mismatched `SWT_` conditions. It ensures that exit tests require process spawning to be enabled/implemented by adding a dependency between `SWT_NO_PROCESS_SPAWNING` and `SWT_NO_EXIT_TESTS`. This PR also tweaks which bits of `ExitTest` are exposed on platforms that do not support exit tests at all. The type needs to be exposed so that `ExitTest.Result` is exposed so that we can correctly expose `#expect(exitsWith:)` and `#require(exitsWith:)` while marking them unavailable, as opposed to hiding the macros and not giving a developer clear diagnostics. ### Checklist: - [ ] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [ ] If public symbols are renamed or modified, DocC references should be updated.
1 parent 4810d90 commit 404f121

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

Diff for: Documentation/Porting.md

+10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ These warnings may be emitted by our internal C++ module (`_TestingInternals`)
5858
or by our library module (`Testing`). Both indicate areas of our code that need
5959
platform-specific attention.
6060

61+
> [!NOTE]
62+
> Rarely, you may encounter errors of a similar form:
63+
>
64+
> > 🛑 ERROR: Platform-specific misconfiguration: ...
65+
>
66+
> These errors are produced when the configuration you're trying to build has
67+
> conflicting requirements (for example, attempting to enable support for pipes
68+
> without also enabling support for file I/O.) You should be able to resolve
69+
> these issues by updating Package.swift and/or CompilerSettings.cmake.
70+
6171
Most platform dependencies can be resolved through the use of platform-specific
6272
API. For example, Swift Testing uses the C11 standard [`timespec`](https://en.cppreference.com/w/c/chrono/timespec)
6373
type to accurately track the durations of test runs. If you are porting Swift

Diff for: Sources/Testing/ExitTests/ExitTest.swift

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010

1111
private import _TestingInternals
1212

13+
#if !SWT_NO_EXIT_TESTS
14+
#if SWT_NO_PIPES
15+
#error("Platform-specific misconfiguration: support for exit tests requires support for (anonymous) pipes")
16+
#endif
17+
#if SWT_NO_PROCESS_SPAWNING
18+
#error("Platform-specific misconfiguration: support for exit tests requires support for process spawning")
19+
#endif
20+
#endif
21+
1322
/// A type describing an exit test.
1423
///
1524
/// Instances of this type describe an exit test defined by the test author and
@@ -19,7 +28,6 @@ private import _TestingInternals
1928
@available(*, unavailable, message: "Exit tests are not available on this platform.")
2029
#endif
2130
public struct ExitTest: Sendable, ~Copyable {
22-
#if !SWT_NO_EXIT_TESTS
2331
/// The expected exit condition of the exit test.
2432
@_spi(ForToolsIntegrationOnly)
2533
public var expectedExitCondition: ExitCondition
@@ -33,7 +41,12 @@ public struct ExitTest: Sendable, ~Copyable {
3341
/// processes, so it can be used to uniquely identify an exit test at runtime.
3442
@_spi(ForToolsIntegrationOnly)
3543
public var sourceLocation: SourceLocation
44+
}
3645

46+
#if !SWT_NO_EXIT_TESTS
47+
// MARK: - Invocation
48+
49+
extension ExitTest {
3750
/// Disable crash reporting, crash logging, or core dumps for the current
3851
/// process.
3952
private static func _disableCrashReporting() {
@@ -100,13 +113,8 @@ public struct ExitTest: Sendable, ~Copyable {
100113
let expectingFailure = expectedExitCondition == .failure
101114
exit(expectingFailure ? EXIT_SUCCESS : EXIT_FAILURE)
102115
}
103-
#endif
104116
}
105117

106-
#if !SWT_NO_EXIT_TESTS
107-
#if SWT_NO_PIPES
108-
#error("Support for exit tests requires support for (anonymous) pipes.")
109-
#endif
110118
// MARK: - Discovery
111119

112120
/// A protocol describing a type that contains an exit test.

Diff for: Sources/Testing/Support/FileHandle.swift

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
internal import _TestingInternals
1212

13+
#if !SWT_NO_PIPES
14+
#if SWT_NO_FILE_IO
15+
#error("Platform-specific misconfiguration: support for (anonymous) pipes requires support for file I/O")
16+
#endif
17+
#endif
18+
1319
#if !SWT_NO_FILE_IO
1420
/// A type representing a file handle.
1521
///

0 commit comments

Comments
 (0)