…lines 1–12 unchanged (12 lines)
13import XCTest
14
15@testable import ArgumentParser
16
17final class HelpTests: XCTestCase {
18 override func setUp() {
19 Platform.Environment[.columns] = nil
20 }
21}
22
23func getErrorText<T: ParsableArguments>(_: T.Type, _ arguments: [String])
24 -> String
25{
…lines 26–49 unchanged (24 lines)
50
51// swift-format-ignore: AlwaysUseLowerCamelCase
52// https://github.com/apple/swift-argument-parser/issues/710
53extension HelpTests {
54 func testGlobalHelp() throws {
55 XCTAssertEqual(
56 getErrorText(Package.self, ["help"]),
57 """
58 USAGE: package <subcommand>
59
60 OPTIONS:
61 -h, --help Show help information.
62
63 SUBCOMMANDS:
64 clean
65 config
66 describe
67 generate-xcodeproj
68
69 See 'package help <subcommand>' for detailed help.
70 """)
71 }
72
73 func testGlobalHelp_messageForCleanExit_helpRequest() throws {
74 XCTAssertEqual(
75 Package.message(for: CleanExit.helpRequest()),
76 """
77 USAGE: package <subcommand>
78
79 OPTIONS:
80 -h, --help Show help information.
81
82 SUBCOMMANDS:
83 clean
84 config
85 describe
86 generate-xcodeproj
87
88 See 'package help <subcommand>' for detailed help.
89 """
90 )
91 }
92
93 func testGlobalHelp_messageForCleanExit_message() throws {
94 let expectedMessage = "Failure"
95 XCTAssertEqual(
96 Package.message(for: CleanExit.message(expectedMessage)),
97 expectedMessage
98 )
99 }
100
101 func testConfigHelp() throws {
102 XCTAssertEqual(
103 getErrorText(Package.self, ["help", "config"], screenWidth: 80),
104 """
105 USAGE: package config <subcommand>
106
107 OPTIONS:
108 -h, --help Show help information.
109
110 SUBCOMMANDS:
111 get-mirror
112 set-mirror
113 unset-mirror
114
115 See 'package help config <subcommand>' for detailed help.
116 """)
117 }
118
119 func testGetMirrorHelp() throws {
120 XCTAssertEqual(
121 getErrorText(
122 Package.self, ["help", "config", "get-mirror"], screenWidth: 80
123 ),
124 """
125 USAGE: package config get-mirror [<options>] --package-url <package-url>
126
127 OPTIONS:
128 --build-path <build-path>
129 Specify build/cache directory (default: ./.build)
…lines 130–162 unchanged (33 lines)
163 -Xswiftc <swift-compiler-flag>
164 Pass flag through to all Swift compiler invocations
165 --package-url <package-url>
166 The package dependency URL
167 -h, --help Show help information.
168
169 """)
170 }
171}
172
173struct Simple: ParsableArguments {
174 @Flag var verbose: Bool = false
175 @Option() var min: Int?
…lines 176–183 unchanged (8 lines)
184 OPTIONS:
185 --verbose
186 --min <min>
187 -h, --help Show help information.
188
189 """
190}
191
192extension HelpTests {
193 func testSimpleHelp() throws {
194 XCTAssertEqual(
195 getErrorText(Simple.self, ["--help"]),
196 Simple.helpText)
197 XCTAssertEqual(
198 getErrorText(Simple.self, ["-h"]),
199 Simple.helpText)
200 }
201}
202
203struct CustomHelp: ParsableCommand {
204 static let configuration = CommandConfiguration(
…lines 205–243 unchanged (39 lines)
244 Error: Missing expected argument '--count <count>'
245 Help: --count <count> How many florps?
246 Usage: no-help --count <count>
247 """)
248
249 XCTAssertEqual(
250 NoHelp.message(for: CleanExit.helpRequest()),
251 """
252 USAGE: no-help --count <count>
253
254 OPTIONS:
255 --count <count> How many florps?
256
…lines 257–307 unchanged (51 lines)