Revert "Move workdirectory to NSFileManager extension."
This reverts commit f8f7c78de9.
This commit is contained in:
+12
-15
@@ -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!
|
||||
|
||||
@@ -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" )
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user