Skip to content

Commit

Permalink
add test coverage for subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
rauhul committed May 1, 2024
1 parent f14f2eb commit c2c96f9
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -712,40 +712,42 @@ extension HelpGenerationTests {

extension HelpGenerationTests {
struct NonCustomUsage: ParsableCommand {
static let configuration = CommandConfiguration()
struct ExampleSubcommand: ParsableCommand {
static let configuration = CommandConfiguration()
@Argument var output: String
}

static let configuration = CommandConfiguration(
subcommands: [ExampleSubcommand.self])

@Argument var file: String
@Flag var verboseMode = false
}

struct CustomUsageShort: ParsableCommand {
static var configuration: CommandConfiguration {
CommandConfiguration(usage: """
static let configuration = CommandConfiguration(
usage: """
example [--verbose] <file-name>
""")
}


@Argument var file: String
@Flag var verboseMode = false
}

struct CustomUsageLong: ParsableCommand {
static var configuration: CommandConfiguration {
CommandConfiguration(usage: """
static let configuration = CommandConfiguration(
usage: """
example <file-name>
example --verbose <file-name>
example --help
""")
}


@Argument var file: String
@Flag var verboseMode = false
}

struct CustomUsageHidden: ParsableCommand {
static var configuration: CommandConfiguration {
CommandConfiguration(usage: "")
}
static let configuration = CommandConfiguration(usage: "")

@Argument var file: String
@Flag var verboseMode = false
Expand All @@ -755,14 +757,32 @@ extension HelpGenerationTests {
AssertEqualStrings(
actual: NonCustomUsage.helpMessage(columns: 80),
expected: """
USAGE: non-custom-usage <file> [--verbose-mode]
USAGE: non-custom-usage <file> [--verbose-mode] <subcommand>
ARGUMENTS:
<file>
OPTIONS:
--verbose-mode
-h, --help Show help information.
SUBCOMMANDS:
example-subcommand
See 'non-custom-usage help <subcommand>' for detailed help.
""")

AssertEqualStrings(
actual: NonCustomUsage.helpMessage(
for: NonCustomUsage.ExampleSubcommand.self, columns: 80),
expected: """
USAGE: non-custom-usage example-subcommand <output>
ARGUMENTS:
<output>
OPTIONS:
-h, --help Show help information.
""")

Expand Down Expand Up @@ -814,7 +834,7 @@ extension HelpGenerationTests {
actual: NonCustomUsage.fullMessage(for: ValidationError("Test")),
expected: """
Error: Test
Usage: non-custom-usage <file> [--verbose-mode]
Usage: non-custom-usage <file> [--verbose-mode] <subcommand>
See 'non-custom-usage --help' for more information.
""")

Expand Down Expand Up @@ -848,7 +868,14 @@ extension HelpGenerationTests {
AssertEqualStrings(
actual: NonCustomUsage.usageString(),
expected: """
non-custom-usage <file> [--verbose-mode]
non-custom-usage <file> [--verbose-mode] <subcommand>
""")

AssertEqualStrings(
actual: NonCustomUsage.usageString(
for: NonCustomUsage.ExampleSubcommand.self),
expected: """
non-custom-usage example-subcommand <output>
""")

AssertEqualStrings(
Expand Down

0 comments on commit c2c96f9

Please sign in to comment.