From 80d88137b442089ecc6e66334209da1313799baa Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Sat, 4 May 2024 22:47:30 +0100 Subject: [PATCH] Fix filesystem test on macOS (#466) It looks like we end up with `EEXISTS` here on newer versions of macOS. Co-authored-by: Boris Buegling --- Sources/TSCBasic/FileSystem.swift | 2 ++ Tests/TSCBasicTests/FileSystemTests.swift | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/TSCBasic/FileSystem.swift b/Sources/TSCBasic/FileSystem.swift index b33b1c61..982a8039 100644 --- a/Sources/TSCBasic/FileSystem.swift +++ b/Sources/TSCBasic/FileSystem.swift @@ -104,6 +104,8 @@ public extension FileSystemError { self.init(.noEntry, path) case TSCLibc.ENOTDIR: self.init(.notDirectory, path) + case TSCLibc.EEXIST: + self.init(.alreadyExistsAtDestination, path) default: self.init(.ioError(code: errno), path) } diff --git a/Tests/TSCBasicTests/FileSystemTests.swift b/Tests/TSCBasicTests/FileSystemTests.swift index 29430b91..07c55cac 100644 --- a/Tests/TSCBasicTests/FileSystemTests.swift +++ b/Tests/TSCBasicTests/FileSystemTests.swift @@ -331,7 +331,13 @@ class FileSystemTests: XCTestCase { _ = try fs.readFileContents(root) } - XCTAssertThrows(FileSystemError(.isDirectory, root)) { + #if os(macOS) + // Newer versions of macOS end up with `EEXISTS` instead of `EISDIR` here. + let expectedError = FileSystemError(.alreadyExistsAtDestination, root) + #else + let expectedError = FileSystemError(.isDirectory, root) + #endif + XCTAssertThrows(expectedError) { try fs.writeFileContents(root, bytes: []) } XCTAssert(fs.exists(filePath))