mirror of
https://github.com/apple/swift-nio
synced 2026-11-30 05:28:44 +00:00
Motivation: I/O is typically blocking, but options for interacting with the filesystem using `async` APIs are limited. This change adds a new module to NIO, `NIOFileSystem`. At the moment this is exposed as the `_NIOFileSystem` product while users get a chance to try it out and provide feedback. During this time the API of `NIOFileSystem` is subject to change. Breaking changes will come in _minor_ NIO releases and additive changes may come in _patch_ releases of NIO. Modifications: - Add `NIOFileSystem`, `NIOFileSystemFoundationCompat`, `NIOFileSystemTests`, `NIOFileSystemIntegrationTests`, and `NIOFileSystemFoundationCompatTests`. - Update docs - Update CNIOLinux and CNIODarwin shims Result: File system can be accessed via `async` APIs
69 lines
2.0 KiB
Swift
69 lines
2.0 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import NIOFileSystem
|
|
import XCTest
|
|
|
|
func XCTAssertThrowsErrorAsync<R>(
|
|
file: StaticString = #file,
|
|
line: UInt = #line,
|
|
expression: () async throws -> R,
|
|
onError: (Error) -> Void = { _ in }
|
|
) async {
|
|
do {
|
|
_ = try await expression()
|
|
XCTFail("expression did not throw", file: file, line: line)
|
|
} catch {
|
|
onError(error)
|
|
}
|
|
}
|
|
|
|
func XCTAssertThrowsFileSystemError<R>(
|
|
_ expression: @autoclosure () throws -> R,
|
|
file: StaticString = #file,
|
|
line: UInt = #line,
|
|
_ onError: (FileSystemError) -> Void = { _ in }
|
|
) {
|
|
XCTAssertThrowsError(try expression(), file: file, line: line) { error in
|
|
if let fsError = error as? FileSystemError {
|
|
onError(fsError)
|
|
} else {
|
|
XCTFail(
|
|
"Expected 'FileSystemError' but found '\(type(of: error))'",
|
|
file: file,
|
|
line: line
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
func XCTAssertThrowsFileSystemErrorAsync<R>(
|
|
file: StaticString = #file,
|
|
line: UInt = #line,
|
|
_ expression: () async throws -> R,
|
|
onError: (FileSystemError) -> Void = { _ in }
|
|
) async {
|
|
await XCTAssertThrowsErrorAsync(file: file, line: line, expression: expression) { error in
|
|
if let fsError = error as? FileSystemError {
|
|
onError(fsError)
|
|
} else {
|
|
XCTFail(
|
|
"Expected 'FileSystemError' but found '\(type(of: error))'",
|
|
file: file,
|
|
line: line
|
|
)
|
|
}
|
|
}
|
|
}
|