mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
Motivation: We changed the file path type in `_NIOFileSystem` to use `NIOFilePath` instead of `FilePath`. Originally we planned to use API shims to avoid breaking API, however in some cases this was inevitable (i.e. where a file path is returned to the caller). To roll over to the new API we will instead introduce the `NIOFileSystem` module using `NIOFilePath` and have `_NIOFileSystem` use `FilePath`. Users can then opt-in to the new stable API rather than having it forced upon them. The first wave of these changes turns `_NIOFileSystem` into `NIOFileSystem` and uses `NIOFilePath` for its APIs. Modifications: - Remove disfavoured overloads (i.e. `FilePath` APIs) - Update the `DirectoryEntry` API to use `NIOFilePath`. - Update tests to use `NIOFilePath` since many were relying on the newly removed shims - Remove the underscore from the module names and products - Remove deprecated methods A follow up change will re-instate the `_NIOFileSystem` (and compat) module and products using `FilePath`. Result: `NIOFileSystem` has a stable API.
40 lines
1.7 KiB
Swift
40 lines
1.7 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2025 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@_spi(Testing) @testable import NIOFileSystem
|
|
import SystemPackage
|
|
import XCTest
|
|
|
|
#if canImport(System)
|
|
import System
|
|
#endif
|
|
|
|
final class FilePathTests: XCTestCase {
|
|
/// Tests that the conversion of a SystemPackage.FilePath instance to a NIOFilePath instance (and vice-versa) results in the same underlying object.
|
|
func testConversion() {
|
|
// Create a NIOFilePath and SystemPackage.FilePath instance, both pointing to "/foo/bar/../baz"
|
|
let filePathNIO = NIOFilePath("/foo/bar/../baz")
|
|
let filePathSystemPackage = SystemPackage.FilePath("/foo/bar/../baz")
|
|
|
|
// Convert the NIOFilePath instance to a SystemPackage.FilePath one, and check if the result matches the
|
|
// directly initialized SystemPackage.FilePath instance
|
|
XCTAssertEqual(SystemPackage.FilePath(filePathNIO), filePathSystemPackage)
|
|
|
|
// Now do the opposite: convert the SystemPackage.FilePath instance to a NIOFilePath, and check if the result
|
|
// matches the directly initialized NIOFilePath instance
|
|
let systemPackageFilePathConvertedToNIO = NIOFilePath(filePathSystemPackage)
|
|
XCTAssertEqual(systemPackageFilePathConvertedToNIO, filePathNIO)
|
|
}
|
|
}
|