Skip to content

Commit f1982b3

Browse files
committed
Make testCopyItemAtPathToPath deterministic
1 parent 92a25ec commit f1982b3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension FileManager {
3434
}
3535

3636
private struct DelegateCaptures : Equatable, Sendable {
37-
struct Operation : Equatable, CustomStringConvertible {
37+
struct Operation : Equatable, CustomStringConvertible, Comparable {
3838
let src: String
3939
let dst: String?
4040

@@ -45,6 +45,10 @@ private struct DelegateCaptures : Equatable, Sendable {
4545
"'\(src)'"
4646
}
4747
}
48+
49+
static func <(lhs: Operation, rhs: Operation) -> Bool {
50+
lhs.src < rhs.src || lhs.dst == nil || (rhs.dst != nil && lhs.dst! < rhs.dst!)
51+
}
4852

4953
init(_ src: String, _ dst: String? = nil) {
5054
self.src = src
@@ -507,9 +511,9 @@ final class FileManagerTests : XCTestCase {
507511
XCTAssertEqual($0.contents(atPath: "dir/foo"), data)
508512
XCTAssertEqual($0.contents(atPath: "dir2/foo"), data)
509513
#if os(Windows)
510-
XCTAssertEqual($0.delegateCaptures.shouldCopy, [.init("dir", "dir2"), .init("dir/bar", "dir2/bar"), .init("dir/foo", "dir2/foo")])
514+
XCTAssertEqual($0.delegateCaptures.shouldCopy.sorted(), [.init("dir", "dir2"), .init("dir/bar", "dir2/bar"), .init("dir/foo", "dir2/foo")].sorted())
511515
#else
512-
XCTAssertEqual($0.delegateCaptures.shouldCopy, [.init("dir", "dir2"), .init("dir/foo", "dir2/foo"), .init("dir/bar", "dir2/bar")])
516+
XCTAssertEqual($0.delegateCaptures.shouldCopy.sorted(), [.init("dir", "dir2"), .init("dir/foo", "dir2/foo"), .init("dir/bar", "dir2/bar")].sorted())
513517

514518
// Specifically for non-Windows (where copying directory metadata takes a special path) double check that the metadata was copied exactly
515519
XCTAssertEqual(try $0.attributesOfItem(atPath: "dir2")[.posixPermissions] as? UInt, 0o777)

0 commit comments

Comments
 (0)