fix panic if an alias is defined to ""

This commit is contained in:
Sean Stangl 2021-12-12 13:29:31 -07:00
parent 6df4b1ef71
commit 4c66d18361
3 changed files with 22 additions and 2 deletions

View file

@ -803,6 +803,15 @@ impl Execs {
}
}
#[track_caller]
pub fn run_expect_error(&mut self) {
self.ran = true;
let p = (&self.process_builder).clone().unwrap();
if self.match_process(&p).is_ok() {
panic!("test was expected to fail, but succeeded running {}", p);
}
}
/// Runs the process, checks the expected output, and returns the first
/// JSON object on stdout.
#[track_caller]

View file

@ -55,7 +55,11 @@ fn try_help(config: &Config) -> CargoResult<bool> {
return Ok(true);
}
// Otherwise, resolve the alias into its subcommand.
Some(argv) => argv[0].clone(),
Some(argv) => {
// An alias with an empty argv can be created via `"empty-alias" = ""`.
let first = argv.get(0).map(String::as_str).unwrap_or(subcommand);
first.to_string()
}
None => subcommand.to_string(),
};

View file

@ -146,12 +146,19 @@ fn help_alias() {
config,
r#"
[alias]
simple-alias = ["build"]
empty-alias = ""
simple-alias = "build"
complex-alias = ["build", "--release"]
"#,
)
.unwrap();
// The `empty-alias` returns an error.
cargo_process("help empty-alias")
.env("PATH", Path::new(""))
.with_stderr_contains("[..]The subcommand 'empty-alias' wasn't recognized[..]")
.run_expect_error();
// Because `simple-alias` aliases a subcommand with no arguments, help shows the manpage.
help_with_man_and_path("", "simple-alias", "build", Path::new(""));