Skip to content

Commit 8139a39

Browse files
committed
wip tests
1 parent ae57151 commit 8139a39

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

Sources/System/FileStatus/FileStatusOperations.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
extension FileDescriptor {
1616
public struct ControlFlags {
1717
let rawValue: Int32
18+
// Test stub
19+
public static var none: ControlFlags = ControlFlags(rawValue: 0)
1820
// Out of scope of this sketch
1921
}
2022
}
@@ -63,7 +65,7 @@ extension FilePath {
6365
retryOnInterrupt: Bool
6466
) -> Result<FileStatus, Errno> {
6567
var result = CInterop.Stat()
66-
let fn = followSymlinks ? system_stat : system_lstat
68+
let fn = followSymlinks ? system_lstat : system_stat
6769
return withPlatformString { ptr in
6870
nothingOrErrno(retryOnInterrupt: retryOnInterrupt) {
6971
fn(ptr, &result)
@@ -177,7 +179,7 @@ extension FilePath {
177179
followSymlinks: Bool,
178180
retryOnInterrupt: Bool
179181
) -> Result<Void, Errno> {
180-
let _chmod = followSymlinks ? system_chmod : system_lchmod
182+
let _chmod = followSymlinks ? system_lchmod : system_chmod
181183
return withPlatformString { ptr in
182184
nothingOrErrno(retryOnInterrupt: retryOnInterrupt) {
183185
_chmod(ptr, permissions.rawValue)
@@ -272,7 +274,7 @@ extension FilePath {
272274
followSymlinks: Bool,
273275
retryOnInterrupt: Bool
274276
) -> Result<Void, Errno> {
275-
let _chown = followSymlinks ? system_chown : system_lchown
277+
let _chown = followSymlinks ? system_lchown : system_chown
276278
return withPlatformString { ptr in
277279
nothingOrErrno(retryOnInterrupt: retryOnInterrupt) {
278280
_chown(ptr, userID, groupID)
@@ -368,7 +370,7 @@ extension FilePath {
368370
followSymlinks: Bool,
369371
retryOnInterrupt: Bool
370372
) -> Result<Void, Errno> {
371-
let _chflags = followSymlinks ? system_chflags : system_lchflags
373+
let _chflags = followSymlinks ? system_lchflags : system_chflags
372374
return withPlatformString { ptr in
373375
nothingOrErrno(retryOnInterrupt: retryOnInterrupt) {
374376
_chflags(ptr, flags.rawValue)

Tests/SystemTests/FileOperationsTest.swift

+45-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ final class FileOperationsTest: XCTestCase {
2828
let writeBuf = UnsafeRawBufferPointer(rawBuf)
2929
let writeBufAddr = writeBuf.baseAddress
3030

31-
let syscallTestCases: Array<MockTestCase> = [
31+
var syscallTestCases: Array<MockTestCase> = []
32+
syscallTestCases += [
3233
MockTestCase(name: "open", .interruptable, "a path", O_RDWR | O_APPEND) {
3334
retryOnInterrupt in
3435
_ = try FileDescriptor.open(
@@ -83,6 +84,49 @@ final class FileOperationsTest: XCTestCase {
8384
},
8485
]
8586

87+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
88+
let fp = FilePath("/")
89+
let rawFP = fp.withPlatformString { strdup($0) }
90+
defer { free(rawFP) }
91+
92+
let stat = UnsafeMutablePointer<stat>.allocate(capacity: 1)
93+
defer { stat.deallocate() }
94+
95+
syscallTestCases += [
96+
// MockTestCase(name: "stat", .interruptable, rawFP) { retryOnInterrupt in
97+
// _ = try fp.stat(followSymlinks: false, retryOnInterrupt: retryOnInterrupt)
98+
// },
99+
// MockTestCase(name: "lstat", .interruptable, rawFP) { retryOnInterrupt in
100+
// _ = try fp.stat(followSymlinks: true, retryOnInterrupt: retryOnInterrupt)
101+
// },
102+
// MockTestCase(name: "fstat", .interruptable, rawFP) { retryOnInterrupt in
103+
// _ = try fd.stat(retryOnInterrupt: retryOnInterrupt)
104+
// },
105+
// MockTestCase(name: "fstatat", .interruptable, rawFP) { retryOnInterrupt in
106+
// _ = try fp.stat(relativeTo: fd, fcntrl: .none, retryOnInterrupt: retryOnInterrupt)
107+
// },
108+
// fstatat
109+
// chmod
110+
// lchmod
111+
// fchmod
112+
// fchmodat
113+
// chown
114+
// lchown
115+
// fchown
116+
// fchownat
117+
// chflags
118+
// lchflags
119+
// fchflags
120+
// umask
121+
// mkfifo
122+
// mknod
123+
// mkdir
124+
// mkdirat
125+
// futimens
126+
// utimensat
127+
]
128+
#endif
129+
86130
for test in syscallTestCases { test.runAllTests() }
87131
}
88132

0 commit comments

Comments
 (0)