From 211884fde1c0eea428795bd5477aebb00744744b Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 30 Oct 2024 18:21:41 -0700 Subject: [PATCH] Fix tests when building swift-format using Swift 6.0.2 When traversing the file URL with Foundation from Swift 6.0.2, you get the following components - `["/", "C:", "test.swift"]` - `["/", "C:"]` - `[]` The component count never reaches 1. Foundation from Swift 6.1 goes - `["/", "C:", "test.swift"]` - `["/", "C:"]` - `["/"]` Cover both cases by checking for `<= 1` instead of `== 1` --- Sources/SwiftFormat/API/Configuration.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftFormat/API/Configuration.swift b/Sources/SwiftFormat/API/Configuration.swift index 7cc0d385..2586024a 100644 --- a/Sources/SwiftFormat/API/Configuration.swift +++ b/Sources/SwiftFormat/API/Configuration.swift @@ -478,7 +478,7 @@ fileprivate extension URL { #if os(Windows) // FIXME: We should call into Windows' native check to check if this path is a root once https://github.com/swiftlang/swift-foundation/issues/976 is fixed. // https://github.com/swiftlang/swift-format/issues/844 - return self.pathComponents.count == 1 + return self.pathComponents.count <= 1 #else // On Linux, we may end up with an string for the path due to https://github.com/swiftlang/swift-foundation/issues/980 // TODO: Remove the check for "" once https://github.com/swiftlang/swift-foundation/issues/980 is fixed.