diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index 646200a76c3..9ed4f7a1ed0 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -87,12 +87,12 @@ fn list_command_looks_at_path() { "cargo-1", &FakeKind::Executable, ); - let mut pr = cargo_process(); let mut path = path(); path.push(proj.root().join("path-test")); let path = env::join_paths(path.iter()).unwrap(); - let output = pr.arg("-v").arg("--list").env("PATH", &path); + let mut p = cargo_process("-v --list"); + let output = p.env("PATH", &path); let output = output.exec_with_output().unwrap(); let output = str::from_utf8(&output.stdout).unwrap(); assert!( @@ -115,12 +115,12 @@ fn list_command_resolves_symlinks() { target: &cargo_exe(), }, ); - let mut pr = cargo_process(); let mut path = path(); path.push(proj.root().join("path-test")); let path = env::join_paths(path.iter()).unwrap(); - let output = pr.arg("-v").arg("--list").env("PATH", &path); + let mut p = cargo_process("-v --list"); + let output = p.env("PATH", &path); let output = output.exec_with_output().unwrap(); let output = str::from_utf8(&output.stdout).unwrap(); assert!( @@ -133,7 +133,7 @@ fn list_command_resolves_symlinks() { #[test] fn find_closest_biuld_to_build() { assert_that( - cargo_process().arg("biuld"), + cargo_process("biuld"), execs().with_status(101).with_stderr_contains( "\ error: no such subcommand: `biuld` @@ -157,17 +157,17 @@ error: no such subcommand: `biuld` .publish(); assert_that( - cargo_process().arg("install").arg("cargo-biuld"), + cargo_process("install cargo-biuld"), execs().with_status(0), ); assert_that( - cargo_process().arg("biuld"), + cargo_process("biuld"), execs() .with_status(0) .with_stdout("Similar, but not identical to, build\n"), ); assert_that( - cargo_process().arg("--list"), + cargo_process("--list"), execs() .with_status(0) .with_stdout_contains(" build Compile a local package and all of its dependencies\n") @@ -178,12 +178,9 @@ error: no such subcommand: `biuld` // if a subcommand is more than 3 edit distance away, we don't make a suggestion #[test] fn find_closest_dont_correct_nonsense() { - let mut pr = cargo_process(); - pr.arg("there-is-no-way-that-there-is-a-command-close-to-this") - .cwd(&paths::root()); - assert_that( - pr, + cargo_process("there-is-no-way-that-there-is-a-command-close-to-this") + .cwd(&paths::root()), execs().with_status(101).with_stderr( "[ERROR] no such subcommand: \ `there-is-no-way-that-there-is-a-command-close-to-this` @@ -194,15 +191,11 @@ fn find_closest_dont_correct_nonsense() { #[test] fn displays_subcommand_on_error() { - let mut pr = cargo_process(); - pr.arg("invalid-command"); - assert_that( - pr, - execs().with_status(101).with_stderr( - "[ERROR] no such subcommand: `invalid-command` -", - ), + cargo_process("invalid-command"), + execs() + .with_status(101) + .with_stderr("[ERROR] no such subcommand: `invalid-command`\n"), ); } @@ -224,11 +217,7 @@ fn override_cargo_home() { .unwrap(); assert_that( - cargo_process() - .arg("new") - .arg("foo") - .env("USER", "foo") - .env("CARGO_HOME", &my_home), + cargo_process("new foo").env("USER", "foo").env("CARGO_HOME", &my_home), execs().with_status(0), ); @@ -264,14 +253,13 @@ fn cargo_subcommand_env() { assert_that(p.cargo("build"), execs().with_status(0)); assert_that(&p.bin("cargo-envtest"), existing_file()); - let mut pr = cargo_process(); let cargo = cargo_exe().canonicalize().unwrap(); let mut path = path(); path.push(target_dir); let path = env::join_paths(path.iter()).unwrap(); assert_that( - pr.arg("envtest").env("PATH", &path), + cargo_process("envtest").env("PATH", &path), execs().with_status(0).with_stdout(cargo.to_str().unwrap()), ); } @@ -300,12 +288,7 @@ fn cargo_subcommand_args() { let path = env::join_paths(path.iter()).unwrap(); assert_that( - cargo_process() - .env("PATH", &path) - .arg("foo") - .arg("bar") - .arg("-v") - .arg("--help"), + cargo_process("foo bar -v --help").env("PATH", &path), execs().with_status(0).with_stdout(format!( r#"[{:?}, "foo", "bar", "-v", "--help"]"#, cargo_foo_bin @@ -315,21 +298,12 @@ fn cargo_subcommand_args() { #[test] fn cargo_help() { - assert_that(cargo_process(), execs().with_status(0)); - assert_that(cargo_process().arg("help"), execs().with_status(0)); - assert_that(cargo_process().arg("-h"), execs().with_status(0)); - assert_that( - cargo_process().arg("help").arg("build"), - execs().with_status(0), - ); - assert_that( - cargo_process().arg("build").arg("-h"), - execs().with_status(0), - ); - assert_that( - cargo_process().arg("help").arg("help"), - execs().with_status(0), - ); + assert_that(cargo_process(""), execs().with_status(0)); + assert_that(cargo_process("help"), execs().with_status(0)); + assert_that(cargo_process("-h"), execs().with_status(0)); + assert_that(cargo_process("help build"), execs().with_status(0)); + assert_that(cargo_process("build -h"), execs().with_status(0)); + assert_that(cargo_process("help help"), execs().with_status(0)); } #[test] @@ -346,11 +320,11 @@ fn cargo_help_external_subcommand() { ) .publish(); assert_that( - cargo_process().args(&["install", "cargo-fake-help"]), + cargo_process("install cargo-fake-help"), execs().with_status(0), ); assert_that( - cargo_process().args(&["help", "fake-help"]), + cargo_process("help fake-help"), execs().with_status(0).with_stdout("fancy help output\n") ); } @@ -358,7 +332,7 @@ fn cargo_help_external_subcommand() { #[test] fn explain() { assert_that( - cargo_process().arg("--explain").arg("E0001"), + cargo_process("--explain E0001"), execs().with_status(0).with_stdout_contains( "This error suggests that the expression arm corresponding to the noted pattern", ), @@ -370,7 +344,7 @@ fn explain() { #[test] fn z_flags_help() { assert_that( - cargo_process().arg("-Z").arg("help"), + cargo_process("-Z help"), execs().with_status(0).with_stdout_contains( " -Z unstable-options -- Allow the usage of unstable options such as --registry", ), diff --git a/tests/testsuite/concurrent.rs b/tests/testsuite/concurrent.rs index 645eb3c5ad9..fc2ea285d43 100644 --- a/tests/testsuite/concurrent.rs +++ b/tests/testsuite/concurrent.rs @@ -8,7 +8,7 @@ use std::sync::mpsc::channel; use std::time::Duration; use git2; -use support; +use support::cargo_process; use support::install::{cargo_home, has_installed_exe}; use support::git; use support::registry::Package; @@ -57,14 +57,8 @@ fn concurrent_installs() { pkg("foo", "0.0.1"); pkg("bar", "0.0.1"); - let mut a = support::cargo_process() - .arg("install") - .arg("foo") - .build_command(); - let mut b = support::cargo_process() - .arg("install") - .arg("bar") - .build_command(); + let mut a = cargo_process("install foo").build_command(); + let mut b = cargo_process("install bar").build_command(); a.stdout(Stdio::piped()).stderr(Stdio::piped()); b.stdout(Stdio::piped()).stderr(Stdio::piped()); diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index 20067c87b2a..aa1c377372c 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -135,7 +135,7 @@ fn simple_install() { .build(); assert_that( - cargo_process().arg("install").arg("bar"), + cargo_process("install bar"), execs().with_status(0).with_stderr( " Installing bar v0.1.0 Compiling foo v0.0.1 @@ -174,7 +174,7 @@ fn simple_install_fail() { .build(); assert_that( - cargo_process().arg("install").arg("bar"), + cargo_process("install bar"), execs().with_status(101).with_stderr( " Installing bar v0.1.0 error: failed to compile `bar v0.1.0`, intermediate artifacts can be found at `[..]` @@ -218,7 +218,7 @@ fn install_without_feature_dep() { .build(); assert_that( - cargo_process().arg("install").arg("bar"), + cargo_process("install bar"), execs().with_status(0).with_stderr( " Installing bar v0.1.0 Compiling foo v0.0.1 diff --git a/tests/testsuite/init.rs b/tests/testsuite/init.rs index fd9fb93a6ee..bf90178bf49 100644 --- a/tests/testsuite/init.rs +++ b/tests/testsuite/init.rs @@ -4,23 +4,19 @@ use std::io::prelude::*; use std::env; use cargo::util::ProcessBuilder; -use support::{cargo_exe, execs, paths}; +use support::{execs, paths}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = support::process(&cargo_exe()); - p.arg(s).cwd(&paths::root()).env("HOME", &paths::home()); + let mut p = support::cargo_process(s); + p.cwd(&paths::root()).env("HOME", &paths::home()); p } #[test] fn simple_lib() { assert_that( - cargo_process("init") - .arg("--lib") - .arg("--vcs") - .arg("none") - .env("USER", "foo"), + cargo_process("init --lib --vcs none").env("USER", "foo"), execs() .with_status(0) .with_stderr("[CREATED] library project"), @@ -38,12 +34,7 @@ fn simple_bin() { let path = paths::root().join("foo"); fs::create_dir(&path).unwrap(); assert_that( - cargo_process("init") - .arg("--bin") - .arg("--vcs") - .arg("none") - .env("USER", "foo") - .cwd(&path), + cargo_process("init --bin --vcs none").env("USER", "foo").cwd(&path), execs() .with_status(0) .with_stderr("[CREATED] binary (application) project"), @@ -62,10 +53,7 @@ fn simple_bin() { #[test] fn both_lib_and_bin() { assert_that( - cargo_process("init") - .arg("--lib") - .arg("--bin") - .env("USER", "foo"), + cargo_process("init --lib --bin").env("USER", "foo"), execs() .with_status(101) .with_stderr("[ERROR] can't specify both lib and binary outputs"), @@ -91,21 +79,12 @@ fn bin_already_exists(explicit: bool, rellocation: &str) { if explicit { assert_that( - cargo_process("init") - .arg("--bin") - .arg("--vcs") - .arg("none") - .env("USER", "foo") - .cwd(&path), + cargo_process("init --bin --vcs none").env("USER", "foo").cwd(&path), execs().with_status(0), ); } else { assert_that( - cargo_process("init") - .arg("--vcs") - .arg("none") - .env("USER", "foo") - .cwd(&path), + cargo_process("init --vcs none").env("USER", "foo").cwd(&path), execs().with_status(0), ); } @@ -175,11 +154,7 @@ fn confused_by_multiple_lib_files() { .unwrap(); assert_that( - cargo_process("init") - .arg("--vcs") - .arg("none") - .env("USER", "foo") - .cwd(&path), + cargo_process("init --vcs none").env("USER", "foo").cwd(&path), execs().with_status(101).with_stderr( "[ERROR] cannot have a project with multiple libraries, found both `src/lib.rs` and `lib.rs`", ), @@ -211,12 +186,7 @@ fn multibin_project_name_clash() { .unwrap(); assert_that( - cargo_process("init") - .arg("--lib") - .arg("--vcs") - .arg("none") - .env("USER", "foo") - .cwd(&path), + cargo_process("init --lib --vcs none").env("USER", "foo").cwd(&path), execs().with_status(101).with_stderr( "\ [ERROR] multiple possible binary sources found: @@ -249,11 +219,7 @@ fn lib_already_exists(rellocation: &str) { .unwrap(); assert_that( - cargo_process("init") - .arg("--vcs") - .arg("none") - .env("USER", "foo") - .cwd(&path), + cargo_process("init --vcs none").env("USER", "foo").cwd(&path), execs().with_status(0), ); @@ -285,11 +251,7 @@ fn lib_already_exists_nosrc() { #[test] fn simple_git() { assert_that( - cargo_process("init") - .arg("--lib") - .arg("--vcs") - .arg("git") - .env("USER", "foo"), + cargo_process("init --lib --vcs git").env("USER", "foo"), execs().with_status(0), ); @@ -302,9 +264,7 @@ fn simple_git() { #[test] fn auto_git() { assert_that( - cargo_process("init") - .arg("--lib") - .env("USER", "foo"), + cargo_process("init --lib").env("USER", "foo"), execs().with_status(0), ); @@ -353,7 +313,7 @@ fn git_autodetect() { fs::create_dir(&paths::root().join(".git")).unwrap(); assert_that( - cargo_process("init").arg("--lib").env("USER", "foo"), + cargo_process("init --lib").env("USER", "foo"), execs().with_status(0), ); @@ -368,7 +328,7 @@ fn mercurial_autodetect() { fs::create_dir(&paths::root().join(".hg")).unwrap(); assert_that( - cargo_process("init").arg("--lib").env("USER", "foo"), + cargo_process("init --lib").env("USER", "foo"), execs().with_status(0), ); @@ -388,7 +348,7 @@ fn gitignore_appended_not_replaced() { .unwrap(); assert_that( - cargo_process("init").arg("--lib").env("USER", "foo"), + cargo_process("init --lib").env("USER", "foo"), execs().with_status(0), ); @@ -415,7 +375,7 @@ fn gitignore_added_newline_in_existing() { .unwrap(); assert_that( - cargo_process("init").arg("--lib").env("USER", "foo"), + cargo_process("init --lib").env("USER", "foo"), execs().with_status(0), ); @@ -434,7 +394,7 @@ fn gitignore_no_newline_in_new() { fs::create_dir(&paths::root().join(".git")).unwrap(); assert_that( - cargo_process("init").arg("--lib").env("USER", "foo"), + cargo_process("init --lib").env("USER", "foo"), execs().with_status(0), ); @@ -458,7 +418,7 @@ fn mercurial_added_newline_in_existing() { .unwrap(); assert_that( - cargo_process("init").arg("--lib").env("USER", "foo"), + cargo_process("init --lib").env("USER", "foo"), execs().with_status(0), ); @@ -477,7 +437,7 @@ fn mercurial_no_newline_in_new() { fs::create_dir(&paths::root().join(".hg")).unwrap(); assert_that( - cargo_process("init").arg("--lib").env("USER", "foo"), + cargo_process("init --lib").env("USER", "foo"), execs().with_status(0), ); @@ -496,11 +456,7 @@ fn cargo_lock_gitignored_if_lib1() { fs::create_dir(&paths::root().join(".git")).unwrap(); assert_that( - cargo_process("init") - .arg("--lib") - .arg("--vcs") - .arg("git") - .env("USER", "foo"), + cargo_process("init --lib --vcs git").env("USER", "foo"), execs().with_status(0), ); @@ -524,10 +480,7 @@ fn cargo_lock_gitignored_if_lib2() { .unwrap(); assert_that( - cargo_process("init") - .arg("--vcs") - .arg("git") - .env("USER", "foo"), + cargo_process("init --vcs git").env("USER", "foo"), execs().with_status(0), ); @@ -546,11 +499,7 @@ fn cargo_lock_not_gitignored_if_bin1() { fs::create_dir(&paths::root().join(".git")).unwrap(); assert_that( - cargo_process("init") - .arg("--vcs") - .arg("git") - .arg("--bin") - .env("USER", "foo"), + cargo_process("init --vcs git --bin").env("USER", "foo"), execs().with_status(0), ); @@ -574,10 +523,7 @@ fn cargo_lock_not_gitignored_if_bin2() { .unwrap(); assert_that( - cargo_process("init") - .arg("--vcs") - .arg("git") - .env("USER", "foo"), + cargo_process("init --vcs git").env("USER", "foo"), execs().with_status(0), ); @@ -594,11 +540,7 @@ fn cargo_lock_not_gitignored_if_bin2() { #[test] fn with_argument() { assert_that( - cargo_process("init") - .arg("foo") - .arg("--vcs") - .arg("none") - .env("USER", "foo"), + cargo_process("init foo --vcs none").env("USER", "foo"), execs().with_status(0), ); assert_that(&paths::root().join("foo/Cargo.toml"), existing_file()); @@ -607,7 +549,7 @@ fn with_argument() { #[test] fn unknown_flags() { assert_that( - cargo_process("init").arg("foo").arg("--flag"), + cargo_process("init foo --flag"), execs().with_status(1).with_stderr_contains( "error: Found argument '--flag' which wasn't expected, or isn't valid in this context", ), @@ -618,7 +560,7 @@ fn unknown_flags() { #[test] fn no_filename() { assert_that( - cargo_process("init").arg("/"), + cargo_process("init /"), execs().with_status(101).with_stderr( "[ERROR] cannot auto-detect project name from path \"/\" ; use --name to override" .to_string(), diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 867b4ab56b1..209e6efbc19 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -2,23 +2,16 @@ use support; use std::fs::{self, File, OpenOptions}; use std::io::prelude::*; -use cargo::util::ProcessBuilder; use support::install::{cargo_home, has_installed_exe}; use support::cross_compile; use support::git; use support::paths; use support::registry::Package; -use support::{basic_manifest, execs, project}; +use support::{basic_manifest, cargo_process, execs, project}; use support::ChannelChanger; use git2; use support::hamcrest::{assert_that, existing_dir, is_not}; -fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = support::cargo_process(); - p.arg(s); - p -} - fn pkg(name: &str, vers: &str) { Package::new(name, vers) .file("src/lib.rs", "") @@ -31,7 +24,7 @@ fn simple() { pkg("foo", "0.0.1"); assert_that( - cargo_process("install").arg("foo"), + cargo_process("install foo"), execs().with_status(0).with_stderr(&format!( "\ [UPDATING] registry `[..]` @@ -48,7 +41,7 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina assert_that(cargo_home(), has_installed_exe("foo")); assert_that( - cargo_process("uninstall").arg("foo"), + cargo_process("uninstall foo"), execs().with_status(0).with_stderr(&format!( "[REMOVING] {home}[..]bin[..]foo[..]", home = cargo_home().display() @@ -63,7 +56,7 @@ fn multiple_pkgs() { pkg("bar", "0.0.2"); assert_that( - cargo_process("install").args(&["foo", "bar", "baz"]), + cargo_process("install foo bar baz"), execs().with_status(101).with_stderr(&format!( "\ [UPDATING] registry `[..]` @@ -89,7 +82,7 @@ error: some crates failed to install assert_that(cargo_home(), has_installed_exe("bar")); assert_that( - cargo_process("uninstall").args(&["foo", "bar"]), + cargo_process("uninstall foo bar"), execs().with_status(0).with_stderr(&format!( "\ [REMOVING] {home}[..]bin[..]foo[..] @@ -113,7 +106,7 @@ fn pick_max_version() { pkg("foo", "0.3.0-pre.2"); assert_that( - cargo_process("install").arg("foo"), + cargo_process("install foo"), execs().with_status(0).with_stderr(&format!( "\ [UPDATING] registry `[..]` @@ -138,10 +131,7 @@ fn installs_beta_version_by_explicit_name_from_git() { .build(); assert_that( - cargo_process("install") - .arg("--git") - .arg(p.url().to_string()) - .arg("foo"), + cargo_process("install --git").arg(p.url().to_string()).arg("foo"), execs().with_status(0), ); assert_that(cargo_home(), has_installed_exe("foo")); @@ -151,7 +141,7 @@ fn installs_beta_version_by_explicit_name_from_git() { fn missing() { pkg("foo", "0.0.1"); assert_that( - cargo_process("install").arg("bar"), + cargo_process("install bar"), execs().with_status(101).with_stderr( "\ [UPDATING] registry [..] @@ -165,7 +155,7 @@ fn missing() { fn bad_version() { pkg("foo", "0.0.1"); assert_that( - cargo_process("install").arg("foo").arg("--vers=0.2.0"), + cargo_process("install foo --vers=0.2.0"), execs().with_status(101).with_stderr( "\ [UPDATING] registry [..] @@ -220,11 +210,7 @@ fn install_location_precedence() { println!("install --root"); assert_that( - cargo_process("install") - .arg("foo") - .arg("--root") - .arg(&t1) - .env("CARGO_INSTALL_ROOT", &t2), + cargo_process("install foo --root").arg(&t1).env("CARGO_INSTALL_ROOT", &t2), execs().with_status(0), ); assert_that(&t1, has_installed_exe("foo")); @@ -233,9 +219,7 @@ fn install_location_precedence() { println!("install CARGO_INSTALL_ROOT"); assert_that( - cargo_process("install") - .arg("foo") - .env("CARGO_INSTALL_ROOT", &t2), + cargo_process("install foo").env("CARGO_INSTALL_ROOT", &t2), execs().with_status(0), ); assert_that(&t2, has_installed_exe("foo")); @@ -243,7 +227,7 @@ fn install_location_precedence() { println!("install install.root"); - assert_that(cargo_process("install").arg("foo"), execs().with_status(0)); + assert_that(cargo_process("install foo"), execs().with_status(0)); assert_that(&t3, has_installed_exe("foo")); assert_that(&t4, is_not(has_installed_exe("foo"))); @@ -251,7 +235,7 @@ fn install_location_precedence() { println!("install cargo home"); - assert_that(cargo_process("install").arg("foo"), execs().with_status(0)); + assert_that(cargo_process("install foo"), execs().with_status(0)); assert_that(&t4, has_installed_exe("foo")); } @@ -262,15 +246,12 @@ fn install_path() { .build(); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(0), ); assert_that(cargo_home(), has_installed_exe("foo")); assert_that( - cargo_process("install") - .arg("--path") - .arg(".") - .cwd(p.root()), + cargo_process("install --path .").cwd(p.root()), execs().with_status(101).with_stderr( "\ [INSTALLING] foo v0.0.1 [..] @@ -291,9 +272,7 @@ fn multiple_crates_error() { .build(); assert_that( - cargo_process("install") - .arg("--git") - .arg(p.url().to_string()), + cargo_process("install --git").arg(p.url().to_string()), execs().with_status(101).with_stderr( "\ [UPDATING] git repository [..] @@ -313,20 +292,14 @@ fn multiple_crates_select() { .build(); assert_that( - cargo_process("install") - .arg("--git") - .arg(p.url().to_string()) - .arg("foo"), + cargo_process("install --git").arg(p.url().to_string()).arg("foo"), execs().with_status(0), ); assert_that(cargo_home(), has_installed_exe("foo")); assert_that(cargo_home(), is_not(has_installed_exe("bar"))); assert_that( - cargo_process("install") - .arg("--git") - .arg(p.url().to_string()) - .arg("bar"), + cargo_process("install --git").arg(p.url().to_string()).arg("bar"), execs().with_status(0), ); assert_that(cargo_home(), has_installed_exe("bar")); @@ -353,7 +326,7 @@ fn multiple_crates_auto_binaries() { .build(); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(0), ); assert_that(cargo_home(), has_installed_exe("foo")); @@ -388,10 +361,7 @@ fn multiple_crates_auto_examples() { .build(); assert_that( - cargo_process("install") - .arg("--path") - .arg(p.root()) - .arg("--example=foo"), + cargo_process("install --path").arg(p.root()).arg("--example=foo"), execs().with_status(0), ); assert_that(cargo_home(), has_installed_exe("foo")); @@ -418,7 +388,7 @@ fn no_binaries_or_examples() { .build(); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs() .with_status(101) .with_stderr("[ERROR] no packages found with binaries or examples"), @@ -433,10 +403,7 @@ fn no_binaries() { .build(); assert_that( - cargo_process("install") - .arg("--path") - .arg(p.root()) - .arg("foo"), + cargo_process("install --path").arg(p.root()).arg("foo"), execs().with_status(101).with_stderr( "\ [INSTALLING] foo [..] @@ -454,10 +421,7 @@ fn examples() { .build(); assert_that( - cargo_process("install") - .arg("--path") - .arg(p.root()) - .arg("--example=foo"), + cargo_process("install --path").arg(p.root()).arg("--example=foo"), execs().with_status(0), ); assert_that(cargo_home(), has_installed_exe("foo")); @@ -471,11 +435,11 @@ fn install_twice() { .build(); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(0), ); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(101).with_stderr( "\ [INSTALLING] foo v0.0.1 [..] @@ -494,7 +458,7 @@ fn install_force() { .build(); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(0), ); @@ -504,10 +468,7 @@ fn install_force() { .build(); assert_that( - cargo_process("install") - .arg("--force") - .arg("--path") - .arg(p.root()), + cargo_process("install --force --path").arg(p.root()), execs().with_status(0).with_stderr(&format!( "\ [INSTALLING] foo v0.2.0 ([..]) @@ -521,7 +482,7 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina ); assert_that( - cargo_process("install").arg("--list"), + cargo_process("install --list"), execs().with_status(0).with_stdout( "\ foo v0.2.0 ([..]): @@ -539,7 +500,7 @@ fn install_force_partial_overlap() { .build(); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(0), ); @@ -550,10 +511,7 @@ fn install_force_partial_overlap() { .build(); assert_that( - cargo_process("install") - .arg("--force") - .arg("--path") - .arg(p.root()), + cargo_process("install --force --path").arg(p.root()), execs().with_status(0).with_stderr(&format!( "\ [INSTALLING] foo v0.2.0 ([..]) @@ -568,7 +526,7 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina ); assert_that( - cargo_process("install").arg("--list"), + cargo_process("install --list"), execs().with_status(0).with_stdout( "\ foo v0.0.1 ([..]): @@ -589,7 +547,7 @@ fn install_force_bin() { .build(); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(0), ); @@ -600,12 +558,7 @@ fn install_force_bin() { .build(); assert_that( - cargo_process("install") - .arg("--force") - .arg("--bin") - .arg("foo-bin2") - .arg("--path") - .arg(p.root()), + cargo_process("install --force --bin foo-bin2 --path").arg(p.root()), execs().with_status(0).with_stderr(&format!( "\ [INSTALLING] foo v0.2.0 ([..]) @@ -619,7 +572,7 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina ); assert_that( - cargo_process("install").arg("--list"), + cargo_process("install --list"), execs().with_status(0).with_stdout( "\ foo v0.0.1 ([..]): @@ -638,7 +591,7 @@ fn compile_failure() { .build(); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(101).with_stderr_contains( "\ [ERROR] failed to compile `foo v0.0.1 ([..])`, intermediate artifacts can be \ @@ -662,10 +615,7 @@ fn git_repo() { // use `--locked` to test that we don't even try to write a lockfile assert_that( - cargo_process("install") - .arg("--locked") - .arg("--git") - .arg(p.url().to_string()), + cargo_process("install --locked --git").arg(p.url().to_string()), execs().with_status(0).with_stderr(&format!( "\ [UPDATING] git repository `[..]` @@ -689,20 +639,17 @@ fn list() { pkg("bar", "0.2.2"); assert_that( - cargo_process("install").arg("--list"), + cargo_process("install --list"), execs().with_status(0).with_stdout(""), ); assert_that( - cargo_process("install") - .arg("bar") - .arg("--vers") - .arg("=0.2.1"), + cargo_process("install bar --vers =0.2.1"), execs().with_status(0), ); - assert_that(cargo_process("install").arg("foo"), execs().with_status(0)); + assert_that(cargo_process("install foo"), execs().with_status(0)); assert_that( - cargo_process("install").arg("--list"), + cargo_process("install --list"), execs().with_status(0).with_stdout( "\ bar v0.2.1: @@ -717,9 +664,9 @@ foo v0.0.1: #[test] fn list_error() { pkg("foo", "0.0.1"); - assert_that(cargo_process("install").arg("foo"), execs().with_status(0)); + assert_that(cargo_process("install foo"), execs().with_status(0)); assert_that( - cargo_process("install").arg("--list"), + cargo_process("install --list"), execs().with_status(0).with_stdout( "\ foo v0.0.1: @@ -736,7 +683,7 @@ foo v0.0.1: worldfile.write_all(b"\x00").unwrap(); drop(worldfile); assert_that( - cargo_process("install").arg("--list").arg("--verbose"), + cargo_process("install --list --verbose"), execs().with_status(101).with_stderr( "\ [ERROR] failed to parse crate metadata at `[..]` @@ -754,7 +701,7 @@ Caused by: #[test] fn uninstall_pkg_does_not_exist() { assert_that( - cargo_process("uninstall").arg("foo"), + cargo_process("uninstall foo"), execs() .with_status(101) .with_stderr("[ERROR] package id specification `foo` matched no packages"), @@ -765,9 +712,9 @@ fn uninstall_pkg_does_not_exist() { fn uninstall_bin_does_not_exist() { pkg("foo", "0.0.1"); - assert_that(cargo_process("install").arg("foo"), execs().with_status(0)); + assert_that(cargo_process("install foo"), execs().with_status(0)); assert_that( - cargo_process("uninstall").arg("foo").arg("--bin=bar"), + cargo_process("uninstall foo --bin=bar"), execs() .with_status(101) .with_stderr("[ERROR] binary `bar[..]` not installed as part of `foo v0.0.1`"), @@ -782,14 +729,14 @@ fn uninstall_piecemeal() { .build(); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(0), ); assert_that(cargo_home(), has_installed_exe("foo")); assert_that(cargo_home(), has_installed_exe("bar")); assert_that( - cargo_process("uninstall").arg("foo").arg("--bin=bar"), + cargo_process("uninstall foo --bin=bar"), execs().with_status(0).with_stderr("[REMOVING] [..]bar[..]"), ); @@ -797,13 +744,13 @@ fn uninstall_piecemeal() { assert_that(cargo_home(), is_not(has_installed_exe("bar"))); assert_that( - cargo_process("uninstall").arg("foo").arg("--bin=foo"), + cargo_process("uninstall foo --bin=foo"), execs().with_status(0).with_stderr("[REMOVING] [..]foo[..]"), ); assert_that(cargo_home(), is_not(has_installed_exe("foo"))); assert_that( - cargo_process("uninstall").arg("foo"), + cargo_process("uninstall foo"), execs() .with_status(101) .with_stderr("[ERROR] package id specification `foo` matched no packages"), @@ -816,7 +763,7 @@ fn subcommand_works_out_of_the_box() { .file("src/main.rs", r#"fn main() { println!("bar"); }"#) .publish(); assert_that( - cargo_process("install").arg("cargo-foo"), + cargo_process("install cargo-foo"), execs().with_status(0), ); assert_that( @@ -870,9 +817,7 @@ fn installs_from_cwd_with_2018_warnings() { .build(); assert_that( - cargo_process("install") - .cwd(p.root()) - .masquerade_as_nightly_cargo(), + cargo_process("install").cwd(p.root()).masquerade_as_nightly_cargo(), execs().with_status(101).with_stderr_contains( "error: To build the current package use `cargo build`, \ to install the current package run `cargo install --path .`, \ @@ -890,9 +835,9 @@ fn do_not_rebuilds_on_local_install() { .file("src/main.rs", "fn main() {}") .build(); - assert_that(p.cargo("build").arg("--release"), execs().with_status(0)); + assert_that(p.cargo("build --release"), execs().with_status(0)); assert_that( - cargo_process("install").arg("--path").arg(p.root()), + cargo_process("install --path").arg(p.root()), execs().with_status(0).with_stderr( "[INSTALLING] [..] [FINISHED] release [optimized] target(s) in [..] @@ -913,7 +858,7 @@ fn reports_unsuccessful_subcommand_result() { .file("src/main.rs", "fn main() { panic!(); }") .publish(); assert_that( - cargo_process("install").arg("cargo-fail"), + cargo_process("install cargo-fail"), execs().with_status(0), ); assert_that( @@ -962,9 +907,7 @@ fn git_with_lockfile() { .build(); assert_that( - cargo_process("install") - .arg("--git") - .arg(p.url().to_string()), + cargo_process("install --git").arg(p.url().to_string()), execs().with_status(0), ); } @@ -976,10 +919,7 @@ fn q_silences_warnings() { .build(); assert_that( - cargo_process("install") - .arg("-q") - .arg("--path") - .arg(p.root()), + cargo_process("install -q --path").arg(p.root()), execs().with_status(0).with_stderr(""), ); } @@ -996,7 +936,7 @@ fn readonly_dir() { fs::set_permissions(dir, perms).unwrap(); assert_that( - cargo_process("install").arg("foo").cwd(dir), + cargo_process("install foo").cwd(dir), execs().with_status(0), ); assert_that(cargo_home(), has_installed_exe("foo")); @@ -1097,10 +1037,7 @@ fn install_target_native() { pkg("foo", "0.1.0"); assert_that( - cargo_process("install") - .arg("foo") - .arg("--target") - .arg(support::rustc_host()), + cargo_process("install foo --target").arg(support::rustc_host()), execs() .with_status(0), ); @@ -1116,10 +1053,7 @@ fn install_target_foreign() { pkg("foo", "0.1.0"); assert_that( - cargo_process("install") - .arg("foo") - .arg("--target") - .arg(cross_compile::alternate()), + cargo_process("install foo --target").arg(cross_compile::alternate()), execs() .with_status(0), ); @@ -1132,10 +1066,7 @@ fn vers_precise() { pkg("foo", "0.1.2"); assert_that( - cargo_process("install") - .arg("foo") - .arg("--vers") - .arg("0.1.1"), + cargo_process("install foo --vers 0.1.1"), execs() .with_status(0) .with_stderr_contains("[DOWNLOADING] foo v0.1.1 (registry [..])"), @@ -1148,10 +1079,7 @@ fn version_too() { pkg("foo", "0.1.2"); assert_that( - cargo_process("install") - .arg("foo") - .arg("--version") - .arg("0.1.1"), + cargo_process("install foo --version 0.1.1"), execs() .with_status(0) .with_stderr_contains("[DOWNLOADING] foo v0.1.1 (registry [..])"), @@ -1164,12 +1092,7 @@ fn not_both_vers_and_version() { pkg("foo", "0.1.2"); assert_that( - cargo_process("install") - .arg("foo") - .arg("--version") - .arg("0.1.1") - .arg("--vers") - .arg("0.1.2"), + cargo_process("install foo --version 0.1.1 --vers 0.1.2"), execs().with_status(1).with_stderr_contains( "\ error: The argument '--version ' was provided more than once, \ @@ -1184,7 +1107,7 @@ fn legacy_version_requirement() { pkg("foo", "0.1.1"); assert_that( - cargo_process("install").arg("foo").arg("--vers").arg("0.1"), + cargo_process("install foo --vers 0.1"), execs().with_status(0).with_stderr_contains( "\ warning: the `--vers` provided, `0.1`, is not a valid semver version @@ -1198,13 +1121,13 @@ and will continue to do so, but this behavior will be removed eventually #[test] fn test_install_git_cannot_be_a_base_url() { - assert_that(cargo_process("install").arg("--git").arg("github.com:rust-lang-nursery/rustfmt.git"), + assert_that(cargo_process("install --git github.com:rust-lang-nursery/rustfmt.git"), execs().with_status(101).with_stderr("error: invalid url `github.com:rust-lang-nursery/rustfmt.git`: cannot-be-a-base-URLs are not supported")); } #[test] fn uninstall_multiple_and_specifying_bin() { - assert_that(cargo_process("uninstall").args(&["foo", "bar"]).arg("--bin").arg("baz"), + assert_that(cargo_process("uninstall foo bar --bin baz"), execs().with_status(101).with_stderr("error: A binary can only be associated with a single installed package, specifying multiple specs with --bin is redundant.")); } @@ -1212,10 +1135,10 @@ fn uninstall_multiple_and_specifying_bin() { fn uninstall_multiple_and_some_pkg_does_not_exist() { pkg("foo", "0.0.1"); - assert_that(cargo_process("install").arg("foo"), execs().with_status(0)); + assert_that(cargo_process("install foo"), execs().with_status(0)); assert_that( - cargo_process("uninstall").args(&["foo", "bar"]), + cargo_process("uninstall foo bar"), execs().with_status(101).with_stderr(&format!( "\ [REMOVING] {home}[..]bin[..]foo[..] @@ -1239,9 +1162,7 @@ fn custom_target_dir_for_git_source() { .build(); assert_that( - cargo_process("install") - .arg("--git") - .arg(p.url().to_string()), + cargo_process("install --git").arg(p.url().to_string()), execs().with_status(0), ); assert_that( @@ -1250,10 +1171,7 @@ fn custom_target_dir_for_git_source() { ); assert_that( - cargo_process("install") - .arg("--force") - .arg("--git") - .arg(p.url().to_string()) + cargo_process("install --force --git").arg(p.url().to_string()) .env("CARGO_TARGET_DIR", "target"), execs().with_status(0), ); @@ -1288,7 +1206,7 @@ dependencies = [ ) .publish(); - assert_that(cargo_process("install").arg("foo"), execs().with_status(0)); + assert_that(cargo_process("install foo"), execs().with_status(0)); } #[test] @@ -1316,7 +1234,7 @@ dependencies = [ ) .publish(); - assert_that(cargo_process("install").arg("foo"), execs().with_status(0)); + assert_that(cargo_process("install foo"), execs().with_status(0)); } #[test] @@ -1339,9 +1257,7 @@ fn git_repo_replace() { let repo = git2::Repository::open(&p.root()).unwrap(); let old_rev = repo.revparse_single("HEAD").unwrap().id(); assert_that( - cargo_process("install") - .arg("--git") - .arg(p.url().to_string()), + cargo_process("install --git").arg(p.url().to_string()), execs().with_status(0), ); git::commit(&repo); @@ -1356,10 +1272,7 @@ fn git_repo_replace() { .contains(&format!("{}", old_rev)) ); assert_that( - cargo_process("install") - .arg("--force") - .arg("--git") - .arg(p.url().to_string()), + cargo_process("install --force --git").arg(p.url().to_string()), execs().with_status(0), ); assert!( @@ -1391,10 +1304,10 @@ fn workspace_uses_workspace_target_dir() { .file("bar/src/main.rs", "fn main() {}") .build(); - assert_that(p.cargo("build").cwd(p.root().join("bar")).arg("--release"), + assert_that(p.cargo("build --release").cwd(p.root().join("bar")), execs().with_status(0)); assert_that( - cargo_process("install").arg("--path").arg(p.root().join("bar")), + cargo_process("install --path").arg(p.root().join("bar")), execs().with_status(0).with_stderr( "[INSTALLING] [..] [FINISHED] release [optimized] target(s) in [..] diff --git a/tests/testsuite/login.rs b/tests/testsuite/login.rs index d847861dd56..5292650edc4 100644 --- a/tests/testsuite/login.rs +++ b/tests/testsuite/login.rs @@ -78,11 +78,7 @@ fn login_with_old_credentials() { setup_old_credentials(); assert_that( - cargo_process() - .arg("login") - .arg("--host") - .arg(registry().to_string()) - .arg(TOKEN), + cargo_process("login --host").arg(registry().to_string()).arg(TOKEN), execs().with_status(0), ); @@ -105,11 +101,7 @@ fn login_with_new_credentials() { setup_new_credentials(); assert_that( - cargo_process() - .arg("login") - .arg("--host") - .arg(registry().to_string()) - .arg(TOKEN), + cargo_process("login --host").arg(registry().to_string()).arg(TOKEN), execs().with_status(0), ); @@ -129,11 +121,7 @@ fn login_with_old_and_new_credentials() { #[test] fn login_without_credentials() { assert_that( - cargo_process() - .arg("login") - .arg("--host") - .arg(registry().to_string()) - .arg(TOKEN), + cargo_process("login --host").arg(registry().to_string()).arg(TOKEN), execs().with_status(0), ); @@ -150,11 +138,7 @@ fn new_credentials_is_used_instead_old() { setup_new_credentials(); assert_that( - cargo_process() - .arg("login") - .arg("--host") - .arg(registry().to_string()) - .arg(TOKEN), + cargo_process("login --host").arg(registry().to_string()).arg(TOKEN), execs().with_status(0), ); @@ -172,13 +156,8 @@ fn registry_credentials() { let reg = "test-reg"; assert_that( - cargo_process() - .arg("login") - .masquerade_as_nightly_cargo() - .arg("--registry") - .arg(reg) - .arg(TOKEN) - .arg("-Zunstable-options"), + cargo_process("login --registry").arg(reg).arg(TOKEN).arg("-Zunstable-options") + .masquerade_as_nightly_cargo(), execs().with_status(0), ); diff --git a/tests/testsuite/new.rs b/tests/testsuite/new.rs index 26901f93c33..c91b4731c97 100644 --- a/tests/testsuite/new.rs +++ b/tests/testsuite/new.rs @@ -2,18 +2,10 @@ use std::fs::{self, File}; use std::io::prelude::*; use std::env; -use support; -use cargo::util::ProcessBuilder; -use support::process; +use support::{cargo_process, git_process}; use support::{execs, paths}; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; -fn cargo_process(s: &str) -> ProcessBuilder { - let mut p = support::cargo_process(); - p.arg(s); - p -} - fn create_empty_gitconfig() { // This helps on Windows where libgit2 is very aggressive in attempting to // find a git config file. @@ -24,12 +16,7 @@ fn create_empty_gitconfig() { #[test] fn simple_lib() { assert_that( - cargo_process("new") - .arg("--lib") - .arg("foo") - .arg("--vcs") - .arg("none") - .env("USER", "foo"), + cargo_process("new --lib foo --vcs none").env("USER", "foo"), execs() .with_status(0) .with_stderr("[CREATED] library `foo` project"), @@ -70,10 +57,7 @@ mod tests { #[test] fn simple_bin() { assert_that( - cargo_process("new") - .arg("--bin") - .arg("foo") - .env("USER", "foo"), + cargo_process("new --bin foo").env("USER", "foo"), execs() .with_status(0) .with_stderr("[CREATED] binary (application) `foo` project"), @@ -96,11 +80,7 @@ fn simple_bin() { #[test] fn both_lib_and_bin() { assert_that( - cargo_process("new") - .arg("--lib") - .arg("--bin") - .arg("foo") - .env("USER", "foo"), + cargo_process("new --lib --bin foo").env("USER", "foo"), execs() .with_status(101) .with_stderr("[ERROR] can't specify both lib and binary outputs"), @@ -110,10 +90,7 @@ fn both_lib_and_bin() { #[test] fn simple_git() { assert_that( - cargo_process("new") - .arg("--lib") - .arg("foo") - .env("USER", "foo"), + cargo_process("new --lib foo").env("USER", "foo"), execs().with_status(0), ); @@ -147,7 +124,7 @@ fn existing() { let dst = paths::root().join("foo"); fs::create_dir(&dst).unwrap(); assert_that( - cargo_process("new").arg("foo"), + cargo_process("new foo"), execs().with_status(101).with_stderr(format!( "[ERROR] destination `{}` already exists\n\n\ Use `cargo init` to initialize the directory", @@ -159,7 +136,7 @@ fn existing() { #[test] fn invalid_characters() { assert_that( - cargo_process("new").arg("foo.rs"), + cargo_process("new foo.rs"), execs().with_status(101).with_stderr( "\ [ERROR] Invalid character `.` in crate name: `foo.rs` @@ -171,7 +148,7 @@ use --name to override crate name", #[test] fn reserved_name() { assert_that( - cargo_process("new").arg("test"), + cargo_process("new test"), execs().with_status(101).with_stderr( "\ [ERROR] The name `test` cannot be used as a crate name\n\ @@ -183,7 +160,7 @@ fn reserved_name() { #[test] fn reserved_binary_name() { assert_that( - cargo_process("new").arg("--bin").arg("incremental"), + cargo_process("new --bin incremental"), execs().with_status(101).with_stderr( "\ [ERROR] The name `incremental` cannot be used as a crate name\n\ @@ -195,7 +172,7 @@ fn reserved_binary_name() { #[test] fn keyword_name() { assert_that( - cargo_process("new").arg("pub"), + cargo_process("new pub"), execs().with_status(101).with_stderr( "\ [ERROR] The name `pub` cannot be used as a crate name\n\ @@ -208,7 +185,7 @@ fn keyword_name() { fn finds_author_user() { create_empty_gitconfig(); assert_that( - cargo_process("new").arg("foo").env("USER", "foo"), + cargo_process("new foo").env("USER", "foo"), execs().with_status(0), ); @@ -225,7 +202,7 @@ fn finds_author_user() { fn finds_author_user_escaped() { create_empty_gitconfig(); assert_that( - cargo_process("new").arg("foo").env("USER", "foo \"bar\""), + cargo_process("new foo").env("USER", "foo \"bar\""), execs().with_status(0), ); @@ -242,10 +219,7 @@ fn finds_author_user_escaped() { fn finds_author_username() { create_empty_gitconfig(); assert_that( - cargo_process("new") - .arg("foo") - .env_remove("USER") - .env("USERNAME", "foo"), + cargo_process("new foo").env_remove("USER").env("USERNAME", "foo"), execs().with_status(0), ); @@ -261,8 +235,7 @@ fn finds_author_username() { #[test] fn finds_author_priority() { assert_that( - cargo_process("new") - .arg("foo") + cargo_process("new foo") .env("USER", "bar2") .env("EMAIL", "baz2") .env("CARGO_NAME", "bar") @@ -283,8 +256,7 @@ fn finds_author_priority() { fn finds_author_email() { create_empty_gitconfig(); assert_that( - cargo_process("new") - .arg("foo") + cargo_process("new foo") .env("USER", "bar") .env("EMAIL", "baz"), execs().with_status(0), @@ -301,16 +273,10 @@ fn finds_author_email() { #[test] fn finds_author_git() { - process("git") - .args(&["config", "--global", "user.name", "bar"]) - .exec() - .unwrap(); - process("git") - .args(&["config", "--global", "user.email", "baz"]) - .exec() - .unwrap(); + git_process("config --global user.name bar").exec().unwrap(); + git_process("config --global user.email baz").exec().unwrap(); assert_that( - cargo_process("new").arg("foo").env("USER", "foo"), + cargo_process("new foo").env("USER", "foo"), execs().with_status(0), ); @@ -325,25 +291,13 @@ fn finds_author_git() { #[test] fn finds_local_author_git() { - process("git").args(&["init"]).exec().unwrap(); - process("git") - .args(&["config", "--global", "user.name", "foo"]) - .exec() - .unwrap(); - process("git") - .args(&["config", "--global", "user.email", "foo@bar"]) - .exec() - .unwrap(); + git_process("init").exec().unwrap(); + git_process("config --global user.name foo").exec().unwrap(); + git_process("config --global user.email foo@bar").exec().unwrap(); // Set local git user config - process("git") - .args(&["config", "user.name", "bar"]) - .exec() - .unwrap(); - process("git") - .args(&["config", "user.email", "baz"]) - .exec() - .unwrap(); + git_process("config user.name bar").exec().unwrap(); + git_process("config user.email baz").exec().unwrap(); assert_that( cargo_process("init").env("USER", "foo"), execs().with_status(0), @@ -361,8 +315,7 @@ fn finds_local_author_git() { #[test] fn finds_git_email() { assert_that( - cargo_process("new") - .arg("foo") + cargo_process("new foo") .env("GIT_AUTHOR_NAME", "foo") .env("GIT_AUTHOR_EMAIL", "gitfoo"), execs().with_status(0), @@ -381,8 +334,7 @@ fn finds_git_email() { fn finds_git_author() { create_empty_gitconfig(); assert_that( - cargo_process("new") - .arg("foo") + cargo_process("new foo") .env_remove("USER") .env("GIT_COMMITTER_NAME", "gitfoo"), execs().with_status(0), @@ -399,14 +351,8 @@ fn finds_git_author() { #[test] fn author_prefers_cargo() { - process("git") - .args(&["config", "--global", "user.name", "foo"]) - .exec() - .unwrap(); - process("git") - .args(&["config", "--global", "user.email", "bar"]) - .exec() - .unwrap(); + git_process("config --global user.name foo").exec().unwrap(); + git_process("config --global user.email bar").exec().unwrap(); let root = paths::root(); fs::create_dir(&root.join(".cargo")).unwrap(); File::create(&root.join(".cargo/config")) @@ -422,7 +368,7 @@ fn author_prefers_cargo() { .unwrap(); assert_that( - cargo_process("new").arg("foo").env("USER", "foo"), + cargo_process("new foo").env("USER", "foo"), execs().with_status(0), ); @@ -453,11 +399,7 @@ fn git_prefers_command_line() { .unwrap(); assert_that( - cargo_process("new") - .arg("foo") - .arg("--vcs") - .arg("git") - .env("USER", "foo"), + cargo_process("new foo --vcs git").env("USER", "foo"), execs().with_status(0), ); assert!(paths::root().join("foo/.gitignore").exists()); @@ -466,7 +408,7 @@ fn git_prefers_command_line() { #[test] fn subpackage_no_git() { assert_that( - cargo_process("new").arg("foo").env("USER", "foo"), + cargo_process("new foo").env("USER", "foo"), execs().with_status(0), ); @@ -476,9 +418,7 @@ fn subpackage_no_git() { let subpackage = paths::root().join("foo").join("components"); fs::create_dir(&subpackage).unwrap(); assert_that( - cargo_process("new") - .arg("foo/components/subcomponent") - .env("USER", "foo"), + cargo_process("new foo/components/subcomponent").env("USER", "foo"), execs().with_status(0), ); @@ -495,7 +435,7 @@ fn subpackage_no_git() { #[test] fn subpackage_git_with_gitignore() { assert_that( - cargo_process("new").arg("foo").env("USER", "foo"), + cargo_process("new foo").env("USER", "foo"), execs().with_status(0), ); @@ -514,9 +454,7 @@ fn subpackage_git_with_gitignore() { let subpackage = paths::root().join("foo/components"); fs::create_dir(&subpackage).unwrap(); assert_that( - cargo_process("new") - .arg("foo/components/subcomponent") - .env("USER", "foo"), + cargo_process("new foo/components/subcomponent").env("USER", "foo"), execs().with_status(0), ); @@ -534,18 +472,14 @@ fn subpackage_git_with_gitignore() { #[test] fn subpackage_git_with_vcs_arg() { assert_that( - cargo_process("new").arg("foo").env("USER", "foo"), + cargo_process("new foo").env("USER", "foo"), execs().with_status(0), ); let subpackage = paths::root().join("foo").join("components"); fs::create_dir(&subpackage).unwrap(); assert_that( - cargo_process("new") - .arg("foo/components/subcomponent") - .arg("--vcs") - .arg("git") - .env("USER", "foo"), + cargo_process("new foo/components/subcomponent --vcs git").env("USER", "foo"), execs().with_status(0), ); @@ -562,7 +496,7 @@ fn subpackage_git_with_vcs_arg() { #[test] fn unknown_flags() { assert_that( - cargo_process("new").arg("foo").arg("--flag"), + cargo_process("new foo --flag"), execs().with_status(1).with_stderr_contains( "error: Found argument '--flag' which wasn't expected, or isn't valid in this context", ), @@ -572,10 +506,7 @@ fn unknown_flags() { #[test] fn explicit_invalid_name_not_suggested() { assert_that( - cargo_process("new") - .arg("--name") - .arg("10-invalid") - .arg("a"), + cargo_process("new --name 10-invalid a"), execs().with_status(101).with_stderr( "[ERROR] Package names starting with a digit cannot be used as a crate name", ), @@ -585,12 +516,7 @@ fn explicit_invalid_name_not_suggested() { #[test] fn explicit_project_name() { assert_that( - cargo_process("new") - .arg("--lib") - .arg("foo") - .arg("--name") - .arg("bar") - .env("USER", "foo"), + cargo_process("new --lib foo --name bar").env("USER", "foo"), execs() .with_status(0) .with_stderr("[CREATED] library `bar` project"), diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index bbf2d1ad23b..0e2c1d75ace 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -4,8 +4,8 @@ use std::io::prelude::*; use std::path::{Path, PathBuf}; use git2; -use support::{cargo_process, process, sleep_ms, ChannelChanger}; -use support::{basic_manifest, cargo_exe, execs, git, paths, project, registry, path2url}; +use support::{cargo_process, sleep_ms, ChannelChanger}; +use support::{basic_manifest, execs, git, paths, project, registry, path2url}; use support::registry::Package; use flate2::read::GzDecoder; use support::hamcrest::{assert_that, contains, existing_file}; @@ -161,13 +161,11 @@ fn package_verbose() { .file("a/Cargo.toml", &basic_manifest("a", "0.0.1")) .file("a/src/lib.rs", "") .build(); - let mut cargo = cargo_process(); - cargo.cwd(p.root()); - assert_that(cargo.clone().arg("build"), execs().with_status(0)); + assert_that(cargo_process("build").cwd(p.root()), execs().with_status(0)); println!("package main repo"); assert_that( - cargo.clone().arg("package").arg("-v").arg("--no-verify"), + cargo_process("package -v --no-verify").cwd(p.root()), execs().with_status(0).with_stderr( "\ [WARNING] manifest has no description[..] @@ -181,11 +179,7 @@ See http://doc.crates.io/manifest.html#package-metadata for more info. println!("package sub-repo"); assert_that( - cargo - .arg("package") - .arg("-v") - .arg("--no-verify") - .cwd(p.root().join("a")), + cargo_process("package -v --no-verify").cwd(p.root().join("a")), execs().with_status(0).with_stderr( "\ [WARNING] manifest has no description[..] @@ -469,11 +463,7 @@ fn package_git_submodule() { .unwrap(); assert_that( - cargo_process() - .arg("package") - .cwd(project.root()) - .arg("--no-verify") - .arg("-v"), + cargo_process("package --no-verify -v").cwd(project.root()), execs() .with_status(0) .with_stderr_contains("[ARCHIVING] bar/Makefile"), @@ -491,11 +481,9 @@ fn no_duplicates_from_modified_tracked_files() { .unwrap() .write_all(br#"fn main() { println!("A change!"); }"#) .unwrap(); - let mut cargo = cargo_process(); - cargo.cwd(p.root()); - assert_that(cargo.clone().arg("build"), execs().with_status(0)); + assert_that(cargo_process("build").cwd(p.root()), execs().with_status(0)); assert_that( - cargo.arg("package").arg("--list"), + cargo_process("package --list").cwd(p.root()), execs().with_status(0).with_stdout( "\ Cargo.toml @@ -618,12 +606,9 @@ fn repackage_on_source_change() { file.write_all(br#"fn main() { println!("foo"); }"#).unwrap(); std::mem::drop(file); - let mut pro = process(&cargo_exe()); - pro.arg("package").cwd(p.root()); - // Check that cargo rebuilds the tarball assert_that( - pro, + cargo_process("package").cwd(p.root()), execs().with_status(0).with_stderr(&format!( "\ [WARNING] [..] diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index fbb16ef2c15..d5d0b3d59eb 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -283,7 +283,7 @@ fn bad_cksum() { t!(File::create(&pkg.archive_dst())); assert_that( - p.cargo("build").arg("-v"), + p.cargo("build -v"), execs().with_status(101).with_stderr( "\ [UPDATING] registry [..] @@ -376,7 +376,7 @@ fn package_with_path_deps() { .build(); assert_that( - p.cargo("package").arg("-v"), + p.cargo("package -v"), execs().with_status(101).with_stderr_contains( "\ [ERROR] failed to verify package tarball @@ -701,7 +701,7 @@ fn update_lockfile() { println!("0.0.3 update"); assert_that( - p.cargo("update").arg("-p").arg("bar"), + p.cargo("update -p bar"), execs().with_status(0).with_stderr( "\ [UPDATING] registry `[..]` @@ -728,7 +728,7 @@ fn update_lockfile() { Package::new("bar", "0.0.4").dep("spam", "0.2.5").publish(); Package::new("spam", "0.2.5").publish(); assert_that( - p.cargo("update").arg("-p").arg("bar"), + p.cargo("update -p bar"), execs().with_status(0).with_stderr( "\ [UPDATING] registry `[..]` @@ -741,7 +741,7 @@ fn update_lockfile() { println!("new dependencies update"); Package::new("bar", "0.0.5").publish(); assert_that( - p.cargo("update").arg("-p").arg("bar"), + p.cargo("update -p bar"), execs().with_status(0).with_stderr( "\ [UPDATING] registry `[..]` @@ -821,7 +821,7 @@ fn login_with_no_cargo_dir() { let home = paths::home().join("new-home"); t!(fs::create_dir(&home)); assert_that( - cargo_process().arg("login").arg("foo").arg("-v"), + cargo_process("login foo -v"), execs().with_status(0), ); } @@ -832,15 +832,15 @@ fn login_with_differently_sized_token() { let home = paths::home().join("new-home"); t!(fs::create_dir(&home)); assert_that( - cargo_process().arg("login").arg("lmaolmaolmao").arg("-v"), + cargo_process("login lmaolmaolmao -v"), execs().with_status(0), ); assert_that( - cargo_process().arg("login").arg("lmao").arg("-v"), + cargo_process("login lmao -v"), execs().with_status(0), ); assert_that( - cargo_process().arg("login").arg("lmaolmaolmao").arg("-v"), + cargo_process("login lmaolmaolmao -v"), execs().with_status(0), ); } @@ -1144,7 +1144,7 @@ fn update_transitive_dependency() { Package::new("b", "0.1.1").publish(); assert_that( - p.cargo("update").arg("-pb"), + p.cargo("update -pb"), execs().with_status(0).with_stderr( "\ [UPDATING] registry `[..]` @@ -1206,7 +1206,7 @@ fn update_backtracking_ok() { .publish(); assert_that( - p.cargo("update").arg("-p").arg("hyper"), + p.cargo("update -p hyper"), execs().with_status(0).with_stderr( "\ [UPDATING] registry `[..]` @@ -1248,7 +1248,7 @@ fn update_multiple_packages() { Package::new("c", "0.1.1").publish(); assert_that( - p.cargo("update").arg("-pa").arg("-pb"), + p.cargo("update -pa -pb"), execs().with_status(0).with_stderr( "\ [UPDATING] registry `[..]` @@ -1259,7 +1259,7 @@ fn update_multiple_packages() { ); assert_that( - p.cargo("update").arg("-pb").arg("-pc"), + p.cargo("update -pb -pc"), execs().with_status(0).with_stderr( "\ [UPDATING] registry `[..]` @@ -1349,7 +1349,7 @@ fn update_same_prefix_oh_my_how_was_this_a_bug() { assert_that(p.cargo("generate-lockfile"), execs().with_status(0)); assert_that( - p.cargo("update").arg("-pfoobar").arg("--precise=0.2.0"), + p.cargo("update -pfoobar --precise=0.2.0"), execs().with_status(0), ); } @@ -1466,7 +1466,7 @@ fn upstream_warnings_on_extra_verbose() { .publish(); assert_that( - p.cargo("build").arg("-vv"), + p.cargo("build -vv"), execs() .with_status(0) .with_stderr_contains("[..]warning: function is never used[..]"), @@ -1492,7 +1492,7 @@ fn disallow_network() { .build(); assert_that( - p.cargo("build").arg("--frozen"), + p.cargo("build --frozen"), execs().with_status(101).with_stderr( "\ error: failed to load source for a dependency on `foo` @@ -1773,7 +1773,7 @@ fn toml_lies_but_index_is_truth() { .file("src/main.rs", "fn main() {}") .build(); - assert_that(p.cargo("build").arg("-v"), execs().with_status(0)); + assert_that(p.cargo("build -v"), execs().with_status(0)); } #[test] @@ -1798,7 +1798,7 @@ fn vv_prints_warnings() { .file("src/main.rs", "fn main() {}") .build(); - assert_that(p.cargo("build").arg("-vv"), execs().with_status(0)); + assert_that(p.cargo("build -vv"), execs().with_status(0)); } #[test] @@ -1824,7 +1824,7 @@ fn bad_and_or_malicious_packages_rejected() { .build(); assert_that( - p.cargo("build").arg("-vv"), + p.cargo("build -vv"), execs().with_status(101).with_stderr( "\ [UPDATING] [..] diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index 0a295eaccac..f2feefc7ac6 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -2,9 +2,7 @@ use std::fs::{self, File}; use std::io::prelude::*; use std::path::Path; -use cargo::util::ProcessBuilder; -use support; -use support::execs; +use support::{cargo_process, execs}; use support::git::repo; use support::paths; use support::registry::{api_path, registry as registry_url, registry_path}; @@ -95,12 +93,6 @@ registry = '{reg}' .unwrap(); } -fn cargo_process(s: &str) -> ProcessBuilder { - let mut b = support::cargo_process(); - b.arg(s); - b -} - #[test] fn not_update() { setup(); @@ -116,7 +108,7 @@ fn not_update() { regsrc.update().unwrap(); assert_that( - cargo_process("search").arg("postgres"), + cargo_process("search postgres"), execs() .with_status(0) .with_stdout_contains( @@ -132,7 +124,7 @@ fn replace_default() { set_cargo_config(); assert_that( - cargo_process("search").arg("postgres"), + cargo_process("search postgres"), execs() .with_status(0) .with_stdout_contains( @@ -147,10 +139,7 @@ fn simple() { setup(); assert_that( - cargo_process("search") - .arg("postgres") - .arg("--index") - .arg(registry_url().to_string()), + cargo_process("search postgres --index").arg(registry_url().to_string()), execs().with_status(0).with_stdout_contains( "hoare = \"0.1.1\" # Design by contract style assertions for Rust", ), @@ -164,10 +153,7 @@ fn simple_with_host() { setup(); assert_that( - cargo_process("search") - .arg("postgres") - .arg("--host") - .arg(registry_url().to_string()), + cargo_process("search postgres --host").arg(registry_url().to_string()), execs() .with_status(0) .with_stderr(&format!( @@ -198,12 +184,7 @@ fn simple_with_index_and_host() { setup(); assert_that( - cargo_process("search") - .arg("postgres") - .arg("--index") - .arg(registry_url().to_string()) - .arg("--host") - .arg(registry_url().to_string()), + cargo_process("search postgres --index").arg(registry_url().to_string()).arg("--host").arg(registry_url().to_string()), execs() .with_status(0) .with_stderr(&format!( @@ -232,11 +213,7 @@ fn multiple_query_params() { setup(); assert_that( - cargo_process("search") - .arg("postgres") - .arg("sql") - .arg("--index") - .arg(registry_url().to_string()), + cargo_process("search postgres sql --index").arg(registry_url().to_string()), execs().with_status(0).with_stdout_contains( "hoare = \"0.1.1\" # Design by contract style assertions for Rust", ), @@ -245,15 +222,15 @@ fn multiple_query_params() { #[test] fn help() { - assert_that(cargo_process("search").arg("-h"), execs().with_status(0)); - assert_that(cargo_process("help").arg("search"), execs().with_status(0)); + assert_that(cargo_process("search -h"), execs().with_status(0)); + assert_that(cargo_process("help search"), execs().with_status(0)); // Ensure that help output goes to stdout, not stderr. assert_that( - cargo_process("search").arg("--help"), + cargo_process("search --help"), execs().with_stderr(""), ); assert_that( - cargo_process("search").arg("--help"), + cargo_process("search --help"), execs().with_stdout_contains("[..] --frozen [..]"), ); } diff --git a/tests/testsuite/support/mod.rs b/tests/testsuite/support/mod.rs index b0b75215c5d..3dd5e328e56 100644 --- a/tests/testsuite/support/mod.rs +++ b/tests/testsuite/support/mod.rs @@ -361,12 +361,7 @@ impl Project { /// assert_that(p.cargo("build --bin foo"), execs().with_status(0)); pub fn cargo(&self, cmd: &str) -> ProcessBuilder { let mut p = self.process(&cargo_exe()); - for arg in cmd.split_whitespace() { - if arg.contains('"') || arg.contains('\'') { - panic!("shell-style argument parsing is not supported") - } - p.arg(arg); - } + split_and_add_args(&mut p, cmd); return p; } @@ -1376,8 +1371,25 @@ impl ChannelChanger for cargo::util::ProcessBuilder { } } -pub fn cargo_process() -> cargo::util::ProcessBuilder { - process(&cargo_exe()) +fn split_and_add_args(p: &mut ProcessBuilder, s: &str) { + for arg in s.split_whitespace() { + if arg.contains('"') || arg.contains('\'') { + panic!("shell-style argument parsing is not supported") + } + p.arg(arg); + } +} + +pub fn cargo_process(s: &str) -> ProcessBuilder { + let mut p = process(&cargo_exe()); + split_and_add_args(&mut p, s); + p +} + +pub fn git_process(s: &str) -> ProcessBuilder { + let mut p = process("git"); + split_and_add_args(&mut p, s); + p } pub fn sleep_ms(ms: u64) { diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 18f2677a2a6..0c850a350d5 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -3207,10 +3207,9 @@ fn cargo_test_env() { .file("src/lib.rs", &src) .build(); - let mut pr = p.cargo("test"); let cargo = cargo_exe().canonicalize().unwrap(); assert_that( - pr.args(&["--lib", "--", "--nocapture"]), + p.cargo("test --lib -- --nocapture"), execs().with_status(0).with_stdout_contains(format!( "\ {} diff --git a/tests/testsuite/tool_paths.rs b/tests/testsuite/tool_paths.rs index 57bc5c83c4b..c27fb1d9de1 100644 --- a/tests/testsuite/tool_paths.rs +++ b/tests/testsuite/tool_paths.rs @@ -174,7 +174,7 @@ fn custom_runner() { .build(); assert_that( - p.cargo("run").args(&["--", "--param"]), + p.cargo("run -- --param"), execs().with_stderr_contains(&format!( "\ [COMPILING] foo v0.0.1 ({url}) @@ -186,8 +186,7 @@ fn custom_runner() { ); assert_that( - p.cargo("test") - .args(&["--test", "test", "--verbose", "--", "--param"]), + p.cargo("test --test test --verbose -- --param"), execs().with_stderr_contains(&format!( "\ [COMPILING] foo v0.0.1 ({url}) @@ -200,8 +199,7 @@ fn custom_runner() { ); assert_that( - p.cargo("bench") - .args(&["--bench", "bench", "--verbose", "--", "--param"]), + p.cargo("bench --bench bench --verbose -- --param"), execs().with_stderr_contains(&format!( "\ [COMPILING] foo v0.0.1 ({url}) diff --git a/tests/testsuite/workspaces.rs b/tests/testsuite/workspaces.rs index 0439c581197..95c47f46461 100644 --- a/tests/testsuite/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -774,7 +774,7 @@ fn explicit_package_argument_works_with_virtual_manifest() { .file("bar/src/main.rs", "fn main() {}"); let p = p.build(); assert_that( - p.cargo("build").cwd(p.root()).args(&["--package", "bar"]), + p.cargo("build --package bar").cwd(p.root()), execs().with_status(0), ); assert_that(&p.root().join("Cargo.lock"), existing_file()); @@ -1276,7 +1276,7 @@ fn workspace_with_transitive_dev_deps() { .file("baz/src/lib.rs", r#"pub fn do_stuff() {}"#); let p = p.build(); - assert_that(p.cargo("test").args(&["-p", "bar"]), execs().with_status(0)); + assert_that(p.cargo("test -p bar"), execs().with_status(0)); } #[test]