Skip to content

Fix compile failure on iOS for Mac Catalyst support #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2021
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
10 changes: 9 additions & 1 deletion Sources/ArgumentParserTestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ extension XCTest {
command: String,
expected: String? = nil,
exitCode: ExitCode = .success,
file: StaticString = #file, line: UInt = #line)
file: StaticString = #file, line: UInt = #line) throws
{
let splitCommand = command.split(separator: " ")
let arguments = splitCommand.dropFirst().map(String.init)
Expand All @@ -188,6 +188,7 @@ extension XCTest {
return
}

#if !canImport(Darwin) || os(macOS)
let process = Process()
if #available(macOS 10.13, *) {
process.executableURL = commandURL
Expand Down Expand Up @@ -222,6 +223,9 @@ extension XCTest {
}

XCTAssertEqual(process.terminationStatus, exitCode.rawValue, file: (file), line: line)
#else
throw XCTSkip("Not supported on this platform")
#endif
}

public func AssertJSONOutputEqual(
Expand All @@ -241,6 +245,7 @@ extension XCTest {
return
}

#if !canImport(Darwin) || os(macOS)
let process = Process()
if #available(macOS 10.13, *) {
process.executableURL = commandURL
Expand All @@ -267,5 +272,8 @@ extension XCTest {
let outputString = try XCTUnwrap(String(data: output.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8))
XCTAssertTrue(error.fileHandleForReading.readDataToEndOfFile().isEmpty, "Error occurred with `--experimental-dump-help`")
try AssertJSONEqualFromString(actual: outputString, expected: expected, for: ToolInfoV0.self)
#else
throw XCTSkip("Not supported on this platform")
#endif
}
}
78 changes: 39 additions & 39 deletions Tests/ArgumentParserExampleTests/MathExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import ArgumentParserTestHelpers

final class MathExampleTests: XCTestCase {
func testMath_Simple() throws {
AssertExecuteCommand(command: "math 1 2 3 4 5", expected: "15")
AssertExecuteCommand(command: "math multiply 1 2 3 4 5", expected: "120")
try AssertExecuteCommand(command: "math 1 2 3 4 5", expected: "15")
try AssertExecuteCommand(command: "math multiply 1 2 3 4 5", expected: "120")
}

func testMath_Help() throws {
Expand All @@ -37,9 +37,9 @@ final class MathExampleTests: XCTestCase {
See 'math help <subcommand>' for detailed help.
"""

AssertExecuteCommand(command: "math -h", expected: helpText)
AssertExecuteCommand(command: "math --help", expected: helpText)
AssertExecuteCommand(command: "math help", expected: helpText)
try AssertExecuteCommand(command: "math -h", expected: helpText)
try AssertExecuteCommand(command: "math --help", expected: helpText)
try AssertExecuteCommand(command: "math help", expected: helpText)
}

func testMath_AddHelp() throws {
Expand All @@ -57,14 +57,14 @@ final class MathExampleTests: XCTestCase {
-h, --help Show help information.
"""

AssertExecuteCommand(command: "math add -h", expected: helpText)
AssertExecuteCommand(command: "math add --help", expected: helpText)
AssertExecuteCommand(command: "math help add", expected: helpText)
try AssertExecuteCommand(command: "math add -h", expected: helpText)
try AssertExecuteCommand(command: "math add --help", expected: helpText)
try AssertExecuteCommand(command: "math help add", expected: helpText)

// Verify that extra help flags are ignored.
AssertExecuteCommand(command: "math help add -h", expected: helpText)
AssertExecuteCommand(command: "math help add -help", expected: helpText)
AssertExecuteCommand(command: "math help add --help", expected: helpText)
try AssertExecuteCommand(command: "math help add -h", expected: helpText)
try AssertExecuteCommand(command: "math help add -help", expected: helpText)
try AssertExecuteCommand(command: "math help add --help", expected: helpText)
}

func testMath_StatsMeanHelp() throws {
Expand All @@ -82,9 +82,9 @@ final class MathExampleTests: XCTestCase {
-h, --help Show help information.
"""

AssertExecuteCommand(command: "math stats average -h", expected: helpText)
AssertExecuteCommand(command: "math stats average --help", expected: helpText)
AssertExecuteCommand(command: "math help stats average", expected: helpText)
try AssertExecuteCommand(command: "math stats average -h", expected: helpText)
try AssertExecuteCommand(command: "math stats average --help", expected: helpText)
try AssertExecuteCommand(command: "math help stats average", expected: helpText)
}

func testMath_StatsQuantilesHelp() throws {
Expand All @@ -109,15 +109,15 @@ final class MathExampleTests: XCTestCase {

// The "quantiles" subcommand's run() method is unimplemented, so it
// just generates the help text.
AssertExecuteCommand(command: "math stats quantiles", expected: helpText)
try AssertExecuteCommand(command: "math stats quantiles", expected: helpText)

AssertExecuteCommand(command: "math stats quantiles -h", expected: helpText)
AssertExecuteCommand(command: "math stats quantiles --help", expected: helpText)
AssertExecuteCommand(command: "math help stats quantiles", expected: helpText)
try AssertExecuteCommand(command: "math stats quantiles -h", expected: helpText)
try AssertExecuteCommand(command: "math stats quantiles --help", expected: helpText)
try AssertExecuteCommand(command: "math help stats quantiles", expected: helpText)
}

func testMath_CustomValidation() throws {
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math stats average --kind mode",
expected: """
Error: Please provide at least one value to calculate the mode.
Expand All @@ -128,38 +128,38 @@ final class MathExampleTests: XCTestCase {
}

func testMath_Versions() throws {
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math --version",
expected: "1.0.0")
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math stats --version",
expected: "1.0.0")
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math stats average --version",
expected: "1.5.0-alpha")
}

func testMath_ExitCodes() throws {
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math stats quantiles --test-success-exit-code",
expected: "",
exitCode: .success)
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math stats quantiles --test-failure-exit-code",
expected: "",
exitCode: .failure)
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math stats quantiles --test-validation-exit-code",
expected: "",
exitCode: .validationFailure)
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math stats quantiles --test-custom-exit-code 42",
expected: "",
exitCode: ExitCode(42))
}

