mirror of
https://github.com/rust-lang/cargo
synced 2024-10-02 14:04:23 +00:00
fix panic if an alias is defined to ""
This commit is contained in:
parent
6df4b1ef71
commit
4c66d18361
|
@ -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]
|
||||
|
|
|
@ -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(),
|
||||
};
|
||||
|
||||
|
|
|
@ -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(""));
|
||||
|
||||
|
|
Loading…
Reference in a new issue