Skip to content

Commit aac4fce

Browse files
committed
fix(alias): add test
1 parent f5235c1 commit aac4fce

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/bin/cargo/cli.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,13 @@ For more information, see issue #12207 <https://github.com/rust-lang/cargo/issue
356356
let global_args = GlobalArgs::new(sub_args);
357357
let new_args = cli(gctx).no_binary_name(true).try_get_matches_from(alias)?;
358358

359-
let new_cmd =
360-
match new_args.subcommand_name() {
361-
Some(new_cmd) => new_cmd,
362-
None => return Err(anyhow!(
363-
"subcommand is required, add a subcommand to the command alias {cmd} ."
364-
)
365-
.into()),
366-
};
359+
let new_cmd = match new_args.subcommand_name() {
360+
Some(new_cmd) => new_cmd,
361+
None => return Err(anyhow!(
362+
"subcommand is required, add a subcommand to the command alias alias.{cmd}"
363+
)
364+
.into()),
365+
};
367366

368367
already_expanded.push(cmd.to_string());
369368
if already_expanded.contains(&new_cmd.to_string()) {

tests/testsuite/cargo_alias_config.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,27 @@ fn empty_alias() {
463463
)
464464
.run();
465465
}
466+
467+
#[cargo_test]
468+
fn alias_no_subcommand() {
469+
let p = project()
470+
.file("Cargo.toml", &basic_bin_manifest("foo"))
471+
.file("src/main.rs", "fn main() {}")
472+
.file(
473+
".cargo/config.toml",
474+
r#"
475+
[alias]
476+
a = "--locked"
477+
"#,
478+
)
479+
.build();
480+
481+
p.cargo("a")
482+
.with_status(101)
483+
.with_stderr(
484+
"\
485+
[ERROR] subcommand is required, add a subcommand to the command alias alias.a
486+
",
487+
)
488+
.run();
489+
}

0 commit comments

Comments
 (0)