Skip to content

Commit

Permalink
add some test & fix some error
Browse files Browse the repository at this point in the history
  • Loading branch information
heisen-li committed Nov 3, 2023
1 parent 3fc6b53 commit 1dc82ae
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 22 deletions.
34 changes: 15 additions & 19 deletions src/bin/cargo/commands/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub fn cli() -> Command {
cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]
cargo owner list [CRATE_NAME] [OPTIONS]",
)
// The following three parameters are planned to be replaced in the form of subcommands.
// refer to issue: https://github.com/rust-lang/cargo/issues/4352
.arg(
multi_opt(
"add",
Expand All @@ -38,10 +36,9 @@ pub fn cli() -> Command {
)
.arg(flag("list", "List owners of a crate").short('l').hide(true))
.subcommands([
for_subcommand_add_arg(
add_registry_args(
Command::new("add")
.about("Name of a user or team to invite as an owner")
.arg_quiet()
.args([
Arg::new("add")
.required(true)
Expand All @@ -52,11 +49,11 @@ pub fn cli() -> Command {
.value_name("CRATE_NAME")
.help("Crate name that you want to manage the owner"),
]),
),
for_subcommand_add_arg(
)
.override_usage("cargo owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]"),
add_registry_args(
Command::new("remove")
.about("Name of a user or team to remove as an owner")
.arg_quiet()
.args([
Arg::new("remove")
.required(true)
Expand All @@ -67,17 +64,16 @@ pub fn cli() -> Command {
.value_name("CRATE_NAME")
.help("Crate name that you want to manage the owner"),
]),
),
for_subcommand_add_arg(
Command::new("list")
.about("List owners of a crate")
.arg_quiet()
.arg(
Arg::new("crate")
.value_name("CRATE_NAME")
.help("Crate name which you want to list all owner names"),
),
),
)
.override_usage("cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]"),
add_registry_args(
Command::new("list").about("List owners of a crate").arg(
Arg::new("crate")
.value_name("CRATE_NAME")
.help("Crate name which you want to list all owner names"),
),
)
.override_usage("cargo owner list [CRATE_NAME] [OPTIONS]"),
])
.arg_index("Registry index URL to modify owners for")
.arg_registry("Registry to modify owners for")
Expand All @@ -87,7 +83,7 @@ pub fn cli() -> Command {
))
}

fn for_subcommand_add_arg(command: Command) -> Command {
fn add_registry_args(command: Command) -> Command {
command
.arg_index("Registry index URL to modify owners for")
.arg_registry("Registry to modify owners for")
Expand Down
14 changes: 14 additions & 0 deletions tests/testsuite/cargo_owner/add_help/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;

#[cargo_test]
fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("owner")
.arg("add")
.arg("--help")
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
Empty file.
22 changes: 22 additions & 0 deletions tests/testsuite/cargo_owner/add_help/stdout.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Name of a user or team to invite as an owner

Usage: cargo owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]

Arguments:
<OWNER_NAME> Name of the owner you want to invite
[CRATE_NAME] Crate name that you want to manage the owner

Options:
--index <INDEX> Registry index URL to modify owners for
--registry <REGISTRY> Registry to modify owners for
--token <TOKEN> API token to use when authenticating
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
--config <KEY=VALUE> Override a configuration value
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
-h, --help Print help

Manifest Options:
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
--offline Run without accessing the network
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_owner/help/stdout.log
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Manage the owners of a crate on the registry

Usage: cargo owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]
cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]
cargo owner list [CRATE_NAME] [OPTIONS]
Usage: cargo[EXE] owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]
cargo[EXE] owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]
cargo[EXE] owner list [CRATE_NAME] [OPTIONS]

Commands:
add Name of a user or team to invite as an owner
Expand Down
14 changes: 14 additions & 0 deletions tests/testsuite/cargo_owner/list_help/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;

#[cargo_test]
fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("owner")
.arg("list")
.arg("--help")
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
Empty file.
21 changes: 21 additions & 0 deletions tests/testsuite/cargo_owner/list_help/stdout.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
List owners of a crate

Usage: cargo owner list [CRATE_NAME] [OPTIONS]

Arguments:
[CRATE_NAME] Crate name which you want to list all owner names

Options:
--index <INDEX> Registry index URL to modify owners for
--registry <REGISTRY> Registry to modify owners for
--token <TOKEN> API token to use when authenticating
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
--config <KEY=VALUE> Override a configuration value
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
-h, --help Print help

Manifest Options:
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
--offline Run without accessing the network
3 changes: 3 additions & 0 deletions tests/testsuite/cargo_owner/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
mod add_help;
mod help;
mod list_help;
mod remove_help;
14 changes: 14 additions & 0 deletions tests/testsuite/cargo_owner/remove_help/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use cargo_test_support::curr_dir;
use cargo_test_support::prelude::*;

#[cargo_test]
fn case() {
snapbox::cmd::Command::cargo_ui()
.arg("owner")
.arg("remove")
.arg("--help")
.assert()
.success()
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));
}
Empty file.
22 changes: 22 additions & 0 deletions tests/testsuite/cargo_owner/remove_help/stdout.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Name of a user or team to remove as an owner

Usage: cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]

Arguments:
<OWNER_NAME> Name of the owner you want to remove
[CRATE_NAME] Crate name that you want to manage the owner

Options:
--index <INDEX> Registry index URL to modify owners for
--registry <REGISTRY> Registry to modify owners for
--token <TOKEN> API token to use when authenticating
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
--color <WHEN> Coloring: auto, always, never
--config <KEY=VALUE> Override a configuration value
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
-h, --help Print help

Manifest Options:
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
--offline Run without accessing the network

0 comments on commit 1dc82ae

Please sign in to comment.