Patterns such as `.*` or `@*` are matched against an item's own name with `fnmatch`, in the same places as excluded names: resolving a tree, extending a watch to a directory that appears later, and delivering events. Dependents that prune large trees can now skip whole families of directories without listing each name.
38 lines
1.4 KiB
Swift
38 lines
1.4 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import Inotify
|
|
|
|
@Suite("Directory Resolver")
|
|
struct DirectoryResolverTests {
|
|
@Test func listsDirectoryTree() async throws {
|
|
try await withTempDir { dir in
|
|
let subDirectory = "\(dir)/Subfolder/Folder 01"
|
|
try FileManager.default.createDirectory(atPath: subDirectory, withIntermediateDirectories: true)
|
|
let directories = try await DirectoryResolver.resolve(dir)
|
|
|
|
#expect(directories.count == 3)
|
|
#expect(directories.map { $0.description } == [dir, "\(dir)/Subfolder", subDirectory])
|
|
}
|
|
}
|
|
|
|
@Test func doesNotDescendIntoExcludedDirectories() async throws {
|
|
try await withTempDir { dir in
|
|
let excludedSubdirectory = "\(dir)/Excluded/Inside"
|
|
try FileManager.default.createDirectory(atPath: excludedSubdirectory, withIntermediateDirectories: true)
|
|
let directories = try await DirectoryResolver.resolve(dir, excluding: ["Excluded"])
|
|
|
|
#expect(directories.map { $0.description } == [dir])
|
|
}
|
|
}
|
|
|
|
@Test func doesNotDescendIntoDirectoriesMatchingAnExcludedPattern() async throws {
|
|
try await withTempDir { dir in
|
|
let excludedSubdirectory = "\(dir)/@eaDir/Inside"
|
|
try FileManager.default.createDirectory(atPath: excludedSubdirectory, withIntermediateDirectories: true)
|
|
let directories = try await DirectoryResolver.resolve([dir], excluding: ExclusionList(patterns: ["@*"]))
|
|
|
|
#expect(directories.map { $0.description } == [dir])
|
|
}
|
|
}
|
|
}
|