<!--
{
  "availability" : [
    "Swift: 6.2.0 -",
    "Xcode: 26.0.0 -",
    "macOS: -",
    "swift: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/require(processExitsWith:observing:_:sourceLocation:performing:)",
  "metadataVersion" : "0.1.0",
  "role" : "Macro",
  "symbol" : {
    "kind" : "Macro",
    "modules" : [
      "Swift Testing"
    ],
    "preciseIdentifier" : "s:7Testing7require16processExitsWith9observing_14sourceLocation10performingAA8ExitTestV6ResultVAH9ConditionV_Says8Sendable_s14PartialKeyPathCyAJGXcGAA7CommentVSgyXKAA06SourceH0VyyYaYbKctcfm"
  },
  "title" : "require(processExitsWith:observing:_:sourceLocation:performing:)"
}
-->

# require(processExitsWith:observing:_:sourceLocation:performing:)

Check that an expression causes the process to terminate in a given fashion
and throw an error if it did not.

```
@discardableResult @freestanding(expression) macro require(processExitsWith expectedExitCondition: ExitTest.Condition, observing observedValues: [any PartialKeyPath<ExitTest.Result> & Sendable] = [], _ comment: @autoclosure () -> Comment? = nil, sourceLocation: SourceLocation = #_sourceLocation, performing expression: @escaping @Sendable () async throws -> Void) -> ExitTest.Result
```

## Parameters

`expectedExitCondition`

The expected exit condition.

`observedValues`

An array of key paths representing results from within
the exit test that should be observed and returned by this macro. The
[`exitStatus`](/documentation/Testing/ExitTest/Result/exitStatus) property is always returned.

`comment`

A comment describing the expectation.

`sourceLocation`

The source location to which recorded expectations and
issues should be attributed.

`expression`

The expression to be evaluated.

## Return Value

An instance of [`ExitTest.Result`](/documentation/Testing/ExitTest/Result) describing the state of the
exit test when it exited.

## Overview> Throws: An instance of ``doc://org.swift.testing/documentation/Testing/ExpectationFailedError`` if the exit condition of
> the child process does not equal `expectedExitCondition`.

Use this overload of `#require()` when an expression will cause the current
process to terminate and the nature of that termination will determine if
the test passes or fails. For example, to test that calling `fatalError()`
causes a process to terminate:

```swift
try await #require(processExitsWith: .failure) {
  fatalError()
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)