---
title: "require(processExitsWith:observing:_:sourceLocation:performing:)"
framework: testing
role: symbol
role_heading: Macro
path: "testing/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.

## Declaration

```swift
@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 doc://org.swift.testing/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.

## Mentioned in

Exit testing

## Return Value

Return Value An instance of ExitTest.Result describing the state of the exit test when it exited.

## Overview

Overview note: An instance of 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: try await #require(processExitsWith: .failure) {   fatalError() }

## See Also

### Checking how processes exit

- [Exit testing](testing/exit-testing.md)
- [expect(processExitsWith:observing:_:sourceLocation:performing:)](testing/expect(processexitswith:observing:_:sourcelocation:performing:).md)
- [ExitStatus](testing/exitstatus.md)
- [ExitTest](testing/exittest.md)
