Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

working directory support #37

Merged
merged 2 commits into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/Core/WorkingDirectory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// This function will attempt to get the current
/// working directory of the application
public func workingDirectory() -> String {
let file = #file
let directory: String?
if file.contains(".build") {
directory = file.components(separatedBy: "/.build").first
} else {
directory = file.components(separatedBy: "/Sources").first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also have one for Packages. This is used in 3.1 when you do swift package edit

}
return directory?.finished(with: "/") ?? "./"
}
9 changes: 9 additions & 0 deletions Tests/CoreTests/UtilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class UtilityTests: XCTestCase {
("testLowercase", testLowercase),
("testUppercase", testUppercase),
("testIntHex", testIntHex),
("testWorkDir", testWorkDir)
]

func testLowercase() {
Expand Down Expand Up @@ -36,4 +37,12 @@ class UtilityTests: XCTestCase {
let unsignedHex = Byte(125).hex
XCTAssertEqual(unsignedHex, "7D")
}

func testWorkDir() {
let file = #file

let workDir = workingDirectory()
XCTAssert(file.hasPrefix(workDir))
XCTAssertNotEqual(workDir, file)
}
}