Skip to content

Commit a6b026b

Browse files
committed
Tests: use FileManager instead of cp
Rather than relying on UNIX semantics of `cp` which is inherently platform dependent. This is required to start experimenting with getting the SPM test suite running on Windows.
1 parent 4fd61ba commit a6b026b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

IntegrationTests/Tests/IntegrationTests/Helpers.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ func fixture(
221221
if localFileSystem.isFile(fixtureDir.appending(component: "Package.swift")) {
222222
// It's a single package, so copy the whole directory as-is.
223223
let dstDir = tmpDirPath.appending(component: copyName)
224-
try systemQuietly("cp", "-R", "-H", fixtureDir.pathString, dstDir.pathString)
224+
try FileManager.default.copyItem(at: URL(fileURLWithPath: fixtureDir.pathString, isDirectory: true),
225+
to: URL(fileURLWithPath: dstDir.pathString, isDirectory: true))
225226

226227
// Invoke the block, passing it the path of the copied fixture.
227228
try body(dstDir)
@@ -231,7 +232,8 @@ func fixture(
231232
let srcDir = fixtureDir.appending(component: fileName)
232233
guard localFileSystem.isDirectory(srcDir) else { continue }
233234
let dstDir = tmpDirPath.appending(component: fileName)
234-
try systemQuietly("cp", "-R", "-H", srcDir.pathString, dstDir.pathString)
235+
try FileManager.default.copyItem(at: URL(fileURLWithPath: srcDir.pathString, isDirectory: true),
236+
to: URL(fileURLWithPath: dstDir.pathString, isDirectory: true))
235237
initGitRepo(dstDir, tag: "1.2.3", addFile: false)
236238
}
237239

Sources/SPMTestSupport/misc.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Basics
14+
import Foundation
1415
import OrderedCollections
1516
import PackageGraph
1617
import PackageLoading
@@ -69,7 +70,8 @@ public func fixture(
6970
if localFileSystem.isFile(fixtureDir.appending(component: "Package.swift")) {
7071
// It's a single package, so copy the whole directory as-is.
7172
let dstDir = tmpDirPath.appending(component: copyName)
72-
try systemQuietly("cp", "-R", "-H", fixtureDir.pathString, dstDir.pathString)
73+
try FileManager.default.copyItem(at: URL(fileURLWithPath: fixtureDir.pathString, isDirectory: true),
74+
to: URL(fileURLWithPath: dstDir.pathString, isDirectory: true))
7375

7476
// Invoke the block, passing it the path of the copied fixture.
7577
try body(dstDir)
@@ -79,7 +81,8 @@ public func fixture(
7981
let srcDir = fixtureDir.appending(component: fileName)
8082
guard localFileSystem.isDirectory(srcDir) else { continue }
8183
let dstDir = tmpDirPath.appending(component: fileName)
82-
try systemQuietly("cp", "-R", "-H", srcDir.pathString, dstDir.pathString)
84+
try FileManager.default.copyItem(at: URL(fileURLWithPath: srcDir.pathString, isDirectory: true),
85+
to: URL(fileURLWithPath: dstDir.pathString, isDirectory: true))
8386
if createGitRepo {
8487
initGitRepo(dstDir, tag: "1.2.3", addFile: false)
8588
}

0 commit comments

Comments
 (0)