test(cli): Verify precedence over external subcommands

This commit is contained in:
Ed Page 2023-06-08 13:27:40 -05:00
parent 21736eda0c
commit b2b4d9771f
2 changed files with 58 additions and 1 deletions

View File

@ -110,7 +110,9 @@ impl FileBuilder {
fn mk(&mut self) {
if self.executable {
self.path.set_extension(env::consts::EXE_EXTENSION);
let mut path = self.path.clone().into_os_string();
write!(path, "{}", env::consts::EXE_SUFFIX).unwrap();
self.path = path.into();
}
self.dirname().mkdir_p();

View File

@ -9,6 +9,10 @@ fn main() {
}
"#;
fn path() -> Vec<std::path::PathBuf> {
std::env::split_paths(&std::env::var_os("PATH").unwrap_or_default()).collect()
}
#[cargo_test]
fn basic_rs() {
let p = cargo_test_support::project()
@ -68,6 +72,57 @@ error: no such command: `echo`
.run();
}
#[cargo_test]
#[cfg(unix)]
fn manifest_precedence_over_plugins() {
let p = cargo_test_support::project()
.file("echo.rs", ECHO_SCRIPT)
.executable(std::path::Path::new("path-test").join("cargo-echo.rs"), "")
.build();
// With path - fmt is there with known description
let mut path = path();
path.push(p.root().join("path-test"));
let path = std::env::join_paths(path.iter()).unwrap();
p.cargo("-Zscript echo.rs")
.arg("--help") // An arg that, if processed by cargo, will cause problems
.env("PATH", &path)
.masquerade_as_nightly_cargo(&["script"])
.with_status(101)
.with_stdout("")
.with_stderr("\
thread 'main' panicked at 'not yet implemented: support for running manifest-commands is not yet implemented', [..]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
")
.run();
}
#[cargo_test]
#[cfg(unix)]
fn manifest_precedence_over_plugins_stable() {
let p = cargo_test_support::project()
.file("echo.rs", ECHO_SCRIPT)
.executable(std::path::Path::new("path-test").join("cargo-echo.rs"), "")
.build();
let mut path = path();
path.push(p.root().join("path-test"));
let path = std::env::join_paths(path.iter()).unwrap();
p.cargo("echo.rs")
.arg("--help") // An arg that, if processed by cargo, will cause problems
.env("PATH", &path)
.with_status(101)
.with_stdout("")
.with_stderr(
"\
error: running `echo.rs` requires `-Zscript`
",
)
.run();
}
#[cargo_test]
fn requires_nightly() {
let p = cargo_test_support::project()