Skip to content

Commit 6744fb5

Browse files
smoeliusrami3l
authored andcommitted
Have mocked cargo better adhere to cargo conventions
Currently, when the mocked cargo command is passed `--recursive-cargo-subcommand`, it runs: ``` cargo-foo --recursive-cargo ``` However, cargo subcommands are normally passed their subcommand name as the first argument. Thus, one would expect the following to be run: ``` cargo-foo foo --recursive-cargo ``` This commit changes the mocked cargo command to do the latter. It also adds a check to ensure that the "subcommand name as first argument" behavior is respected. This is, admittedly, a rather pedantic change. Extracted from #4175
1 parent f41403f commit 6744fb5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/test/mock/mock_bin_src.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ use std::path::{Path, PathBuf};
55
use std::process::Command;
66

77
fn main() {
8-
let mut args = env::args_os().skip(1);
8+
let mut args = env::args_os();
9+
let arg0 = args.next().unwrap();
10+
if let Some(cargo_subcommand) = PathBuf::from(arg0)
11+
.file_stem()
12+
.and_then(|s| s.to_str())
13+
.and_then(|s| s.strip_prefix("cargo-"))
14+
{
15+
let arg1 = args.next().unwrap();
16+
assert_eq!(arg1, cargo_subcommand);
17+
}
918
match args.next().as_ref().and_then(|s| s.to_str()) {
1019
Some("--version") => {
1120
let me = env::current_exe().unwrap();
@@ -63,7 +72,7 @@ fn main() {
6372
}
6473
Some("--recursive-cargo-subcommand") => {
6574
let status = Command::new("cargo-foo")
66-
.arg("--recursive-cargo")
75+
.args(["foo", "--recursive-cargo"])
6776
.status()
6877
.unwrap();
6978
assert!(status.success());

0 commit comments

Comments
 (0)