Skip to content

Commit fec0d2b

Browse files
committed
Fix file copying tests when running on a filesystem without xattr support
This is often the case with virtual machine shared folders.
1 parent e7b46ac commit fec0d2b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Tests/SWBTaskExecutionTests/FileCopyTaskTests.swift

+26
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ fileprivate struct FileCopyTaskTests {
2323
try await withTemporaryDirectory { tmpDir in
2424
let testDataDirPath = try Path(#require(Bundle.module.resourceURL).appendingPathComponent("TestData").appendingPathComponent("FileCopyTask").path)
2525

26+
// Many filesystems on other platforms (e.g. various non-ext4 temporary filesystems on Linux) don't support xattrs and will return ENOTSUP.
27+
// In particular, tmpfs doesn't support xattrs on Linux unless `CONFIG_TMPFS_XATTR` is enabled in the kernel config.
28+
if try ProcessInfo.processInfo.hostOperatingSystem() == .linux {
29+
do {
30+
_ = try localFS.getExtendedAttribute(testDataDirPath, key: "user.test")
31+
} catch let error as SWBUtil.POSIXError where error.code == ENOTSUP {
32+
return
33+
}
34+
}
35+
2636
// Set up the copy task and run it.
2737
let action = FileCopyTaskAction(.init(skipAppStoreDeployment: false, stubPartialCompilerCommandLine: [], stubPartialLinkerCommandLine: [], stubPartialLipoCommandLine: [], partialTargetValues: [], llvmTargetTripleOSVersion: "", llvmTargetTripleSuffix: "", platformName: "", swiftPlatformTargetPrefix: "", isMacCatalyst: false))
2838
let task = Task(forTarget: nil, ruleInfo: [], commandLine: ["builtin-copy", testDataDirPath.join("LoneFile.txt").str, tmpDir.str], workingDirectory: testDataDirPath, outputs: [], action: action, execDescription: "Copy File")
@@ -36,6 +46,9 @@ fileprivate struct FileCopyTaskTests {
3646
outputDelegate: outputDelegate
3747
)
3848

49+
#expect(outputDelegate.errors == [])
50+
#expect(outputDelegate.warnings == [])
51+
3952
// Make sure it completed successfully.
4053
#expect(result == .succeeded)
4154

@@ -49,6 +62,16 @@ fileprivate struct FileCopyTaskTests {
4962
try await withTemporaryDirectory { tmpDir in
5063
let testDataDirPath = try Path(#require(Bundle.module.resourceURL).appendingPathComponent("TestData").appendingPathComponent("FileCopyTask").path)
5164

65+
// Many filesystems on other platforms (e.g. various non-ext4 temporary filesystems on Linux) don't support xattrs and will return ENOTSUP.
66+
// In particular, tmpfs doesn't support xattrs on Linux unless `CONFIG_TMPFS_XATTR` is enabled in the kernel config.
67+
if try ProcessInfo.processInfo.hostOperatingSystem() == .linux {
68+
do {
69+
_ = try localFS.getExtendedAttribute(testDataDirPath, key: "user.test")
70+
} catch let error as SWBUtil.POSIXError where error.code == ENOTSUP {
71+
return
72+
}
73+
}
74+
5275
// Set up the copy task and run it.
5376
let action = FileCopyTaskAction(.init(skipAppStoreDeployment: false, stubPartialCompilerCommandLine: [], stubPartialLinkerCommandLine: [], stubPartialLipoCommandLine: [], partialTargetValues: [], llvmTargetTripleOSVersion: "", llvmTargetTripleSuffix: "", platformName: "", swiftPlatformTargetPrefix: "", isMacCatalyst: false))
5477
let task = Task(forTarget: nil, ruleInfo: [], commandLine: ["builtin-copy", testDataDirPath.join("SimpleDir").str, tmpDir.str], workingDirectory: testDataDirPath, outputs: [], action: action, execDescription: "Copy Directory")
@@ -62,6 +85,9 @@ fileprivate struct FileCopyTaskTests {
6285
outputDelegate: outputDelegate
6386
)
6487

88+
#expect(outputDelegate.errors == [])
89+
#expect(outputDelegate.warnings == [])
90+
6591
// Make sure it completed successfully.
6692
#expect(result == .succeeded)
6793

0 commit comments

Comments
 (0)