Skip to content

Commit 3da34d6

Browse files
Port Spectest for Windows
1 parent 45a723e commit 3da34d6

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

Sources/Spectest/Spectest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct Spectest: AsyncParsableCommand {
4141

4242
let rootPath: String
4343
let filePath = FilePath(path)
44-
if (try? FileDescriptor.open(filePath, FileDescriptor.AccessMode.readOnly, options: .directory)) != nil {
44+
if isDirectory(filePath) {
4545
rootPath = path
4646
} else {
4747
rootPath = URL(fileURLWithPath: path).deletingLastPathComponent().path

Sources/Spectest/TestCase.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ struct TestCase {
7979
let content: Content
8080
let path: String
8181

82-
private static func isDirectory(_ path: FilePath) -> Bool {
83-
let fd = try? FileDescriptor.open(path, FileDescriptor.AccessMode.readOnly, options: .directory)
84-
let isDirectory = fd != nil
85-
try? fd?.close()
86-
return isDirectory
87-
}
88-
8982
static func load(include: [String], exclude: [String], in path: String, log: ((String) -> Void)? = nil) throws -> [TestCase] {
9083
let fileManager = FileManager.default
9184
let filePath = FilePath(path)
@@ -563,3 +556,20 @@ extension Swift.Error {
563556
return "unknown error: \(self)"
564557
}
565558
}
559+
560+
#if os(Windows)
561+
import WinSDK
562+
#endif
563+
internal func isDirectory(_ path: FilePath) -> Bool {
564+
#if os(Windows)
565+
return path.withPlatformString {
566+
let result = GetFileAttributesW($0)
567+
return result != INVALID_FILE_ATTRIBUTES && result & DWORD(FILE_ATTRIBUTE_DIRECTORY) != 0
568+
}
569+
#else
570+
let fd = try? FileDescriptor.open(path, FileDescriptor.AccessMode.readOnly, options: .directory)
571+
let isDirectory = fd != nil
572+
try? fd?.close()
573+
return isDirectory
574+
#endif
575+
}

0 commit comments

Comments
 (0)