Contents

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

@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 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

Return Value

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

Overview

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