Fix regression when passing arguments to subcommands
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 19 Mar 2018 21:31:37 +0000 (00:31 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 20 Mar 2018 00:34:37 +0000 (03:34 +0300)
src/bin/cargo.rs
tests/testsuite/cargo_command.rs

index d5265250cf79f48b1ac4cae485b7c6293012bba0..7d7c7db6e4cb6882e96539c853b6b9c72cb05c48 100644 (file)
@@ -144,7 +144,7 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli
     let cargo_exe = config.cargo_exe()?;
     let err = match util::process(&command)
         .env(cargo::CARGO_ENV, cargo_exe)
-        .args(&args[1..])
+        .args(args)
         .exec_replace()
     {
         Ok(()) => return Ok(()),
index 7b180ec7a09bc4b1dd3c57fd157612bd3262818c..f3ceeca6318892502d359f1f6ac60058de90f662 100644 (file)
@@ -8,7 +8,7 @@ use cargo;
 use cargotest::cargo_process;
 use cargotest::support::paths::{self, CargoPathExt};
 use cargotest::support::registry::Package;
-use cargotest::support::{basic_bin_manifest, execs, project, Project};
+use cargotest::support::{basic_bin_manifest, cargo_exe, execs, project, Project};
 use hamcrest::{assert_that, existing_file};
 
 #[cfg_attr(windows, allow(dead_code))]
@@ -88,8 +88,6 @@ fn list_command_looks_at_path() {
 #[cfg(unix)]
 #[test]
 fn list_command_resolves_symlinks() {
-    use cargotest::support::cargo_exe;
-
     let proj = project("list-non-overlapping").build();
     let proj = fake_file(
         proj,
@@ -227,8 +225,6 @@ fn override_cargo_home() {
 
 #[test]
 fn cargo_subcommand_env() {
-    use cargotest::support::cargo_exe;
-
     let src = format!(
         r#"
         use std::env;
@@ -262,6 +258,51 @@ fn cargo_subcommand_env() {
     );
 }
 
+#[test]
+fn cargo_subcommand_args() {
+    let p = project("cargo-foo")
+        .file(
+            "Cargo.toml",
+            r#"
+            [package]
+            name = "cargo-foo"
+            version = "0.0.1"
+            authors = []
+        "#,
+        )
+        .file(
+            "src/main.rs",
+            r#"
+            fn main() {
+                let args: Vec<_> = ::std::env::args().collect();
+                println!("{:?}", args);
+            }
+        "#,
+        )
+        .build();
+
+    assert_that(p.cargo("build"), execs().with_status(0));
+    let cargo_foo_bin = p.bin("cargo-foo");
+    assert_that(&cargo_foo_bin, existing_file());
+
+    let mut path = path();
+    path.push(p.target_debug_dir());
+    let path = env::join_paths(path.iter()).unwrap();
+
+    assert_that(
+        cargo_process()
+            .env("PATH", &path)
+            .arg("foo")
+            .arg("bar")
+            .arg("-v")
+            .arg("--help"),
+        execs().with_status(0).with_stdout(format!(
+            r#"[{:?}, "foo", "bar", "-v", "--help"]"#,
+            cargo_foo_bin
+        )),
+    );
+}
+
 #[test]
 fn cargo_help() {
     assert_that(cargo_process(), execs().with_status(0));