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
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
//
// This source file is part of the Swift Argument Parser open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

import ArgumentParser
import XCTest
import Testing

final class AsyncCommandEndToEndTests: XCTestCase {}
@Suite(.serialized) struct AsyncCommandEndToEndTests {}

actor AsyncStatusCheck {
struct Status: OptionSet {
Expand Down Expand Up @@ -55,17 +55,15 @@ struct AsyncCommand: AsyncParsableCommand {
// swift-format-ignore: AlwaysUseLowerCamelCase
// https://github.com/apple/swift-argument-parser/issues/710
extension AsyncCommandEndToEndTests {
@MainActor
func testAsyncMain_root() async throws {
XCTAssertFalse(statusCheck.status.contains(.root))
@Test @MainActor func asyncMain_root() async throws {
#expect(!statusCheck.status.contains(.root))
await AsyncCommand.main([])
XCTAssertTrue(statusCheck.status.contains(.root))
#expect(statusCheck.status.contains(.root))
}

@MainActor
func testAsyncMain_sub() async throws {
XCTAssertFalse(statusCheck.status.contains(.sub))
@Test @MainActor func asyncMain_sub() async throws {
#expect(!statusCheck.status.contains(.sub))
await AsyncCommand.main(["sub-command"])
XCTAssertTrue(statusCheck.status.contains(.sub))
#expect(statusCheck.status.contains(.sub))
}
}
77 changes: 42 additions & 35 deletions Tests/ArgumentParserEndToEndTests/EnumEndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Argument Parser open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand All @@ -12,9 +12,8 @@
import ArgumentParser
import ArgumentParserTestHelpers
import Testing
import XCTest

final class EnumEndToEndTests: XCTestCase {}
@Suite struct EnumEndToEndTests {}

// MARK: -

Expand All @@ -31,26 +30,26 @@ private struct Bar: ParsableArguments {
// swift-format-ignore: AlwaysUseLowerCamelCase
// https://github.com/apple/swift-argument-parser/issues/710
extension EnumEndToEndTests {
func testParsing_SingleOption() throws {
AssertParse(Bar.self, ["--index", "hello"]) { bar in
XCTAssertEqual(bar.index, Bar.Index.hello)
@Test func parsing_SingleOption() throws {
expectParse(Bar.self, ["--index", "hello"]) { bar in
#expect(bar.index == Bar.Index.hello)
}
AssertParse(Bar.self, ["--index", "goodbye"]) { bar in
XCTAssertEqual(bar.index, Bar.Index.goodbye)
expectParse(Bar.self, ["--index", "goodbye"]) { bar in
#expect(bar.index == Bar.Index.goodbye)
}
}

func testParsing_SingleOptionMultipleTimes() throws {
AssertParse(Bar.self, ["--index", "hello", "--index", "goodbye"]) { bar in
XCTAssertEqual(bar.index, Bar.Index.goodbye)
@Test func parsing_SingleOptionMultipleTimes() throws {
expectParse(Bar.self, ["--index", "hello", "--index", "goodbye"]) { bar in
#expect(bar.index == Bar.Index.goodbye)
}
}

func testParsing_SingleOption_Fails() throws {
XCTAssertThrowsError(try Bar.parse([]))
XCTAssertThrowsError(try Bar.parse(["--index"]))
XCTAssertThrowsError(try Bar.parse(["--index", "hell"]))
XCTAssertThrowsError(try Bar.parse(["--index", "helloo"]))
@Test func parsing_SingleOption_Fails() throws {
#expect(throws: (any Error).self) { try Bar.parse([]) }
#expect(throws: (any Error).self) { try Bar.parse(["--index"]) }
#expect(throws: (any Error).self) { try Bar.parse(["--index", "hell"]) }
#expect(throws: (any Error).self) { try Bar.parse(["--index", "helloo"]) }
}
}

Expand All @@ -69,32 +68,40 @@ private struct Baz: ParsableArguments {
// swift-format-ignore: AlwaysUseLowerCamelCase
// https://github.com/apple/swift-argument-parser/issues/710
extension EnumEndToEndTests {
func test_ParsingRawValue_Option() throws {
AssertParse(Baz.self, ["--mode", "generate-bash-script"]) { baz in
XCTAssertEqual(baz.modeOption, .generateBashScript)
XCTAssertNil(baz.modeArg)
@Test func parsingRawValue_Option() throws {
expectParse(Baz.self, ["--mode", "generate-bash-script"]) { baz in
#expect(baz.modeOption == .generateBashScript)
#expect(baz.modeArg == nil)
}
AssertParse(Baz.self, ["--mode", "generateZshScript"]) { baz in
XCTAssertEqual(baz.modeOption, .generateZshScript)
XCTAssertNil(baz.modeArg)
expectParse(Baz.self, ["--mode", "generateZshScript"]) { baz in
#expect(baz.modeOption == .generateZshScript)
#expect(baz.modeArg == nil)
}
}

func test_ParsingRawValue_Argument() throws {
AssertParse(Baz.self, ["generate-bash-script"]) { baz in
XCTAssertEqual(baz.modeArg, .generateBashScript)
XCTAssertNil(baz.modeOption)
@Test func parsingRawValue_Argument() throws {
expectParse(Baz.self, ["generate-bash-script"]) { baz in
#expect(baz.modeArg == .generateBashScript)
#expect(baz.modeOption == nil)
}
AssertParse(Baz.self, ["generateZshScript"]) { baz in
XCTAssertEqual(baz.modeArg, .generateZshScript)
XCTAssertNil(baz.modeOption)
expectParse(Baz.self, ["generateZshScript"]) { baz in
#expect(baz.modeArg == .generateZshScript)
#expect(baz.modeOption == nil)
}
}

func test_ParsingRawValue_Fails() throws {
XCTAssertThrowsError(try Baz.parse(["generateBashScript"]))
XCTAssertThrowsError(try Baz.parse(["--mode generateBashScript"]))
XCTAssertThrowsError(try Baz.parse(["generate-zsh-script"]))
XCTAssertThrowsError(try Baz.parse(["--mode generate-zsh-script"]))
@Test func parsingRawValue_Fails() throws {
#expect(throws: (any Error).self) {
try Baz.parse(["generateBashScript"])
}
#expect(throws: (any Error).self) {
try Baz.parse(["--mode generateBashScript"])
}
#expect(throws: (any Error).self) {
try Baz.parse(["generate-zsh-script"])
}
#expect(throws: (any Error).self) {
try Baz.parse(["--mode generate-zsh-script"])
}
}
}
45 changes: 22 additions & 23 deletions Tests/ArgumentParserEndToEndTests/EqualsEndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Argument Parser open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand All @@ -12,9 +12,8 @@
import ArgumentParser
import ArgumentParserTestHelpers
import Testing
import XCTest

final class EqualsEndToEndTests: XCTestCase {}
@Suite struct EqualsEndToEndTests {}

// MARK: .short name

Expand All @@ -27,24 +26,24 @@ private struct Foo: ParsableArguments {
// swift-format-ignore: AlwaysUseLowerCamelCase
// https://github.com/apple/swift-argument-parser/issues/710
extension EqualsEndToEndTests {
func testEquals_withShortName() throws {
AssertParse(Foo.self, ["-n=Name", "-f=Format"]) { foo in
XCTAssertEqual(foo.toggle, false)
XCTAssertEqual(foo.name, "Name")
XCTAssertEqual(foo.format, "Format")
@Test func equals_withShortName() throws {
expectParse(Foo.self, ["-n=Name", "-f=Format"]) { foo in
#expect(foo.toggle == false)
#expect(foo.name == "Name")
#expect(foo.format == "Format")
}
}

func testEquals_withCombinedShortName_1() throws {
AssertParse(Foo.self, ["-tf", "Format"]) { foo in
XCTAssertEqual(foo.toggle, true)
XCTAssertEqual(foo.name, nil)
XCTAssertEqual(foo.format, "Format")
@Test func equals_withCombinedShortName_1() throws {
expectParse(Foo.self, ["-tf", "Format"]) { foo in
#expect(foo.toggle == true)
#expect(foo.name == nil)
#expect(foo.format == "Format")
}
}

func testEquals_withCombinedShortName_2() throws {
XCTAssertThrowsError(try Foo.parse(["-tf=Format"]))
@Test func equals_withCombinedShortName_2() throws {
#expect(throws: (any Error).self) { try Foo.parse(["-tf=Format"]) }
}
}

Expand All @@ -58,10 +57,10 @@ private struct Bar: ParsableArguments {
// swift-format-ignore: AlwaysUseLowerCamelCase
// https://github.com/apple/swift-argument-parser/issues/710
extension EqualsEndToEndTests {
func testEquals_withShortAndLongName() throws {
AssertParse(Bar.self, ["-n=Name", "-f=Format"]) { bar in
XCTAssertEqual(bar.name, "Name")
XCTAssertEqual(bar.format, "Format")
@Test func equals_withShortAndLongName() throws {
expectParse(Bar.self, ["-n=Name", "-f=Format"]) { bar in
#expect(bar.name == "Name")
#expect(bar.format == "Format")
}
}
}
Expand All @@ -76,10 +75,10 @@ private struct Baz: ParsableArguments {
// swift-format-ignore: AlwaysUseLowerCamelCase
// https://github.com/apple/swift-argument-parser/issues/710
extension EqualsEndToEndTests {
func testEquals_withCustomShortName() throws {
AssertParse(Baz.self, ["-i=Name", "-t=Format"]) { baz in
XCTAssertEqual(baz.name, "Name")
XCTAssertEqual(baz.format, "Format")
@Test func equals_withCustomShortName() throws {
expectParse(Baz.self, ["-i=Name", "-t=Format"]) { baz in
#expect(baz.name == "Name")
#expect(baz.format == "Format")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift Argument Parser open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Copyright (c) 2020-2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand All @@ -12,9 +12,8 @@
import ArgumentParser
import ArgumentParserTestHelpers
import Testing
import XCTest

final class RawRepresentableEndToEndTests: XCTestCase {}
@Suite struct RawRepresentableEndToEndTests {}

// MARK: -

Expand All @@ -29,24 +28,28 @@ private struct Bar: ParsableArguments {
// swift-format-ignore: AlwaysUseLowerCamelCase
// https://github.com/apple/swift-argument-parser/issues/710
extension RawRepresentableEndToEndTests {
func testParsing_SingleOption() throws {
AssertParse(Bar.self, ["--identifier", "123"]) { bar in
XCTAssertEqual(bar.identifier, Bar.Identifier(rawValue: 123))
@Test func parsing_SingleOption() throws {
expectParse(Bar.self, ["--identifier", "123"]) { bar in
#expect(bar.identifier == Bar.Identifier(rawValue: 123))
}
}

func testParsing_SingleOptionMultipleTimes() throws {
AssertParse(Bar.self, ["--identifier", "123", "--identifier", "456"]) {
@Test func parsing_SingleOptionMultipleTimes() throws {
expectParse(Bar.self, ["--identifier", "123", "--identifier", "456"]) {
bar in
XCTAssertEqual(bar.identifier, Bar.Identifier(rawValue: 456))
#expect(bar.identifier == Bar.Identifier(rawValue: 456))
}
}

func testParsing_SingleOption_Fails() throws {
XCTAssertThrowsError(try Bar.parse([]))
XCTAssertThrowsError(try Bar.parse(["--identifier"]))
XCTAssertThrowsError(try Bar.parse(["--identifier", "not a number"]))
XCTAssertThrowsError(try Bar.parse(["--identifier", "123.456"]))
@Test func parsing_SingleOption_Fails() throws {
#expect(throws: (any Error).self) { try Bar.parse([]) }
#expect(throws: (any Error).self) { try Bar.parse(["--identifier"]) }
#expect(throws: (any Error).self) {
try Bar.parse(["--identifier", "not a number"])
}
#expect(throws: (any Error).self) {
try Bar.parse(["--identifier", "123.456"])
}
}
}

Expand Down
Loading