Skip to content

Commit 2db87df

Browse files
authored
Fix FreeBSD tests (#1122)
* fix test on FreeBSD * Make `testCopyItemAtPathToPath` deterministic * Always test copying directory first
1 parent 7aacaff commit 2db87df

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift

+8-2
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
@@ -509,7 +513,9 @@ final class FileManagerTests : XCTestCase {
509513
#if os(Windows)
510514
XCTAssertEqual($0.delegateCaptures.shouldCopy, [.init("dir", "dir2"), .init("dir/bar", "dir2/bar"), .init("dir/foo", "dir2/foo")])
511515
#else
512-
XCTAssertEqual($0.delegateCaptures.shouldCopy, [.init("dir", "dir2"), .init("dir/foo", "dir2/foo"), .init("dir/bar", "dir2/bar")])
516+
var shouldCopy = $0.delegateCaptures.shouldCopy
517+
XCTAssertEqual(shouldCopy.removeFirst(), .init("dir", "dir2"))
518+
XCTAssertEqual(shouldCopy.sorted(), [.init("dir/foo", "dir2/foo"), .init("dir/bar", "dir2/bar")].sorted())
513519

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

Tests/FoundationEssentialsTests/ProcessInfoTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ final class ProcessInfoTests : XCTestCase {
171171
func testProcessName() {
172172
#if FOUNDATION_FRAMEWORK
173173
let targetName = "TestHost"
174-
#elseif os(Linux) || os(Windows) || os(Android)
174+
#elseif os(Linux) || os(Windows) || os(Android) || os(FreeBSD)
175175
let targetName = "swift-foundationPackageTests.xctest"
176176
#else
177177
let targetName = "xctest"

0 commit comments

Comments
 (0)