マクロ


expect(_:sourceLocation:performing:
throws:)

  廃止  

式が常に何らかの条件に一致するエラーを throw することを確認し、そうでない場合はエラーを throw します。


Swift 6.0+ Xcode 16.0+

@discardableResult @freestanding(expression)
macro expect<R>(
    _ comment: @autoclosure () -> Comment? = nil,
    sourceLocation: SourceLocation = #_sourceLocation,
    performing expression: () async throws -> R,
    throws errorMatcher: (any Error) async throws -> Bool
) -> any Error


  廃止   代わりに expect(throws:_:sourceLocation:performing:) または expect(throws:_:sourceLocation:performing:) の結果を調べて下さい。

let error = try #require(throws: FoodTruckError.self) {
  ...
}
#expect(error.napkinCount == 0)




以下も見よ


エラーが throw されたか確認する


Swift コード内のエラーのテスト

コードがあなたの期待どおりにエラーを処理することを確認します。


macro expect<E, R>(throws: E.Type, @autoclosure () -> Comment?, sourceLocation: SourceLocation, performing: () async throws -> R) -> E?

式が常に与えられた型のエラーを throw することを確認します。


macro expect<E, R>(throws: E, @autoclosure () -> Comment?, sourceLocation: SourceLocation, performing: () async throws -> R) -> E?

式が常に特定のエラーを throw することを確認します。


macro expect<R>(@autoclosure () -> Comment?, sourceLocation: SourceLocation, performing: () async throws -> R, throws: (any Error) async throws -> Bool) -> (any Error)?

式が常に何らかの条件に一致するエラーを throw することを確認します。

  廃止  


macro require<E, R>(throws: E.Type, @autoclosure () -> Comment?, sourceLocation: SourceLocation, performing: () async throws -> R) -> E

式が常に与えられた型のエラーを throw することを確認し、そうでない場合はエラーを throw します。


macro require<E, R>(throws: E, @autoclosure () -> Comment?, sourceLocation: SourceLocation, performing: () async throws -> R) -> E














トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ












トップへ