Revert "Move workdirectory to NSFileManager extension."

This reverts commit f8f7c78de9.
This commit is contained in:
Kare Morstol
2015-02-27 23:52:56 +01:00
parent f8f7c78de9
commit 9e2d44682f
2 changed files with 16 additions and 19 deletions
+12 -15
View File
@@ -35,27 +35,24 @@ public let tempdirectory: String = {
return tempdirectory
}()
public extension NSFileManager {
/**
The current working directory.
/**
The current working directory.
Must be used instead of `run("cd ...")` because all the `run` commands are executed in a
separate process and changing the directory there will not affect the rest of the Swift script.
This directory is also used as the base for relative URL's.
*/
public var workdirectory: String {
get { return File.currentDirectoryPath }
set {
if !File.changeCurrentDirectoryPath(newValue) {
printErrorAndExit("Could not change the working directory to \(newValue)")
}
Must be used instead of `run("cd ...")` because all the `run` commands are executed in a
separate process and changing the directory there will not affect the rest of the Swift script.
This directory is also used as the base for relative URL's.
*/
public struct workdirectory {
public static func get() -> String { return File.currentDirectoryPath }
public static func set(newValue: String) {
if !File.changeCurrentDirectoryPath(newValue) {
printErrorAndExit("Could not change the working directory to \(newValue)")
}
}
}
/** Allows for `"/directory" / "file.extension"` etc. */
public func / (leftpath: String, rightpath: String) -> String {
return toURLOrError(leftpath).URLByAppendingPathComponent(rightpath).path!
+4 -4
View File
@@ -16,19 +16,19 @@ class Files_Tests: XCTestCase {
}
func testWorkDirectory_IsCurrentDirectory () {
XCTAssertEqual( File.workdirectory, NSFileManager.defaultManager().currentDirectoryPath )
XCTAssertEqual( workdirectory.get(), NSFileManager.defaultManager().currentDirectoryPath )
}
func testWorkDirectory_CanChange () {
File.workdirectory = ("/private/tmp")
workdirectory.set("/private/tmp")
XCTAssertEqual( File.workdirectory, "/private/tmp" )
XCTAssertEqual( workdirectory.get(), "/private/tmp" )
XCTAssertEqual( $("pwd"), "/private/tmp" )
}
func testURLConcatenationOperator () {
XCTAssertEqual( "/directory" / "file.extension", "/directory/file.extension" )
XCTAssertEqual( "/root" / "directory" / "file.extension", "/root/directory/file.extension" )
XCTAssertEqual( "directory" / "file.extension", File.workdirectory + "/directory/file.extension" )
XCTAssertEqual( "directory" / "file.extension", workdirectory.get() + "/directory/file.extension" )
}
}