---
title: "expect(processExitsWith:observing:_:sourceLocation:performing:)"
framework: testing
role: symbol
role_heading: Macro
path: "testing/expect(processexitswith:observing:_:sourcelocation:performing:)"
---

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

Check that an expression causes the process to terminate in a given fashion.

## Declaration

```swift
@discardableResult @freestanding(expression) macro expect(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 If the exit test passes, an instance of ExitTest.Result describing the state of the exit test when it exited. If the exit test fails, the result is nil.

## Overview

Overview Use this overload of #expect() 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: await #expect(processExitsWith: .failure) {   fatalError() }

## See Also

### Checking how processes exit

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