Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions Sources/ArgumentParser/Usage/DumpHelpGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ internal struct DumpHelpGenerator {
func rendered() -> String {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
if #available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *) {
encoder.outputFormatting.insert(.sortedKeys)
}
encoder.outputFormatting.insert(.sortedKeys)
guard let encoded = try? encoder.encode(self.toolInfo) else { return "" }
return String(data: encoded, encoding: .utf8) ?? ""
}
Expand Down
28 changes: 9 additions & 19 deletions Sources/ArgumentParserTestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,25 +350,17 @@ extension XCTest {

#if !canImport(Darwin) || os(macOS)
let process = Process()
if #available(macOS 10.13, *) {
process.executableURL = commandURL
} else {
process.launchPath = commandURL.path
}
process.executableURL = commandURL
process.arguments = arguments

let output = Pipe()
process.standardOutput = output
let error = Pipe()
process.standardError = error

if #available(macOS 10.13, *) {
guard (try? process.run()) != nil else {
XCTFail("Couldn't run command process.", file: file, line: line)
return ""
}
} else {
process.launch()
guard (try? process.run()) != nil else {
XCTFail("Couldn't run command process.", file: file, line: line)
return ""
}
process.waitUntilExit()

Expand Down Expand Up @@ -401,13 +393,11 @@ extension XCTest {
actual: String, expected: String, for type: T.Type,
file: StaticString = #filePath, line: UInt = #line
) throws {
if #available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *) {
AssertEqualStrings(
actual: actual.trimmingCharacters(in: .whitespacesAndNewlines),
expected: expected.trimmingCharacters(in: .whitespacesAndNewlines),
file: file,
line: line)
}
AssertEqualStrings(
actual: actual.trimmingCharacters(in: .whitespacesAndNewlines),
expected: expected.trimmingCharacters(in: .whitespacesAndNewlines),
file: file,
line: line)

let actualJSONData = try XCTUnwrap(
actual.data(using: .utf8), file: file, line: line)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@ func executeCommand(
process.standardOutput = output
process.standardError = FileHandle.nullDevice

if #available(macOS 10.13, *) {
do {
try process.run()
} catch {
throw SubprocessError.failedToLaunch(error: error)
}
} else {
process.launch()
do {
try process.run()
} catch {
throw SubprocessError.failedToLaunch(error: error)
}
let outputData = output.fileHandleForReading.readDataToEndOfFile()
process.waitUntilExit()
Expand Down
18 changes: 5 additions & 13 deletions Tools/generate-manual/Extensions/Process+SimpleAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,18 @@ func executeCommand(
}

let process = Process()
if #available(macOS 10.13, *) {
process.executableURL = executable
} else {
process.launchPath = executable.path
}
process.executableURL = executable
process.arguments = arguments

let output = Pipe()
process.standardOutput = output
let error = Pipe()
process.standardError = error

if #available(macOS 10.13, *) {
do {
try process.run()
} catch {
throw SubprocessError.failedToLaunch(error: error)
}
} else {
process.launch()
do {
try process.run()
} catch {
throw SubprocessError.failedToLaunch(error: error)
}
let outputData = output.fileHandleForReading.readDataToEndOfFile()
let errorData = error.fileHandleForReading.readDataToEndOfFile()
Expand Down