Skip to content

Commit

Permalink
fix(alias): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
heisen-li committed Apr 28, 2024
1 parent f5235c1 commit aac4fce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,13 @@ For more information, see issue #12207 <https://github.com/rust-lang/cargo/issue
let global_args = GlobalArgs::new(sub_args);
let new_args = cli(gctx).no_binary_name(true).try_get_matches_from(alias)?;

let new_cmd =
match new_args.subcommand_name() {
Some(new_cmd) => new_cmd,
None => return Err(anyhow!(
"subcommand is required, add a subcommand to the command alias {cmd} ."
)
.into()),
};
let new_cmd = match new_args.subcommand_name() {
Some(new_cmd) => new_cmd,
None => return Err(anyhow!(
"subcommand is required, add a subcommand to the command alias alias.{cmd}"
)
.into()),
};

already_expanded.push(cmd.to_string());
if already_expanded.contains(&new_cmd.to_string()) {
Expand Down
24 changes: 24 additions & 0 deletions tests/testsuite/cargo_alias_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,27 @@ fn empty_alias() {
)
.run();
}

#[cargo_test]
fn alias_no_subcommand() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/main.rs", "fn main() {}")
.file(
".cargo/config.toml",
r#"
[alias]
a = "--locked"
"#,
)
.build();

p.cargo("a")
.with_status(101)
.with_stderr(
"\
[ERROR] subcommand is required, add a subcommand to the command alias alias.a
",
)
.run();
}

0 comments on commit aac4fce

Please sign in to comment.