Skip to content

Commit 33d4d8e

Browse files
committed
added some tests
1 parent 0914671 commit 33d4d8e

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

Tests/TSCBasicTests/FileSystemTests.swift

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,37 @@ class FileSystemTests: XCTestCase {
374374
XCTAssert(fs.exists(filePath) && !fs.isDirectory(filePath))
375375
}
376376

377+
func testInMemoryCreateSymlink() throws {
378+
let fs = InMemoryFileSystem()
379+
let path = fs.homeDirectory
380+
try fs.createDirectory(path, recursive: true)
381+
382+
let source = path.appending(component: "source")
383+
let target = path.appending(component: "target")
384+
try fs.writeFileContents(target, bytes: "source")
385+
386+
// Source and target exist.
387+
388+
try fs.createSymbolicLink(source, pointingAt: target)
389+
XCTAssertEqual(fs.exists(source), true)
390+
XCTAssertEqual(fs.exists(source, followSymlink: true), true)
391+
XCTAssertEqual(fs.exists(source, followSymlink: false), true)
392+
393+
// Source only exists.
394+
395+
try fs.removeFileTree(target)
396+
XCTAssertEqual(fs.exists(source), false)
397+
XCTAssertEqual(fs.exists(source, followSymlink: true), false)
398+
XCTAssertEqual(fs.exists(source, followSymlink: false), true)
399+
400+
// None exist.
401+
402+
try fs.removeFileTree(source)
403+
XCTAssertEqual(fs.exists(source), false)
404+
XCTAssertEqual(fs.exists(source, followSymlink: true), false)
405+
XCTAssertEqual(fs.exists(source, followSymlink: false), false)
406+
}
407+
377408
func testInMemoryReadWriteFile() {
378409
let fs = InMemoryFileSystem()
379410
try! fs.createDirectory(AbsolutePath("/new-dir/subdir"), recursive: true)
@@ -550,6 +581,43 @@ class FileSystemTests: XCTestCase {
550581
XCTAssert(baseFileSystem.isDirectory(AbsolutePath("/base/rootIsHere/subdir2")))
551582
}
552583

584+
func testRootedCreateSymlink() throws {
585+
// Create the test file system.
586+
let baseFileSystem = InMemoryFileSystem() as FileSystem
587+
try baseFileSystem.createDirectory(AbsolutePath("/base/rootIsHere/subdir"), recursive: true)
588+
589+
// Create the rooted file system.
590+
let fs = RerootedFileSystemView(baseFileSystem, rootedAt: AbsolutePath("/base/rootIsHere"))
591+
592+
let path = AbsolutePath("/test")
593+
try fs.createDirectory(path, recursive: true)
594+
595+
let source = path.appending(component: "source")
596+
let target = path.appending(component: "target")
597+
try fs.writeFileContents(target, bytes: "source")
598+
599+
// Source and target exist.
600+
601+
try fs.createSymbolicLink(source, pointingAt: target)
602+
XCTAssertEqual(fs.exists(source), true)
603+
XCTAssertEqual(fs.exists(source, followSymlink: true), true)
604+
XCTAssertEqual(fs.exists(source, followSymlink: false), true)
605+
606+
// Source only exists.
607+
608+
try fs.removeFileTree(target)
609+
XCTAssertEqual(fs.exists(source), false)
610+
XCTAssertEqual(fs.exists(source, followSymlink: true), false)
611+
XCTAssertEqual(fs.exists(source, followSymlink: false), true)
612+
613+
// None exist.
614+
615+
try fs.removeFileTree(source)
616+
XCTAssertEqual(fs.exists(source), false)
617+
XCTAssertEqual(fs.exists(source, followSymlink: true), false)
618+
XCTAssertEqual(fs.exists(source, followSymlink: false), false)
619+
}
620+
553621
func testSetAttribute() throws {
554622
#if os(macOS) || os(Linux) || os(Android)
555623
try testWithTemporaryDirectory { tmpdir in

0 commit comments

Comments
 (0)