Skip to content

Commit 1e72780

Browse files
committed
Add a relative symlink to FileIteratorTests
1 parent 8068ff7 commit 1e72780

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Tests/SwiftFormatTests/Utilities/FileIteratorTests.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class FileIteratorTests: XCTestCase {
1818
try touch("project/.hidden.swift")
1919
try touch("project/.build/generated.swift")
2020
try symlink("project/link.swift", to: "project/.hidden.swift")
21+
try symlink("project/rellink.swift", relativeTo: ".hidden.swift")
2122
}
2223

2324
override func tearDownWithError() throws {
@@ -55,7 +56,10 @@ final class FileIteratorTests: XCTestCase {
5556
// passed to the iterator. This is meant to avoid situations where a symlink could be hidden by
5657
// shell expansion; for example, if the user writes `swift-format --no-follow-symlinks *`, if
5758
// the current directory contains a symlink, they would probably *not* expect it to be followed.
58-
let seen = allFilesSeen(iteratingOver: [tmpURL("project/link.swift")], followSymlinks: false)
59+
let seen = allFilesSeen(
60+
iteratingOver: [tmpURL("project/link.swift"), tmpURL("project/rellink.swift")],
61+
followSymlinks: false
62+
)
5963
XCTAssertTrue(seen.isEmpty)
6064
}
6165
}
@@ -81,14 +85,22 @@ extension FileIteratorTests {
8185
}
8286
}
8387

84-
/// Create a symlink between files or directories in the test's temporary space.
88+
/// Create a absolute symlink between files or directories in the test's temporary space.
8589
private func symlink(_ source: String, to target: String) throws {
8690
try FileManager.default.createSymbolicLink(
8791
at: tmpURL(source),
8892
withDestinationURL: tmpURL(target)
8993
)
9094
}
9195

96+
/// Create a relative symlink between files or directories in the test's temporary space.
97+
private func symlink(_ source: String, relativeTo target: String) throws {
98+
try FileManager.default.createSymbolicLink(
99+
atPath: tmpURL(source).path,
100+
withDestinationPath: target
101+
)
102+
}
103+
92104
/// Computes the list of all files seen by using `FileIterator` to iterate over the given URLs.
93105
private func allFilesSeen(iteratingOver urls: [URL], followSymlinks: Bool) -> [String] {
94106
let iterator = FileIterator(urls: urls, followSymlinks: followSymlinks)

0 commit comments

Comments
 (0)