Skip to content

Commit a410b36

Browse files
committed
Update tests
1 parent d5d6b22 commit a410b36

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

Sources/ShellOut.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import ShellQuote
4040
quoteArguments: Bool = true
4141
) throws -> String {
4242
guard !ShellQuote.hasUnsafeContent(command) else {
43-
throw ShellOutCommand.Error(message: "Command must not contain characters that require quoting.")
43+
throw ShellOutCommand.Error(message: "Command must not contain characters that require quoting, was: \(command)")
4444
}
4545
let arguments = quoteArguments ? arguments.map(ShellQuote.quote) : arguments
4646
let command = "cd \(path.escapingSpaces) && \(command) \(arguments.joined(separator: " "))"

Tests/ShellOutTests/ShellOutTests.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@ class ShellOutTests: XCTestCase {
1818
XCTAssertEqual(echo, "Hello world")
1919
}
2020

21-
func testWithInlineArguments() throws {
22-
let echo = try shellOut(to: "echo \"Hello world\"")
23-
XCTAssertEqual(echo, "Hello world")
24-
}
25-
2621
func testSingleCommandAtPath() throws {
27-
try shellOut(to: "echo \"Hello\" > \(NSTemporaryDirectory())ShellOutTests-SingleCommand.txt")
22+
try shellOut(to: "echo", arguments: [#"Hello" > \#(NSTemporaryDirectory())ShellOutTests-SingleCommand.txt"#])
2823

29-
let textFileContent = try shellOut(to: "cat ShellOutTests-SingleCommand.txt",
24+
let textFileContent = try shellOut(to: "cat",
25+
arguments: ["ShellOutTests-SingleCommand.txt"],
3026
at: NSTemporaryDirectory())
3127

3228
XCTAssertEqual(textFileContent, "Hello")
3329
}
3430

3531
func testSingleCommandAtPathContainingSpace() throws {
36-
try shellOut(to: "mkdir -p \"ShellOut Test Folder\"", at: NSTemporaryDirectory())
37-
try shellOut(to: "echo \"Hello\" > File", at: NSTemporaryDirectory() + "ShellOut Test Folder")
32+
try shellOut(to: "mkdir", arguments: ["-p", "ShellOut Test Folder"],
33+
at: NSTemporaryDirectory())
34+
try shellOut(to: "echo", arguments: ["Hello", ">", "File"],
35+
at: NSTemporaryDirectory() + "ShellOut Test Folder")
3836

39-
let output = try shellOut(to: "cat \(NSTemporaryDirectory())ShellOut\\ Test\\ Folder/File")
37+
let output = try shellOut(to: "cat",
38+
arguments: ["\(NSTemporaryDirectory())ShellOut Test Folder/File"])
4039
XCTAssertEqual(output, "Hello")
4140
}
4241

@@ -108,8 +107,8 @@ class ShellOutTests: XCTestCase {
108107
func testGitCommands() throws {
109108
// Setup & clear state
110109
let tempFolderPath = NSTemporaryDirectory()
111-
try shellOut(to: "rm -rf GitTestOrigin", at: tempFolderPath)
112-
try shellOut(to: "rm -rf GitTestClone", at: tempFolderPath)
110+
try shellOut(to: "rm", arguments: ["-rf", "GitTestOrigin"], at: tempFolderPath)
111+
try shellOut(to: "rm", arguments: ["-rf", "GitTestClone"], at: tempFolderPath)
113112

114113
// Create a origin repository and make a commit with a file
115114
let originPath = tempFolderPath + "/GitTestOrigin"
@@ -138,7 +137,9 @@ class ShellOutTests: XCTestCase {
138137
func testSwiftPackageManagerCommands() throws {
139138
// Setup & clear state
140139
let tempFolderPath = NSTemporaryDirectory()
141-
try shellOut(to: "rm -rf SwiftPackageManagerTest", at: tempFolderPath)
140+
try shellOut(to: "rm",
141+
arguments: ["-rf", "SwiftPackageManagerTest"],
142+
at: tempFolderPath)
142143
try shellOut(to: .createFolder(named: "SwiftPackageManagerTest"), at: tempFolderPath)
143144

144145
// Create a Swift package and verify that it has a Package.swift file

0 commit comments

Comments
 (0)