func testMath_Fail() throws {
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math --foo",
expected: """
Error: Unknown option '--foo'
Expand All @@ -168,7 +168,7 @@ final class MathExampleTests: XCTestCase {
""",
exitCode: .validationFailure)

AssertExecuteCommand(
try AssertExecuteCommand(
command: "math ZZZ",
expected: """
Error: The value 'ZZZ' is invalid for '<values>'
Expand All @@ -183,45 +183,45 @@ final class MathExampleTests: XCTestCase {
// MARK: - Completion Script

extension MathExampleTests {
func testMath_CompletionScript() {
AssertExecuteCommand(
func testMath_CompletionScript() throws {
try AssertExecuteCommand(
command: "math --generate-completion-script=bash",
expected: bashCompletionScriptText)
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math --generate-completion-script bash",
expected: bashCompletionScriptText)
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math --generate-completion-script=zsh",
expected: zshCompletionScriptText)
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math --generate-completion-script zsh",
expected: zshCompletionScriptText)
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math --generate-completion-script=fish",
expected: fishCompletionScriptText)
AssertExecuteCommand(
try AssertExecuteCommand(
command: "math --generate-completion-script fish",
expected: fishCompletionScriptText)
}

func testMath_CustomCompletion() {
AssertExecuteCommand(
func testMath_CustomCompletion() throws {
try AssertExecuteCommand(
command: "math ---completion stats quantiles -- --custom",
expected: """
hello
helicopter
heliotrope
""")

AssertExecuteCommand(
try AssertExecuteCommand(
command: "math ---completion stats quantiles -- --custom h",
expected: """
hello
helicopter
heliotrope
""")

AssertExecuteCommand(
try AssertExecuteCommand(
command: "math ---completion stats quantiles -- --custom a",
expected: """
aardvark
Expand Down
14 changes: 7 additions & 7 deletions Tests/ArgumentParserExampleTests/RepeatExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ArgumentParserTestHelpers

final class RepeatExampleTests: XCTestCase {
func testRepeat() throws {
AssertExecuteCommand(command: "repeat hello --count 6", expected: """
try AssertExecuteCommand(command: "repeat hello --count 6", expected: """
hello
hello
hello
Expand All @@ -38,12 +38,12 @@ final class RepeatExampleTests: XCTestCase {
-h, --help Show help information.
"""

AssertExecuteCommand(command: "repeat -h", expected: helpText)
AssertExecuteCommand(command: "repeat --help", expected: helpText)
try AssertExecuteCommand(command: "repeat -h", expected: helpText)
try AssertExecuteCommand(command: "repeat --help", expected: helpText)
}

func testRepeat_Fail() throws {
AssertExecuteCommand(
try AssertExecuteCommand(
command: "repeat",
expected: """
Error: Missing expected argument '<phrase>'
Expand All @@ -60,7 +60,7 @@ final class RepeatExampleTests: XCTestCase {
""",
exitCode: .validationFailure)

AssertExecuteCommand(
try AssertExecuteCommand(
command: "repeat hello --count",
expected: """
Error: Missing value for '--count <count>'
Expand All @@ -70,7 +70,7 @@ final class RepeatExampleTests: XCTestCase {
""",
exitCode: .validationFailure)

AssertExecuteCommand(
try AssertExecuteCommand(
command: "repeat hello --count ZZZ",
expected: """
Error: The value 'ZZZ' is invalid for '--count <count>'
Expand All @@ -80,7 +80,7 @@ final class RepeatExampleTests: XCTestCase {
""",
exitCode: .validationFailure)

AssertExecuteCommand(
try AssertExecuteCommand(
command: "repeat --version hello",
expected: """
Error: Unknown option '--version'
Expand Down
10 changes: 5 additions & 5 deletions Tests/ArgumentParserExampleTests/RollDiceExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ArgumentParserTestHelpers

final class RollDiceExampleTests: XCTestCase {
func testRollDice() throws {
AssertExecuteCommand(command: "roll --times 6")
try AssertExecuteCommand(command: "roll --times 6")
}

func testRollDice_Help() throws {
Expand All @@ -31,12 +31,12 @@ final class RollDiceExampleTests: XCTestCase {
-h, --help Show help information.
"""

AssertExecuteCommand(command: "roll -h", expected: helpText)
AssertExecuteCommand(command: "roll --help", expected: helpText)
try AssertExecuteCommand(command: "roll -h", expected: helpText)
try AssertExecuteCommand(command: "roll --help", expected: helpText)
}

func testRollDice_Fail() throws {
AssertExecuteCommand(
try AssertExecuteCommand(
command: "roll --times",
expected: """
Error: Missing value for '--times <n>'
Expand All @@ -46,7 +46,7 @@ final class RollDiceExampleTests: XCTestCase {
""",
exitCode: .validationFailure)

AssertExecuteCommand(
try AssertExecuteCommand(
command: "roll --times ZZZ",
expected: """
Error: The value 'ZZZ' is invalid for '--times <n>'
Expand Down