Skip to content
This repository has been archived by the owner on Jan 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #115 from JohnSundell/arguments-with-space
Browse files Browse the repository at this point in the history
Support script arguments containing a space
  • Loading branch information
JohnSundell authored Aug 14, 2017
2 parents 765af24 + 06f7b1b commit 5c05891
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/MarathonCore/Script.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ internal final class Script {

func run(in executionFolder: Folder, with arguments: [String]) throws -> String {
let scriptPath = folder.path + ".build/debug/" + name
let command = scriptPath + " " + arguments.joined(separator: " ")
var command = scriptPath

if !arguments.isEmpty {
command += " \"" + arguments.joined(separator: "\" \"") + "\""
}

return try executionFolder.moveToAndPerform(command: command, printer: printer)
}

Expand Down
9 changes: 9 additions & 0 deletions Tests/MarathonTests/MarathonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ class MarathonTests: XCTestCase {
XCTAssertTrue(output.hasPrefix("🚘"))
}

func testRunningScriptWithArgumentContainingSpace() throws {
let scriptFile = try folder.createFile(named: "script.swift")
try scriptFile.write(string: "print(CommandLine.arguments[1])")

let output = try run(with: ["run", scriptFile.path, "Hello world"])
XCTAssertEqual(output, "Hello world")
}

// MARK: - Installing scripts

func testInstallingLocalScript() throws {
Expand Down Expand Up @@ -830,6 +838,7 @@ extension MarathonTests {
("testRunningScriptWithVerboseOutput", testRunningScriptWithVerboseOutput),
("testRunningRemoteScriptFromURL", testRunningRemoteScriptFromURL),
("testRunningRemoteScriptFromGitHubRepository", testRunningRemoteScriptFromGitHubRepository),
("testRunningScriptWithArgumentContainingSpace", testRunningScriptWithArgumentContainingSpace),
("testInstallingLocalScript", testInstallingLocalScript),
("testInstallingRemoteScriptWithDependenciesUsingRegularGithubURL", testInstallingRemoteScriptWithDependenciesUsingRegularGithubURL),
("testInstallingRemoteScriptWithDependenciesUsingRawGithubURL", testInstallingRemoteScriptWithDependenciesUsingRawGithubURL),
Expand Down

0 comments on commit 5c05891

Please sign in to comment.