-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Reenable testUsage() as testInvalidUsage() #8014
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,10 +48,9 @@ final class PackageCommandTests: CommandsTestCase { | |
XCTAssertMatch(stdout, .contains("USAGE: swift package")) | ||
} | ||
|
||
func testUsage() async throws { | ||
throw XCTSkip("rdar://131126477") | ||
func testInvalidUsage() async throws { | ||
do { | ||
_ = try await execute(["-halp"]) | ||
_ = try await execute(["--xxx"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: Can we add a test, if they don't currently exist, that specified the behaviour when executing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these tests should probably go in swift-argument-parser, since it handles the help arguments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar tests should definitely be included in swift-argument-parser. However, from swift-package-manager perspective, it's an implementation details. This is a |
||
XCTFail("expecting `execute` to fail") | ||
} catch SwiftPMError.executionFailure(_, _, let stderr) { | ||
XCTAssertMatch(stderr, .contains("Usage: swift package")) | ||
|
@@ -69,27 +68,27 @@ final class PackageCommandTests: CommandsTestCase { | |
let stdout = try await execute(["--version"]).stdout | ||
XCTAssertMatch(stdout, .contains("Swift Package Manager")) | ||
} | ||
|
||
func testCompletionTool() async throws { | ||
let stdout = try await execute(["completion-tool", "--help"]).stdout | ||
XCTAssertMatch(stdout, .contains("OVERVIEW: Completion command (for shell completions)")) | ||
} | ||
|
||
func testInitOverview() async throws { | ||
let stdout = try await execute(["init", "--help"]).stdout | ||
XCTAssertMatch(stdout, .contains("OVERVIEW: Initialize a new package")) | ||
} | ||
func testInitUsage() async throws { | ||
let stdout = try await execute(["init", "--help"]).stdout | ||
XCTAssertMatch(stdout, .contains("USAGE: swift package init [--type <type>] ")) | ||
XCTAssertMatch(stdout, .contains(" [--name <name>]")) | ||
} | ||
func testInitOptionsHelp() async throws { | ||
let stdout = try await execute(["init", "--help"]).stdout | ||
XCTAssertMatch(stdout, .contains("OPTIONS:")) | ||
} | ||
func testInitOverview() async throws { | ||
let stdout = try await execute(["init", "--help"]).stdout | ||
XCTAssertMatch(stdout, .contains("OVERVIEW: Initialize a new package")) | ||
} | ||
|
||
func testInitUsage() async throws { | ||
let stdout = try await execute(["init", "--help"]).stdout | ||
XCTAssertMatch(stdout, .contains("USAGE: swift package init [--type <type>] ")) | ||
XCTAssertMatch(stdout, .contains(" [--name <name>]")) | ||
} | ||
|
||
func testInitOptionsHelp() async throws { | ||
let stdout = try await execute(["init", "--help"]).stdout | ||
XCTAssertMatch(stdout, .contains("OPTIONS:")) | ||
} | ||
|
||
func testPlugin() async throws { | ||
await XCTAssertThrowsCommandExecutionError(try await execute(["plugin"])) { error in | ||
|
@@ -2301,13 +2300,13 @@ final class PackageCommandTests: CommandsTestCase { | |
} | ||
|
||
try await runPlugin(flags: [], diagnostics: ["print", "progress", "remark"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
} | ||
|
||
try await runPlugin(flags: [], diagnostics: ["print", "progress", "remark", "warning"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertMatch(stderr, containsWarning) | ||
} | ||
|
||
|
@@ -2330,24 +2329,24 @@ final class PackageCommandTests: CommandsTestCase { | |
} | ||
|
||
try await runPlugin(flags: ["-q"], diagnostics: ["print", "progress"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
} | ||
|
||
try await runPlugin(flags: ["-q"], diagnostics: ["print", "progress", "remark"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
} | ||
|
||
try await runPlugin(flags: ["-q"], diagnostics: ["print", "progress", "remark", "warning"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
} | ||
|
||
try await runPluginWithError(flags: ["-q"], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertNoMatch(stderr, containsRemark) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertNoMatch(stderr, containsRemark) | ||
XCTAssertNoMatch(stderr, containsWarning) | ||
XCTAssertMatch(stderr, containsError) | ||
} | ||
|
@@ -2363,27 +2362,27 @@ final class PackageCommandTests: CommandsTestCase { | |
} | ||
|
||
try await runPlugin(flags: ["-v"], diagnostics: ["print", "progress"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
} | ||
|
||
try await runPlugin(flags: ["-v"], diagnostics: ["print", "progress", "remark"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertMatch(stderr, containsRemark) | ||
} | ||
|
||
try await runPlugin(flags: ["-v"], diagnostics: ["print", "progress", "remark", "warning"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertMatch(stderr, containsRemark) | ||
XCTAssertMatch(stderr, containsWarning) | ||
} | ||
|
||
try await runPluginWithError(flags: ["-v"], diagnostics: ["print", "progress", "remark", "warning", "error"]) { stdout, stderr in | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertMatch(stderr, containsRemark) | ||
XCTAssertMatch(stdout, isOnlyPrint) | ||
XCTAssertMatch(stderr, containsProgress) | ||
XCTAssertMatch(stderr, containsRemark) | ||
XCTAssertMatch(stderr, containsWarning) | ||
XCTAssertMatch(stderr, containsError) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have this radar resolved then? I find it confusing that any option that starts with
-h
leads to this unexpected behavior. We should at least raise this on the SAP repo for them to resolve this first, especially as this is a regression from Swift Argument Parser 1.2.2.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is works as intended, but maybe @natecook1000 can chime in. If any argument resolves to a help flag it takes precedence and shows the help string.
Swift Argument Parser respects combined flags, so
-halp
is equivalent to-h -a -l -p
. Short flags can be combined, and short flags must also be only one character, so-halp
isn’t a valid as a single flag. Only short flags can be combined, so —help-foo won’t match —help.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @rauhul
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised that's the default, given that both
swiftc
andclang
stick to single dash options, and thusclang -fblocks
is clearly not equivalent toclang -f -b -l -o -c -k -s
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swiftc and clang also use options with
-long-name
so I wouldn't take them as amazing prior art. arg parser follows the pattern ofls -asl
andgit clean -Xdf
where short names are combined.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MaxDesiatov @rauhul Any lingering concerns with this PR/behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if
swift build -halp
is parsed the same asswift build -h -a -l -p
and-h
is a valid flag, I'd still expect an error message to be printed about invalid-a -l -p
flags.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @MaxDesiatov .
I also think swift-argument-parser test need to be augmented to cover this case, if they currently don't!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at the current swift package manager behaviour, I think I'm find with it.
Running
swift build -halp
andswift build -alhp
both yield the help usage. That's ok.Running
swift build -alp
yields an error.The usage help should probably indicate
See 'build --help
for more informationor
See 'build -h' for more information. it currently has a single
-before
help`.