diff --git a/Sources/ArgumentParserTestHelpers/TestHelpers+SwiftTesting.swift b/Sources/ArgumentParserTestHelpers/TestHelpers+SwiftTesting.swift index 8989236f7..25a942618 100644 --- a/Sources/ArgumentParserTestHelpers/TestHelpers+SwiftTesting.swift +++ b/Sources/ArgumentParserTestHelpers/TestHelpers+SwiftTesting.swift @@ -10,6 +10,7 @@ //===----------------------------------------------------------------------===// import ArgumentParser +import ArgumentParserToolInfo import Foundation import Testing @@ -200,3 +201,105 @@ public func expectSnapshot( return expected } } + +public func expectJSONEqualFromString( + actual: String, + expected: String, + for type: T.Type, + sourceLocation: SourceLocation = #_sourceLocation +) throws { + expectEqualStrings( + actual: actual, + expected: expected, + sourceLocation: sourceLocation + ) + + let actualJSONData = try #require( + actual.data(using: .utf8), + sourceLocation: sourceLocation + ) + let actualDumpJSON = try JSONDecoder().decode(type, from: actualJSONData) + + let expectedJSONData = try #require( + expected.data(using: .utf8), + sourceLocation: sourceLocation + ) + let expectedDumpJSON = try JSONDecoder().decode(type, from: expectedJSONData) + + #expect( + actualDumpJSON == expectedDumpJSON, + sourceLocation: sourceLocation + ) +} + +public func expectDumpHelp( + type: T.Type, + record: Bool = false, + test: String = #function, + filePath: StaticString = #filePath, + sourceLocation: SourceLocation = #_sourceLocation +) throws { + // TODO: migrate to the following API when the minimum Swift version supports it + /// + // let error = #expect(throws: (any Error).self) { + // _ = try T.parse(["--experimental-dump-help"]) + // } + // let actual = T.fullMessage(for: error) + let actual: String + do { + _ = try T.parse(["--experimental-dump-help"]) + Issue.record( + "Expected T.parse to throw a help request.", + sourceLocation: sourceLocation) + return + } catch { + actual = T.fullMessage(for: error) + } + + let apiOutput = T._dumpHelp() + expectEqualStrings( + actual: actual, + expected: apiOutput, + sourceLocation: sourceLocation + ) + + let expected = try expectSnapshot( + actual: actual, + extension: "json", + record: record, + test: test, + filePath: filePath, + sourceLocation: sourceLocation + ) + + guard let expected else { return } + + try expectJSONEqualFromString( + actual: actual, + expected: expected, + for: ToolInfoV0.self, + sourceLocation: sourceLocation + ) +} + +public func expectDumpHelp( + command: String, + record: Bool = false, + test: String = #function, + filePath: StaticString = #filePath, + sourceLocation: SourceLocation = #_sourceLocation +) throws { + let actual = try requireExecuteCommand( + command: command + " --experimental-dump-help", + expected: nil, + sourceLocation: sourceLocation + ) + try expectSnapshot( + actual: actual, + extension: "json", + record: record, + test: test, + filePath: filePath, + sourceLocation: sourceLocation + ) +} diff --git a/Tests/ArgumentParserUnitTests/DefaultAsFlagCompletionTests.swift b/Tests/ArgumentParserUnitTests/DefaultAsFlagCompletionTests.swift index 2c06de653..b6c80b7ed 100644 --- a/Tests/ArgumentParserUnitTests/DefaultAsFlagCompletionTests.swift +++ b/Tests/ArgumentParserUnitTests/DefaultAsFlagCompletionTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Argument Parser open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025-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 @@ -10,33 +10,33 @@ //===----------------------------------------------------------------------===// import ArgumentParserTestHelpers -import XCTest +import Testing @testable import ArgumentParser -final class DefaultAsFlagCompletionTests: XCTestCase { - func testDefaultAsFlagCompletion_Bash() throws { +@Suite struct DefaultAsFlagCompletionTests { + @Test func defaultAsFlagCompletion_Bash() throws { let script = try CompletionsGenerator( command: DefaultAsFlagCommand.self, shell: .bash ) .generateCompletionScript() - try assertSnapshot(actual: script, extension: "bash") + try expectSnapshot(actual: script, extension: "bash") } - func testDefaultAsFlagCompletion_Zsh() throws { + @Test func defaultAsFlagCompletion_Zsh() throws { let script = try CompletionsGenerator( command: DefaultAsFlagCommand.self, shell: .zsh ) .generateCompletionScript() - try assertSnapshot(actual: script, extension: "zsh") + try expectSnapshot(actual: script, extension: "zsh") } - func testDefaultAsFlagCompletion_Fish() throws { + @Test func defaultAsFlagCompletion_Fish() throws { let script = try CompletionsGenerator( command: DefaultAsFlagCommand.self, shell: .fish ) .generateCompletionScript() - try assertSnapshot(actual: script, extension: "fish") + try expectSnapshot(actual: script, extension: "fish") } } diff --git a/Tests/ArgumentParserUnitTests/DefaultAsFlagDumpHelpTests.swift b/Tests/ArgumentParserUnitTests/DefaultAsFlagDumpHelpTests.swift index 5d1174188..582369c7c 100644 --- a/Tests/ArgumentParserUnitTests/DefaultAsFlagDumpHelpTests.swift +++ b/Tests/ArgumentParserUnitTests/DefaultAsFlagDumpHelpTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Argument Parser open source project // -// Copyright (c) 2025 Apple Inc. and the Swift project authors +// Copyright (c) 2025-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 @@ -10,17 +10,17 @@ //===----------------------------------------------------------------------===// import ArgumentParserTestHelpers -import XCTest +import Testing @testable import ArgumentParser -final class DefaultAsFlagDumpHelpTests: XCTestCase { - func testDefaultAsFlagDumpHelp() throws { - try assertDumpHelp(type: DefaultAsFlagCommand.self) +@Suite struct DefaultAsFlagDumpHelpTests { + @Test func defaultAsFlagDumpHelp() throws { + try expectDumpHelp(type: DefaultAsFlagCommand.self) } - func testDefaultAsFlagWithTransformDumpHelp() throws { - try assertDumpHelp(type: DefaultAsFlagWithTransformCommand.self) + @Test func defaultAsFlagWithTransformDumpHelp() throws { + try expectDumpHelp(type: DefaultAsFlagWithTransformCommand.self) } } diff --git a/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift b/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift index 9a652479c..083b59dc3 100644 --- a/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift +++ b/Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift @@ -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 @@ -10,37 +10,45 @@ //===----------------------------------------------------------------------===// import ArgumentParserTestHelpers -import XCTest +import Testing @testable import ArgumentParser -final class DumpHelpGenerationTests: XCTestCase { - public func testADumpHelp() throws { - try assertDumpHelp(type: A.self) +@Suite struct DumpHelpGenerationTests { + @Test func aDumpHelp() throws { + try expectDumpHelp(type: A.self) } - public func testBDumpHelp() throws { - try assertDumpHelp(type: B.self) + @Test func bDumpHelp() throws { + try expectDumpHelp(type: B.self) } - public func testCDumpHelp() throws { - try assertDumpHelp(type: C.self) + @Test func cDumpHelp() throws { + try expectDumpHelp(type: C.self) } - func testMathDumpHelp() throws { - try assertDumpHelp(command: "math") + @Test( + .requiresProcessExecution + ) func mathDumpHelp() throws { + try expectDumpHelp(command: "math") } - func testMathAddDumpHelp() throws { - try assertDumpHelp(command: "math add") + @Test( + .requiresProcessExecution + ) func mathAddDumpHelp() throws { + try expectDumpHelp(command: "math add") } - func testMathMultiplyDumpHelp() throws { - try assertDumpHelp(command: "math multiply") + @Test( + .requiresProcessExecution + ) func mathMultiplyDumpHelp() throws { + try expectDumpHelp(command: "math multiply") } - func testMathStatsDumpHelp() throws { - try assertDumpHelp(command: "math stats") + @Test( + .requiresProcessExecution + ) func mathStatsDumpHelp() throws { + try expectDumpHelp(command: "math stats") } } diff --git a/Tests/ArgumentParserUnitTests/ExitCodeTests.swift b/Tests/ArgumentParserUnitTests/ExitCodeTests.swift index 137fcdc0e..febfc8842 100644 --- a/Tests/ArgumentParserUnitTests/ExitCodeTests.swift +++ b/Tests/ArgumentParserUnitTests/ExitCodeTests.swift @@ -2,18 +2,19 @@ // // 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 XCTest +import Foundation +import Testing @testable import ArgumentParser -final class ExitCodeTests: XCTestCase {} +@Suite struct ExitCodeTests {} // MARK: - @@ -26,56 +27,55 @@ extension ExitCodeTests { static let configuration = CommandConfiguration(version: "v1") } - func testExitCodes() { - XCTAssertEqual(ExitCode.failure, A.exitCode(for: E())) - XCTAssertEqual( - ExitCode.validationFailure, A.exitCode(for: ValidationError(""))) + @Test func exitCodes() { + #expect(A.exitCode(for: E()) == ExitCode.failure) + #expect(A.exitCode(for: ValidationError("")) == ExitCode.validationFailure) do { _ = try A.parse(["-h"]) - XCTFail("Didn't throw help request error.") + Issue.record("Didn't throw help request error.") } catch { - XCTAssertEqual(ExitCode.success, A.exitCode(for: error)) + #expect(A.exitCode(for: error) == ExitCode.success) } do { _ = try A.parse(["--version"]) - XCTFail("Didn't throw unrecognized --version error.") + Issue.record("Didn't throw unrecognized --version error.") } catch { - XCTAssertEqual(ExitCode.validationFailure, A.exitCode(for: error)) + #expect(A.exitCode(for: error) == ExitCode.validationFailure) } do { _ = try C.parse(["--version"]) - XCTFail("Didn't throw version request error.") + Issue.record("Didn't throw version request error.") } catch { - XCTAssertEqual(ExitCode.success, C.exitCode(for: error)) + #expect(C.exitCode(for: error) == ExitCode.success) } } - func testExitCode_Success() { - XCTAssertFalse(A.exitCode(for: E()).isSuccess) - XCTAssertFalse(A.exitCode(for: ValidationError("")).isSuccess) + @Test func exitCode_Success() { + #expect(A.exitCode(for: E()).isSuccess == false) + #expect(A.exitCode(for: ValidationError("")).isSuccess == false) do { _ = try A.parse(["-h"]) - XCTFail("Didn't throw help request error.") + Issue.record("Didn't throw help request error.") } catch { - XCTAssertTrue(A.exitCode(for: error).isSuccess) + #expect(A.exitCode(for: error).isSuccess) } do { _ = try A.parse(["--version"]) - XCTFail("Didn't throw unrecognized --version error.") + Issue.record("Didn't throw unrecognized --version error.") } catch { - XCTAssertFalse(A.exitCode(for: error).isSuccess) + #expect(A.exitCode(for: error).isSuccess == false) } do { _ = try C.parse(["--version"]) - XCTFail("Didn't throw version request error.") + Issue.record("Didn't throw version request error.") } catch { - XCTAssertTrue(C.exitCode(for: error).isSuccess) + #expect(C.exitCode(for: error).isSuccess) } } } @@ -83,7 +83,7 @@ extension ExitCodeTests { // MARK: - NSError tests extension ExitCodeTests { - func testNSErrorIsHandled() { + @Test func nsErrorIsHandled() { struct NSErrorCommand: ParsableCommand { static let message = "The file “foo/bar” couldn’t be opened because there is no such file" @@ -93,26 +93,26 @@ extension ExitCodeTests { code: 1, userInfo: [NSLocalizedDescriptionKey: Self.message]) } - XCTAssertEqual( - NSErrorCommand.exitCode(for: NSErrorCommand.fileNotFoundNSError), - ExitCode(rawValue: 1)) + #expect( + NSErrorCommand.exitCode(for: NSErrorCommand.fileNotFoundNSError) + == ExitCode(rawValue: 1)) #if canImport(FoundationEssentials) let prefix = "Error Domain=TestError Code=1 \"(null)\"" #if compiler(<6.1) - XCTAssertEqual( - NSErrorCommand.message(for: NSErrorCommand.fileNotFoundNSError), - "\(prefix)") + #expect( + NSErrorCommand.message(for: NSErrorCommand.fileNotFoundNSError) + == "\(prefix)") #else - XCTAssertEqual( - NSErrorCommand.message(for: NSErrorCommand.fileNotFoundNSError), - "\(prefix)UserInfo={NSLocalizedDescription=\(NSErrorCommand.message)}" + #expect( + NSErrorCommand.message(for: NSErrorCommand.fileNotFoundNSError) + == "\(prefix)UserInfo={NSLocalizedDescription=\(NSErrorCommand.message)}" ) #endif #else - XCTAssertEqual( - NSErrorCommand.message(for: NSErrorCommand.fileNotFoundNSError), - NSErrorCommand.message) + #expect( + NSErrorCommand.message(for: NSErrorCommand.fileNotFoundNSError) + == NSErrorCommand.message) #endif } } diff --git a/Tests/ArgumentParserUnitTests/NameSpecificationTests.swift b/Tests/ArgumentParserUnitTests/NameSpecificationTests.swift index fe1135360..63c2af251 100644 --- a/Tests/ArgumentParserUnitTests/NameSpecificationTests.swift +++ b/Tests/ArgumentParserUnitTests/NameSpecificationTests.swift @@ -2,263 +2,274 @@ // // 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 XCTest +import Testing @testable import ArgumentParser -final class NameSpecificationTests: XCTestCase {} +@Suite struct NameSpecificationTests {} // swift-format-ignore: AlwaysUseLowerCamelCase // https://github.com/apple/swift-argument-parser/issues/710 extension NameSpecificationTests { - func testFlagNames_withNoPrefix() { + @Test func flagNames_withNoPrefix() { let key = InputKey(name: "index", parent: nil) - XCTAssertEqual( + #expect( FlagInversion.prefixedNo.enableDisableNamePair( for: key, name: .long - ).1, [.long("no-index")]) - XCTAssertEqual( + ).1 == [.long("no-index")]) + #expect( FlagInversion.prefixedNo.enableDisableNamePair( for: key, name: .customLong("foo") - ).1, [.long("no-foo")]) - XCTAssertEqual( + ).1 == [.long("no-foo")]) + #expect( FlagInversion.prefixedNo.enableDisableNamePair( for: key, name: .customLong("foo-bar-baz") - ).1, [.long("no-foo-bar-baz")]) - XCTAssertEqual( + ).1 == [.long("no-foo-bar-baz")]) + #expect( FlagInversion.prefixedNo.enableDisableNamePair( for: key, name: .customLong("foo_bar_baz") - ).1, [.long("no_foo_bar_baz")]) - XCTAssertEqual( + ).1 == [.long("no_foo_bar_baz")]) + #expect( FlagInversion.prefixedNo.enableDisableNamePair( for: key, name: .customLong("fooBarBaz") - ).1, [.long("noFooBarBaz")]) + ).1 == [.long("noFooBarBaz")]) // Short names don't work in combination - XCTAssertEqual( + #expect( FlagInversion.prefixedNo.enableDisableNamePair( for: key, name: .short - ).1, []) + ).1 == []) } - func testFlagNames_withEnableDisablePrefix() { + @Test func flagNames_withEnableDisablePrefix() { let key = InputKey(name: "index", parent: nil) - XCTAssertEqual( + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .long - ).0, [.long("enable-index")]) - XCTAssertEqual( + ).0 == [.long("enable-index")]) + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .long - ).1, [.long("disable-index")]) + ).1 == [.long("disable-index")]) - XCTAssertEqual( + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .customLong("foo") - ).0, [.long("enable-foo")]) - XCTAssertEqual( + ).0 == [.long("enable-foo")]) + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .customLong("foo") - ).1, [.long("disable-foo")]) + ).1 == [.long("disable-foo")]) - XCTAssertEqual( + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .customLong("foo-bar-baz") - ).0, [.long("enable-foo-bar-baz")]) - XCTAssertEqual( + ).0 == [.long("enable-foo-bar-baz")]) + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .customLong("foo-bar-baz") - ).1, [.long("disable-foo-bar-baz")]) - XCTAssertEqual( + ).1 == [.long("disable-foo-bar-baz")]) + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .customLong("foo_bar_baz") - ).0, [.long("enable_foo_bar_baz")]) - XCTAssertEqual( + ).0 == [.long("enable_foo_bar_baz")]) + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .customLong("foo_bar_baz") - ).1, [.long("disable_foo_bar_baz")]) - XCTAssertEqual( + ).1 == [.long("disable_foo_bar_baz")]) + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .customLong("fooBarBaz") - ).0, [.long("enableFooBarBaz")]) - XCTAssertEqual( + ).0 == [.long("enableFooBarBaz")]) + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .customLong("fooBarBaz") - ).1, [.long("disableFooBarBaz")]) + ).1 == [.long("disableFooBarBaz")]) // Short names don't work in combination - XCTAssertEqual( + #expect( FlagInversion.prefixedEnableDisable.enableDisableNamePair( for: key, name: .short - ).1, []) + ).1 == []) } } -// swift-format-ignore: AlwaysUseLowerCamelCase -private func Assert( - nameSpecification: NameSpecification, key: String, parent: InputKey? = nil, - makeNames expected: [Name], file: StaticString = #filePath, line: UInt = #line +private func expectNames( + nameSpecification: NameSpecification, + key: String, + parent: InputKey? = nil, + makeNames expected: [Name], + sourceLocation: SourceLocation = #_sourceLocation ) { let names = nameSpecification.makeNames(InputKey(name: key, parent: parent)) - Assert(names: names, expected: expected, file: file, line: line) + expectNames( + names: names, expected: expected, sourceLocation: sourceLocation) } -// swift-format-ignore: AlwaysUseLowerCamelCase -private func Assert( - names: [N], expected: [N], file: StaticString = #filePath, line: UInt = #line +private func expectNames( + names: [N], expected: [N], + sourceLocation: SourceLocation = #_sourceLocation ) where N: Equatable { for name in names { - XCTAssert( - expected.contains(name), "Unexpected name '\(name)'.", file: file, - line: line) + #expect( + expected.contains(name), + "Unexpected name '\(name)'.", + sourceLocation: sourceLocation) } for expected in expected { - XCTAssert( - names.contains(expected), "Missing name '\(expected)'.", file: file, - line: line) + #expect( + names.contains(expected), + "Missing name '\(expected)'.", + sourceLocation: sourceLocation) } } -// swift-format-ignore: AlwaysUseLowerCamelCase -private func AssertInvalid( +private func expectInvalid( nameSpecification: NameSpecification, - file: StaticString = #filePath, - line: UInt = #line + sourceLocation: SourceLocation = #_sourceLocation ) { - XCTAssert( + #expect( nameSpecification.elements.contains(where: { if case .invalidLiteral = $0.base { return true } else { return false } - }), "Expected invalid name.", - file: file, line: line) + }), + "Expected invalid name.", + sourceLocation: sourceLocation) } // swift-format-ignore: AlwaysUseLowerCamelCase // https://github.com/apple/swift-argument-parser/issues/710 extension NameSpecificationTests { - func testMakeNames_short() { - Assert(nameSpecification: .short, key: "foo", makeNames: [.short("f")]) + @Test func makeNames_short() { + expectNames(nameSpecification: .short, key: "foo", makeNames: [.short("f")]) } - func testMakeNames_Long() { - Assert( + @Test func makeNames_Long() { + expectNames( nameSpecification: .long, key: "fooBarBaz", makeNames: [.long("foo-bar-baz")]) - Assert( + expectNames( nameSpecification: .long, key: "fooURLForBarBaz", makeNames: [.long("foo-url-for-bar-baz")]) } - func testMakeNames_customLong() { - Assert( + @Test func makeNames_customLong() { + expectNames( nameSpecification: .customLong("bar"), key: "foo", makeNames: [.long("bar")]) } - func testMakeNames_customShort() { - Assert( - nameSpecification: .customShort("v"), key: "foo", makeNames: [.short("v")] + @Test func makeNames_customShort() { + expectNames( + nameSpecification: .customShort("v"), key: "foo", + makeNames: [.short("v")] ) } - func testMakeNames_customLongWithSingleDash() { - Assert( + @Test func makeNames_customLongWithSingleDash() { + expectNames( nameSpecification: .customLong("baz", withSingleDash: true), key: "foo", makeNames: [.longWithSingleDash("baz")]) } - func testMakeNames_shortLiteral() { - Assert(nameSpecification: "-x", key: "foo", makeNames: [.short("x")]) - Assert(nameSpecification: ["-x"], key: "foo", makeNames: [.short("x")]) + @Test func makeNames_shortLiteral() { + expectNames(nameSpecification: "-x", key: "foo", makeNames: [.short("x")]) + expectNames(nameSpecification: ["-x"], key: "foo", makeNames: [.short("x")]) } - func testMakeNames_longLiteral() { - Assert(nameSpecification: "--foo", key: "foo", makeNames: [.long("foo")]) - Assert(nameSpecification: ["--foo"], key: "foo", makeNames: [.long("foo")]) - Assert( + @Test func makeNames_longLiteral() { + expectNames( + nameSpecification: "--foo", key: "foo", makeNames: [.long("foo")]) + expectNames( + nameSpecification: ["--foo"], key: "foo", makeNames: [.long("foo")]) + expectNames( nameSpecification: "--foo-bar-baz", key: "foo", makeNames: [.long("foo-bar-baz")]) - Assert( + expectNames( nameSpecification: "--fooBarBAZ", key: "foo", makeNames: [.long("fooBarBAZ")]) } - func testMakeNames_longWithSingleDashLiteral() { - Assert( + @Test func makeNames_longWithSingleDashLiteral() { + expectNames( nameSpecification: "-foo", key: "foo", makeNames: [.longWithSingleDash("foo")]) - Assert( + expectNames( nameSpecification: ["-foo"], key: "foo", makeNames: [.longWithSingleDash("foo")]) - Assert( + expectNames( nameSpecification: "-foo-bar-baz", key: "foo", makeNames: [.longWithSingleDash("foo-bar-baz")]) - Assert( + expectNames( nameSpecification: "-fooBarBAZ", key: "foo", makeNames: [.longWithSingleDash("fooBarBAZ")]) } - func testMakeNames_combinedLiteral() { - Assert( + @Test func makeNames_combinedLiteral() { + expectNames( nameSpecification: "-x -y --zilch", key: "foo", makeNames: [.short("x"), .short("y"), .long("zilch")]) - Assert( + expectNames( nameSpecification: " -x -y ", key: "foo", makeNames: [.short("x"), .short("y")]) - Assert( + expectNames( nameSpecification: ["-x", "-y", "--zilch"], key: "foo", makeNames: [.short("x"), .short("y"), .long("zilch")]) } - func testMakeNames_interpolations() { + @Test func makeNames_interpolations() { let x = "x" - Assert(nameSpecification: ["-\(x)"], key: "foo", makeNames: [.short("x")]) - Assert(nameSpecification: ["--\(x)"], key: "foo", makeNames: [.long("x")]) - Assert( + expectNames( + nameSpecification: ["-\(x)"], key: "foo", makeNames: [.short("x")]) + expectNames( + nameSpecification: ["--\(x)"], key: "foo", makeNames: [.long("x")]) + expectNames( nameSpecification: ["-\(x)\(x)\(x)"], key: "foo", makeNames: [.longWithSingleDash("xxx")]) - Assert(nameSpecification: "-\(x)", key: "foo", makeNames: [.short("x")]) - Assert(nameSpecification: "--\(x)", key: "foo", makeNames: [.long("x")]) - Assert( + expectNames( + nameSpecification: "-\(x)", key: "foo", makeNames: [.short("x")]) + expectNames( + nameSpecification: "--\(x)", key: "foo", makeNames: [.long("x")]) + expectNames( nameSpecification: "-\(x)\(x)\(x)", key: "foo", makeNames: [.longWithSingleDash("xxx")]) } - func testMakeNames_literalFailures() { + @Test func makeNames_literalFailures() { // Empty string and whitespace-only - AssertInvalid(nameSpecification: "") - AssertInvalid(nameSpecification: " ") - AssertInvalid(nameSpecification: " ") + expectInvalid(nameSpecification: "") + expectInvalid(nameSpecification: " ") + expectInvalid(nameSpecification: " ") // No dash prefix - AssertInvalid(nameSpecification: "x") + expectInvalid(nameSpecification: "x") // Dash prefix only - AssertInvalid(nameSpecification: "-") - AssertInvalid(nameSpecification: "--") - AssertInvalid(nameSpecification: "---") + expectInvalid(nameSpecification: "-") + expectInvalid(nameSpecification: "--") + expectInvalid(nameSpecification: "---") // Triple dash - AssertInvalid(nameSpecification: "---x") + expectInvalid(nameSpecification: "---x") // Invalid characters - AssertInvalid(nameSpecification: "--café") - AssertInvalid(nameSpecification: "--c!f!") + expectInvalid(nameSpecification: "--café") + expectInvalid(nameSpecification: "--c!f!") // Repeating as elements - AssertInvalid(nameSpecification: [""]) - AssertInvalid(nameSpecification: ["x"]) - AssertInvalid(nameSpecification: ["-"]) - AssertInvalid(nameSpecification: ["--"]) - AssertInvalid(nameSpecification: ["---"]) - AssertInvalid(nameSpecification: ["---x"]) - AssertInvalid(nameSpecification: ["--café"]) + expectInvalid(nameSpecification: [""]) + expectInvalid(nameSpecification: ["x"]) + expectInvalid(nameSpecification: ["-"]) + expectInvalid(nameSpecification: ["--"]) + expectInvalid(nameSpecification: ["---"]) + expectInvalid(nameSpecification: ["---x"]) + expectInvalid(nameSpecification: ["--café"]) // Spaces in _elements_, not the top level literal - AssertInvalid(nameSpecification: ["-x -y -z"]) - AssertInvalid(nameSpecification: ["-x", "-y", " -z"]) + expectInvalid(nameSpecification: ["-x -y -z"]) + expectInvalid(nameSpecification: ["-x", "-y", " -z"]) } } diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/aDumpHelp().json similarity index 100% rename from Tests/ArgumentParserUnitTests/Snapshots/testADumpHelp().json rename to Tests/ArgumentParserUnitTests/Snapshots/aDumpHelp().json diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/bDumpHelp().json similarity index 100% rename from Tests/ArgumentParserUnitTests/Snapshots/testBDumpHelp().json rename to Tests/ArgumentParserUnitTests/Snapshots/bDumpHelp().json diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/cDumpHelp().json similarity index 100% rename from Tests/ArgumentParserUnitTests/Snapshots/testCDumpHelp().json rename to Tests/ArgumentParserUnitTests/Snapshots/cDumpHelp().json diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagCompletion_Bash().bash b/Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagCompletion_Bash().bash similarity index 100% rename from Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagCompletion_Bash().bash rename to Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagCompletion_Bash().bash diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagCompletion_Fish().fish b/Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagCompletion_Fish().fish similarity index 100% rename from Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagCompletion_Fish().fish rename to Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagCompletion_Fish().fish diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagCompletion_Zsh().zsh b/Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagCompletion_Zsh().zsh similarity index 100% rename from Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagCompletion_Zsh().zsh rename to Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagCompletion_Zsh().zsh diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagDumpHelp().json similarity index 100% rename from Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagDumpHelp().json rename to Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagDumpHelp().json diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagWithTransformDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagWithTransformDumpHelp().json similarity index 100% rename from Tests/ArgumentParserUnitTests/Snapshots/testDefaultAsFlagWithTransformDumpHelp().json rename to Tests/ArgumentParserUnitTests/Snapshots/defaultAsFlagWithTransformDumpHelp().json diff --git a/Tests/ArgumentParserUnitTests/Snapshots/defaultasflagefaultAsFlagDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/defaultasflagefaultAsFlagDumpHelp().json new file mode 100644 index 000000000..4ef80e79e --- /dev/null +++ b/Tests/ArgumentParserUnitTests/Snapshots/defaultasflagefaultAsFlagDumpHelp().json @@ -0,0 +1,144 @@ +{ + "command" : { + "abstract" : "A command with defaultAsFlag options for testing dump help.", + "arguments" : [ + { + "defaultValue" : "\/usr\/bin", + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "binary-path" + } + ], + "parsingStrategy" : "scanningForValue", + "preferredName" : { + "kind" : "long", + "name" : "binary-path" + }, + "shouldDisplay" : true, + "valueName" : "binary-path" + }, + { + "defaultValue" : "42", + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "count" + } + ], + "parsingStrategy" : "scanningForValue", + "preferredName" : { + "kind" : "long", + "name" : "count" + }, + "shouldDisplay" : true, + "valueName" : "count" + }, + { + "defaultValue" : "true", + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "verbose" + } + ], + "parsingStrategy" : "scanningForValue", + "preferredName" : { + "kind" : "long", + "name" : "verbose" + }, + "shouldDisplay" : true, + "valueName" : "verbose" + }, + { + "isOptional" : false, + "isRepeating" : false, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "input" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "default-as-flag-command", + "shouldDisplay" : true, + "subcommands" : [ + { + "abstract" : "Show subcommand help information.", + "arguments" : [ + { + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "subcommands" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + }, + { + "kind" : "longWithSingleDash", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : false, + "valueName" : "help" + } + ], + "commandName" : "help", + "shouldDisplay" : true, + "superCommands" : [ + "default-as-flag-command" + ] + } + ] + }, + "serializationVersion" : 0 +} \ No newline at end of file diff --git a/Tests/ArgumentParserUnitTests/Snapshots/mathAddDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/mathAddDumpHelp().json new file mode 100644 index 000000000..51568de7c --- /dev/null +++ b/Tests/ArgumentParserUnitTests/Snapshots/mathAddDumpHelp().json @@ -0,0 +1,153 @@ +{ + "command" : { + "abstract" : "Print the sum of the values.", + "arguments" : [ + { + "abstract" : "Use hexadecimal notation for the result.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "hex-output" + }, + { + "kind" : "short", + "name" : "x" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "hex-output" + }, + "shouldDisplay" : true, + "valueName" : "hex-output" + }, + { + "abstract" : "A group of integers to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "add", + "shouldDisplay" : true, + "subcommands" : [ + { + "abstract" : "Show subcommand help information.", + "arguments" : [ + { + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "subcommands" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + }, + { + "kind" : "longWithSingleDash", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : false, + "valueName" : "help" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + } + ], + "commandName" : "help", + "shouldDisplay" : true, + "superCommands" : [ + "math", + "add" + ] + } + ], + "superCommands" : [ + "math" + ] + }, + "serializationVersion" : 0 +} diff --git a/Tests/ArgumentParserUnitTests/Snapshots/mathDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/mathDumpHelp().json new file mode 100644 index 000000000..cca3abc42 --- /dev/null +++ b/Tests/ArgumentParserUnitTests/Snapshots/mathDumpHelp().json @@ -0,0 +1,799 @@ +{ + "command" : { + "abstract" : "A utility for performing maths.", + "arguments" : [ + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "math", + "shouldDisplay" : true, + "subcommands" : [ + { + "abstract" : "Print the sum of the values.", + "arguments" : [ + { + "abstract" : "Use hexadecimal notation for the result.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "hex-output" + }, + { + "kind" : "short", + "name" : "x" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "hex-output" + }, + "shouldDisplay" : true, + "valueName" : "hex-output" + }, + { + "abstract" : "A group of integers to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "add", + "shouldDisplay" : true, + "superCommands" : [ + "math" + ] + }, + { + "abstract" : "Print the product of the values.", + "aliases" : [ + "mul" + ], + "arguments" : [ + { + "abstract" : "Use hexadecimal notation for the result.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "hex-output" + }, + { + "kind" : "short", + "name" : "x" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "hex-output" + }, + "shouldDisplay" : true, + "valueName" : "hex-output" + }, + { + "abstract" : "A group of integers to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "multiply", + "shouldDisplay" : true, + "superCommands" : [ + "math" + ] + }, + { + "abstract" : "Calculate descriptive statistics.", + "arguments" : [ + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "stats", + "shouldDisplay" : true, + "subcommands" : [ + { + "abstract" : "Print the average of the values.", + "aliases" : [ + "avg" + ], + "arguments" : [ + { + "abstract" : "The kind of average to provide.", + "allValues" : [ + "mean", + "median", + "mode" + ], + "completionKind" : { + "list" : { + "values" : [ + "mean", + "median", + "mode" + ] + } + }, + "defaultValue" : "mean", + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "kind" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "kind" + }, + "shouldDisplay" : true, + "valueName" : "kind" + }, + { + "abstract" : "A group of floating-point values to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "average", + "shouldDisplay" : true, + "superCommands" : [ + "math", + "stats" + ] + }, + { + "abstract" : "Print the standard deviation of the values.", + "arguments" : [ + { + "abstract" : "A group of floating-point values to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "stdev", + "shouldDisplay" : true, + "superCommands" : [ + "math", + "stats" + ] + }, + { + "abstract" : "Print the quantiles of the values (TBD).", + "arguments" : [ + { + "completionKind" : { + "list" : { + "values" : [ + "alphabet", + "alligator", + "branch", + "braggart" + ] + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "one-of-four" + }, + { + "completionKind" : { + "custom" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "custom-arg" + }, + { + "completionKind" : { + "customDeprecated" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "custom-deprecated-arg" + }, + { + "abstract" : "A group of floating-point values to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "test-success-exit-code" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "test-success-exit-code" + }, + "shouldDisplay" : false, + "valueName" : "test-success-exit-code" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "test-failure-exit-code" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "test-failure-exit-code" + }, + "shouldDisplay" : false, + "valueName" : "test-failure-exit-code" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "test-validation-exit-code" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "test-validation-exit-code" + }, + "shouldDisplay" : false, + "valueName" : "test-validation-exit-code" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "test-custom-exit-code" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "test-custom-exit-code" + }, + "shouldDisplay" : false, + "valueName" : "test-custom-exit-code" + }, + { + "completionKind" : { + "file" : { + "extensions" : [ + "txt", + "md" + ] + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "file" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "file" + }, + "shouldDisplay" : true, + "valueName" : "file" + }, + { + "completionKind" : { + "directory" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "directory" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "directory" + }, + "shouldDisplay" : true, + "valueName" : "directory" + }, + { + "completionKind" : { + "shellCommand" : { + "command" : "head -100 '\/usr\/share\/dict\/words' | tail -50" + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "shell" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "shell" + }, + "shouldDisplay" : true, + "valueName" : "shell" + }, + { + "completionKind" : { + "custom" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "custom" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "custom" + }, + "shouldDisplay" : true, + "valueName" : "custom" + }, + { + "completionKind" : { + "customDeprecated" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "custom-deprecated" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "custom-deprecated" + }, + "shouldDisplay" : true, + "valueName" : "custom-deprecated" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "quantiles", + "shouldDisplay" : true, + "superCommands" : [ + "math", + "stats" + ] + } + ], + "superCommands" : [ + "math" + ] + }, + { + "abstract" : "Show subcommand help information.", + "arguments" : [ + { + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "subcommands" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + }, + { + "kind" : "longWithSingleDash", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : false, + "valueName" : "help" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + } + ], + "commandName" : "help", + "shouldDisplay" : true, + "superCommands" : [ + "math" + ] + } + ] + }, + "serializationVersion" : 0 +} diff --git a/Tests/ArgumentParserUnitTests/Snapshots/mathMultiplyDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/mathMultiplyDumpHelp().json new file mode 100644 index 000000000..fbfb8a2ca --- /dev/null +++ b/Tests/ArgumentParserUnitTests/Snapshots/mathMultiplyDumpHelp().json @@ -0,0 +1,156 @@ +{ + "command" : { + "abstract" : "Print the product of the values.", + "aliases" : [ + "mul" + ], + "arguments" : [ + { + "abstract" : "Use hexadecimal notation for the result.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "hex-output" + }, + { + "kind" : "short", + "name" : "x" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "hex-output" + }, + "shouldDisplay" : true, + "valueName" : "hex-output" + }, + { + "abstract" : "A group of integers to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "multiply", + "shouldDisplay" : true, + "subcommands" : [ + { + "abstract" : "Show subcommand help information.", + "arguments" : [ + { + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "subcommands" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + }, + { + "kind" : "longWithSingleDash", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : false, + "valueName" : "help" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + } + ], + "commandName" : "help", + "shouldDisplay" : true, + "superCommands" : [ + "math", + "multiply" + ] + } + ], + "superCommands" : [ + "math" + ] + }, + "serializationVersion" : 0 +} diff --git a/Tests/ArgumentParserUnitTests/Snapshots/mathStatsDumpHelp().json b/Tests/ArgumentParserUnitTests/Snapshots/mathStatsDumpHelp().json new file mode 100644 index 000000000..432e78e5d --- /dev/null +++ b/Tests/ArgumentParserUnitTests/Snapshots/mathStatsDumpHelp().json @@ -0,0 +1,578 @@ +{ + "command" : { + "abstract" : "Calculate descriptive statistics.", + "arguments" : [ + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "stats", + "shouldDisplay" : true, + "subcommands" : [ + { + "abstract" : "Print the average of the values.", + "aliases" : [ + "avg" + ], + "arguments" : [ + { + "abstract" : "The kind of average to provide.", + "allValues" : [ + "mean", + "median", + "mode" + ], + "completionKind" : { + "list" : { + "values" : [ + "mean", + "median", + "mode" + ] + } + }, + "defaultValue" : "mean", + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "kind" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "kind" + }, + "shouldDisplay" : true, + "valueName" : "kind" + }, + { + "abstract" : "A group of floating-point values to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "average", + "shouldDisplay" : true, + "superCommands" : [ + "math", + "stats" + ] + }, + { + "abstract" : "Print the standard deviation of the values.", + "arguments" : [ + { + "abstract" : "A group of floating-point values to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "stdev", + "shouldDisplay" : true, + "superCommands" : [ + "math", + "stats" + ] + }, + { + "abstract" : "Print the quantiles of the values (TBD).", + "arguments" : [ + { + "completionKind" : { + "list" : { + "values" : [ + "alphabet", + "alligator", + "branch", + "braggart" + ] + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "one-of-four" + }, + { + "completionKind" : { + "custom" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "custom-arg" + }, + { + "completionKind" : { + "customDeprecated" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "custom-deprecated-arg" + }, + { + "abstract" : "A group of floating-point values to operate on.", + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "values" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "test-success-exit-code" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "test-success-exit-code" + }, + "shouldDisplay" : false, + "valueName" : "test-success-exit-code" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "test-failure-exit-code" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "test-failure-exit-code" + }, + "shouldDisplay" : false, + "valueName" : "test-failure-exit-code" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "test-validation-exit-code" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "test-validation-exit-code" + }, + "shouldDisplay" : false, + "valueName" : "test-validation-exit-code" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "test-custom-exit-code" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "test-custom-exit-code" + }, + "shouldDisplay" : false, + "valueName" : "test-custom-exit-code" + }, + { + "completionKind" : { + "file" : { + "extensions" : [ + "txt", + "md" + ] + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "file" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "file" + }, + "shouldDisplay" : true, + "valueName" : "file" + }, + { + "completionKind" : { + "directory" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "directory" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "directory" + }, + "shouldDisplay" : true, + "valueName" : "directory" + }, + { + "completionKind" : { + "shellCommand" : { + "command" : "head -100 '\/usr\/share\/dict\/words' | tail -50" + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "shell" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "shell" + }, + "shouldDisplay" : true, + "valueName" : "shell" + }, + { + "completionKind" : { + "custom" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "custom" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "custom" + }, + "shouldDisplay" : true, + "valueName" : "custom" + }, + { + "completionKind" : { + "customDeprecated" : { + + } + }, + "isOptional" : true, + "isRepeating" : false, + "kind" : "option", + "names" : [ + { + "kind" : "long", + "name" : "custom-deprecated" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "custom-deprecated" + }, + "shouldDisplay" : true, + "valueName" : "custom-deprecated" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + }, + { + "abstract" : "Show help information.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : true, + "valueName" : "help" + } + ], + "commandName" : "quantiles", + "shouldDisplay" : true, + "superCommands" : [ + "math", + "stats" + ] + }, + { + "abstract" : "Show subcommand help information.", + "arguments" : [ + { + "isOptional" : true, + "isRepeating" : true, + "kind" : "positional", + "parsingStrategy" : "default", + "shouldDisplay" : true, + "valueName" : "subcommands" + }, + { + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "short", + "name" : "h" + }, + { + "kind" : "long", + "name" : "help" + }, + { + "kind" : "longWithSingleDash", + "name" : "help" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "help" + }, + "shouldDisplay" : false, + "valueName" : "help" + }, + { + "abstract" : "Show the version.", + "isOptional" : true, + "isRepeating" : false, + "kind" : "flag", + "names" : [ + { + "kind" : "long", + "name" : "version" + } + ], + "parsingStrategy" : "default", + "preferredName" : { + "kind" : "long", + "name" : "version" + }, + "shouldDisplay" : true, + "valueName" : "version" + } + ], + "commandName" : "help", + "shouldDisplay" : true, + "superCommands" : [ + "math", + "stats" + ] + } + ], + "superCommands" : [ + "math" + ] + }, + "serializationVersion" : 0 +} diff --git a/Tests/ArgumentParserUnitTests/UsageGenerationTests.swift b/Tests/ArgumentParserUnitTests/UsageGenerationTests.swift index d7cfae894..30a3adc28 100644 --- a/Tests/ArgumentParserUnitTests/UsageGenerationTests.swift +++ b/Tests/ArgumentParserUnitTests/UsageGenerationTests.swift @@ -2,39 +2,37 @@ // // 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 XCTest +import Testing @testable import ArgumentParser -final class UsageGenerationTests: XCTestCase { -} +@Suite struct UsageGenerationTests {} -func _testSynopsis( +private func expectSynopsis( _ type: T.Type, visibility: ArgumentVisibility = .default, expected: String, - file: StaticString = #filePath, - line: UInt = #line + sourceLocation: SourceLocation = #_sourceLocation ) { let help = UsageGenerator( toolName: "example", parsable: T(), visibility: visibility, parent: nil) - XCTAssertEqual(help.synopsis, expected, file: file, line: line) + #expect(help.synopsis == expected, sourceLocation: sourceLocation) } // MARK: - extension UsageGenerationTests { - func testNameSynopsis() { - XCTAssertEqual(Name.long("foo").synopsisString, "--foo") - XCTAssertEqual(Name.short("f").synopsisString, "-f") - XCTAssertEqual(Name.longWithSingleDash("foo").synopsisString, "-foo") + @Test func nameSynopsis() { + #expect(Name.long("foo").synopsisString == "--foo") + #expect(Name.short("f").synopsisString == "-f") + #expect(Name.longWithSingleDash("foo").synopsisString == "-foo") } } @@ -44,8 +42,8 @@ extension UsageGenerationTests { @Option() var title: String } - func testSynopsis() { - _testSynopsis( + @Test func synopsis() { + expectSynopsis( A.self, expected: "example --first-name --title ") } @@ -54,9 +52,10 @@ extension UsageGenerationTests { @Option() var title: String? } - func testSynopsisWithOptional() { - _testSynopsis( - B.self, expected: "example [--first-name <first-name>] [--title <title>]") + @Test func synopsisWithOptional() { + expectSynopsis( + B.self, expected: "example [--first-name <first-name>] [--title <title>]" + ) } struct C: ParsableArguments { @@ -64,8 +63,8 @@ extension UsageGenerationTests { @Flag() var verbose: Int } - func testFlagSynopsis() { - _testSynopsis(C.self, expected: "example [--log] [--verbose ...]") + @Test func flagSynopsis() { + expectSynopsis(C.self, expected: "example [--log] [--verbose ...]") } struct D: ParsableArguments { @@ -73,8 +72,8 @@ extension UsageGenerationTests { @Argument() var title: String? } - func testPositionalSynopsis() { - _testSynopsis(D.self, expected: "example <first-name> [<title>]") + @Test func positionalSynopsis() { + expectSynopsis(D.self, expected: "example <first-name> [<title>]") } struct E: ParsableArguments { @@ -88,8 +87,8 @@ extension UsageGenerationTests { var arg: String = "no-arg" } - func testSynopsisWithDefaults() { - _testSynopsis( + @Test func synopsisWithDefaults() { + expectSynopsis( E.self, expected: "example [--name <name>] [--count <count>] [<arg>]") } @@ -98,8 +97,8 @@ extension UsageGenerationTests { @Argument() var nameCounts: [Int] = [] } - func testSynopsisWithRepeats() { - _testSynopsis( + @Test func synopsisWithRepeats() { + expectSynopsis( F.self, expected: "example [--name <name> ...] [<name-counts> ...]") } @@ -111,8 +110,8 @@ extension UsageGenerationTests { var homePath: String } - func testSynopsisWithCustomization() { - _testSynopsis( + @Test func synopsisWithCustomization() { + expectSynopsis( G.self, expected: "example [--file-path <path>] <user-home-path>") } @@ -121,9 +120,9 @@ extension UsageGenerationTests { @Argument(help: .hidden) var title: String? } - func testSynopsisWithHidden() { - _testSynopsis(H.self, expected: "example") - _testSynopsis( + @Test func synopsisWithHidden() { + expectSynopsis(H.self, expected: "example") + expectSynopsis( H.self, visibility: .hidden, expected: "example [--first-name <first-name>] [<title>]") } @@ -149,8 +148,8 @@ extension UsageGenerationTests { var color: Color = .red } - func testSynopsisWithDefaultValueAndTransform() { - _testSynopsis(I.self, expected: "example [--color <color>]") + @Test func synopsisWithDefaultValueAndTransform() { + expectSynopsis(I.self, expected: "example [--color <color>]") } struct J: ParsableArguments { @@ -159,8 +158,8 @@ extension UsageGenerationTests { @Option(transform: { _ in Foo() }) var opt: Foo? } - func testSynopsisWithTransform() { - _testSynopsis(J.self, expected: "example --req <req> [--opt <opt>]") + @Test func synopsisWithTransform() { + expectSynopsis(J.self, expected: "example --req <req> [--opt <opt>]") } struct K: ParsableArguments { @@ -173,8 +172,8 @@ extension UsageGenerationTests { var time: String? } - func testSynopsisWithMultipleCustomNames() { - _testSynopsis(K.self, expected: "example [--remote <remote>]") + @Test func synopsisWithMultipleCustomNames() { + expectSynopsis(K.self, expected: "example [--remote <remote>]") } struct L: ParsableArguments { @@ -187,8 +186,8 @@ extension UsageGenerationTests { var time: String? } - func testSynopsisWithSingleDashLongNameFirst() { - _testSynopsis(L.self, expected: "example [-remote <remote>]") + @Test func synopsisWithSingleDashLongNameFirst() { + expectSynopsis(L.self, expected: "example [-remote <remote>]") } struct M: ParsableArguments { @@ -219,8 +218,8 @@ extension UsageGenerationTests { @Argument var output: String? } - func testSynopsisWithTooManyOptions() { - _testSynopsis( + @Test func synopsisWithTooManyOptions() { + expectSynopsis( M.self, expected: "example [<options>] --option <option> <input> [<output>]") } @@ -232,9 +231,9 @@ extension UsageGenerationTests { var decode = false } - func testNonwrappedValues() { - _testSynopsis(N.self, expected: "example [--a] [--b]") - _testSynopsis(N.self, visibility: .hidden, expected: "example [--a] [--b]") + @Test func nonwrappedValues() { + expectSynopsis(N.self, expected: "example [--a] [--b]") + expectSynopsis(N.self, visibility: .hidden, expected: "example [--a] [--b]") } struct O: ParsableArguments { @@ -242,7 +241,7 @@ extension UsageGenerationTests { @Argument(parsing: .postTerminator) var b: [String] = [] } - func testSynopsisWithPostTerminatorParsingStrategy() { - _testSynopsis(O.self, expected: "example <a> -- [<b> ...]") + @Test func synopsisWithPostTerminatorParsingStrategy() { + expectSynopsis(O.self, expected: "example <a> -- [<b> ...]") } }