diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 0441f0a660c..7c588c93826 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -83,24 +83,17 @@ rust source code is created in a temporary directory, `cargo` binary is invoked via `std::process::Command` and then stdout and stderr are verified against the expected output. To simplify testing, several macros of the form `[MACRO]` are used in the expected output. For -example, `[..]` matches any string and `[/]` matches `/` on Unixes and -`\` on windows. +example, `[..]` matches any string. -To see stdout and stderr streams of the subordinate process, add `.stream()` -call to `execs()`: +To see stdout and stderr streams of the subordinate process, add `.stream()` +call to the built-up `Execs`: ```rust // Before -assert_that( - p.cargo("run"), - execs() -); +p.cargo("run").run(); // After -assert_that( - p.cargo("run"), - execs().stream() -); +p.cargo("run").stream().run(); ``` Alternatively to build and run a custom version of cargo simply run `cargo build` diff --git a/tests/testsuite/bench.rs b/tests/testsuite/bench.rs index 913860d8c3a..e7e902425fe 100644 --- a/tests/testsuite/bench.rs +++ b/tests/testsuite/bench.rs @@ -1,10 +1,7 @@ -use std::str; - -use cargo::util::process; use support::hamcrest::{assert_that, existing_file}; use support::is_nightly; use support::paths::CargoPathExt; -use support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, execs, project}; +use support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project}; #[test] fn cargo_bench_simple() { @@ -38,7 +35,7 @@ fn cargo_bench_simple() { p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("hello\n")); + p.process(&p.bin("foo")).with_stdout("hello\n").run(); p.cargo("bench") .with_stderr(&format!( @@ -269,23 +266,11 @@ fn many_similar_names() { "#, ).build(); - let output = p.cargo("bench").exec_with_output().unwrap(); - let output = str::from_utf8(&output.stdout).unwrap(); - assert!( - output.contains("test bin_bench"), - "bin_bench missing\n{}", - output - ); - assert!( - output.contains("test lib_bench"), - "lib_bench missing\n{}", - output - ); - assert!( - output.contains("test bench_bench"), - "bench_bench missing\n{}", - output - ); + p.cargo("bench") + .with_stdout_contains("test bin_bench ... bench: 0 ns/iter (+/- 0)") + .with_stdout_contains("test lib_bench ... bench: 0 ns/iter (+/- 0)") + .with_stdout_contains("test bench_bench ... bench: 0 ns/iter (+/- 0)") + .run(); } #[test] @@ -319,7 +304,7 @@ fn cargo_bench_failing_test() { p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("hello\n")); + p.process(&p.bin("foo")).with_stdout("hello\n").run(); // Force libtest into serial execution so that the test header will be printed. p.cargo("bench -- --test-threads=1") diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index c6b1680fefd..9e59239cd6c 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -3,7 +3,6 @@ use std::fs::{self, File}; use std::io::prelude::*; use cargo::util::paths::dylib_path_envvar; -use cargo::util::process; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::paths::{root, CargoPathExt}; use support::registry::Package; @@ -11,7 +10,7 @@ use support::ProjectBuilder; use support::{ basic_bin_manifest, basic_lib_manifest, basic_manifest, is_nightly, rustc_host, sleep_ms, }; -use support::{execs, main_file, project, Execs}; +use support::{main_file, project, Execs}; #[test] fn cargo_compile_simple() { @@ -23,7 +22,7 @@ fn cargo_compile_simple() { p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("i am foo\n")); + p.process(&p.bin("foo")).with_stdout("i am foo\n").run(); } #[test] @@ -530,7 +529,7 @@ fn cargo_compile_with_warnings_in_a_dep_package() { assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("test passed\n")); + p.process(&p.bin("foo")).with_stdout("test passed\n").run(); } #[test] @@ -583,13 +582,13 @@ fn cargo_compile_with_nested_deps_inferred() { "#, ).build(); - p.cargo("build").exec_with_output().unwrap(); + p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); assert_that(&p.bin("libbar.rlib"), is_not(existing_file())); assert_that(&p.bin("libbaz.rlib"), is_not(existing_file())); - assert_that(process(&p.bin("foo")), execs().with_stdout("test passed\n")); + p.process(&p.bin("foo")).with_stdout("test passed\n").run(); } #[test] @@ -642,13 +641,13 @@ fn cargo_compile_with_nested_deps_correct_bin() { "#, ).build(); - p.cargo("build").exec_with_output().unwrap(); + p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); assert_that(&p.bin("libbar.rlib"), is_not(existing_file())); assert_that(&p.bin("libbaz.rlib"), is_not(existing_file())); - assert_that(process(&p.bin("foo")), execs().with_stdout("test passed\n")); + p.process(&p.bin("foo")).with_stdout("test passed\n").run(); } #[test] @@ -702,13 +701,13 @@ fn cargo_compile_with_nested_deps_shorthand() { "#, ).build(); - p.cargo("build").exec_with_output().unwrap(); + p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); assert_that(&p.bin("libbar.rlib"), is_not(existing_file())); assert_that(&p.bin("libbaz.rlib"), is_not(existing_file())); - assert_that(process(&p.bin("foo")), execs().with_stdout("test passed\n")); + p.process(&p.bin("foo")).with_stdout("test passed\n").run(); } #[test] @@ -774,7 +773,7 @@ fn cargo_compile_with_nested_deps_longhand() { assert_that(&p.bin("libbar.rlib"), is_not(existing_file())); assert_that(&p.bin("libbaz.rlib"), is_not(existing_file())); - assert_that(process(&p.bin("foo")), execs().with_stdout("test passed\n")); + p.process(&p.bin("foo")).with_stdout("test passed\n").run(); } // Check that Cargo gives a sensible error if a dependency can't be found @@ -1156,7 +1155,7 @@ fn compile_offline_while_transitive_dep_not_cached() { .build(); // simulate download bar, but fail to download baz - let _out = p.cargo("build").exec_with_output(); + p.cargo("build").with_status(101).run(); drop(File::create(baz_path).ok().unwrap().write_all(&content)); @@ -1378,10 +1377,9 @@ fn crate_env_vars() { p.cargo("build -v").run(); println!("bin"); - assert_that( - process(&p.bin("foo")), - execs().with_stdout(&format!("0-5-1 @ alpha.1 in {}\n", p.root().display())), - ); + p.process(&p.bin("foo")) + .with_stdout(&format!("0-5-1 @ alpha.1 in {}\n", p.root().display())) + .run(); println!("test"); p.cargo("test -v").run(); @@ -1425,10 +1423,9 @@ fn crate_authors_env_vars() { p.cargo("build -v").run(); println!("bin"); - assert_that( - process(&p.bin("foo")), - execs().with_stdout("wycats@example.com:neikos@example.com"), - ); + p.process(&p.bin("foo")) + .with_stdout("wycats@example.com:neikos@example.com") + .run(); println!("test"); p.cargo("test -v").run(); @@ -1584,7 +1581,7 @@ fn ignore_broken_symlinks() { p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("i am foo\n")); + p.process(&p.bin("foo")).with_stdout("i am foo\n").run(); } #[test] @@ -1787,14 +1784,12 @@ fn explicit_examples() { ).build(); p.cargo("test -v").run(); - assert_that( - process(&p.bin("examples/hello")), - execs().with_stdout("Hello, World!\n"), - ); - assert_that( - process(&p.bin("examples/goodbye")), - execs().with_stdout("Goodbye, World!\n"), - ); + p.process(&p.bin("examples/hello")) + .with_stdout("Hello, World!\n") + .run(); + p.process(&p.bin("examples/goodbye")) + .with_stdout("Goodbye, World!\n") + .run(); } #[test] @@ -1948,14 +1943,12 @@ fn implicit_examples() { ).build(); p.cargo("test").run(); - assert_that( - process(&p.bin("examples/hello")), - execs().with_stdout("Hello, World!\n"), - ); - assert_that( - process(&p.bin("examples/goodbye")), - execs().with_stdout("Goodbye, World!\n"), - ); + p.process(&p.bin("examples/hello")) + .with_stdout("Hello, World!\n") + .run(); + p.process(&p.bin("examples/goodbye")) + .with_stdout("Goodbye, World!\n") + .run(); } #[test] @@ -1976,7 +1969,7 @@ fn standard_build_no_ndebug() { ).build(); p.cargo("build").run(); - assert_that(process(&p.bin("foo")), execs().with_stdout("slow\n")); + p.process(&p.bin("foo")).with_stdout("slow\n").run(); } #[test] @@ -1997,10 +1990,7 @@ fn release_build_ndebug() { ).build(); p.cargo("build --release").run(); - assert_that( - process(&p.release_bin("foo")), - execs().with_stdout("fast\n"), - ); + p.process(&p.release_bin("foo")).with_stdout("fast\n").run(); } #[test] @@ -2008,7 +1998,7 @@ fn inferred_main_bin() { let p = project().file("src/main.rs", "fn main() {}").build(); p.cargo("build").run(); - assert_that(process(&p.bin("foo")), execs()); + p.process(&p.bin("foo")).run(); } #[test] @@ -2043,7 +2033,7 @@ fn bad_cargo_toml_in_target_dir() { .build(); p.cargo("build").run(); - assert_that(process(&p.bin("foo")), execs()); + p.process(&p.bin("foo")).run(); } #[test] @@ -2417,10 +2407,10 @@ fn cargo_platform_specific_dependency_wrong_platform() { "invalid rust file, should not be compiled", ).build(); - p.cargo("build").exec_with_output().unwrap(); + p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs()); + p.process(&p.bin("foo")).run(); let loc = p.root().join("Cargo.lock"); let mut lockfile = String::new(); @@ -2534,13 +2524,13 @@ fn example_bin_same_name() { .file("examples/foo.rs", "fn main() {}") .build(); - p.cargo("test --no-run -v").exec_with_output().unwrap(); + p.cargo("test --no-run -v").run(); assert_that(&p.bin("foo"), is_not(existing_file())); // We expect a file of the form bin/foo-{metadata_hash} assert_that(&p.bin("examples/foo"), existing_file()); - p.cargo("test --no-run -v").exec_with_output().unwrap(); + p.cargo("test --no-run -v").run(); assert_that(&p.bin("foo"), is_not(existing_file())); // We expect a file of the form bin/foo-{metadata_hash} @@ -2958,7 +2948,7 @@ fn build_multiple_packages() { p.cargo("build -p d1 -p d2 -p foo").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("i am foo\n")); + p.process(&p.bin("foo")).with_stdout("i am foo\n").run(); let d1_path = &p .build_dir() @@ -2970,10 +2960,10 @@ fn build_multiple_packages() { .join(format!("d2{}", env::consts::EXE_SUFFIX)); assert_that(d1_path, existing_file()); - assert_that(process(d1_path), execs().with_stdout("d1")); + p.process(d1_path).with_stdout("d1").run(); assert_that(d2_path, existing_file()); - assert_that(process(d2_path), execs().with_stdout("d2")); + p.process(d2_path).with_stdout("d2").run(); } #[test] @@ -3696,8 +3686,8 @@ fn run_proper_alias_binary_from_src() { .build(); p.cargo("build --all").run(); - assert_that(process(&p.bin("foo")), execs().with_stdout("foo\n")); - assert_that(process(&p.bin("bar")), execs().with_stdout("bar\n")); + p.process(&p.bin("foo")).with_stdout("foo\n").run(); + p.process(&p.bin("bar")).with_stdout("bar\n").run(); } #[test] @@ -3719,8 +3709,8 @@ fn run_proper_alias_binary_main_rs() { .build(); p.cargo("build --all").run(); - assert_that(process(&p.bin("foo")), execs().with_stdout("main\n")); - assert_that(process(&p.bin("bar")), execs().with_stdout("main\n")); + p.process(&p.bin("foo")).with_stdout("main\n").run(); + p.process(&p.bin("bar")).with_stdout("main\n").run(); } #[test] diff --git a/tests/testsuite/cargo_command.rs b/tests/testsuite/cargo_command.rs index c58c9807ad3..ee35dbbb886 100644 --- a/tests/testsuite/cargo_command.rs +++ b/tests/testsuite/cargo_command.rs @@ -64,21 +64,11 @@ fn path() -> Vec { #[test] fn list_commands_with_descriptions() { let p = project().build(); - let output = p.cargo("--list").exec_with_output().unwrap(); - let output = str::from_utf8(&output.stdout).unwrap(); - assert!( - output.contains( - "\n build Compile a local package and all of its dependencies" - ), - "missing build, with description: {}", - output - ); - // assert read-manifest prints the right one-line description followed by another command, indented. - assert!( - output.contains("\n read-manifest Print a JSON representation of a Cargo.toml manifest.\n "), - "missing build, with description: {}", - output - ); + p.cargo("--list") + .with_stdout_contains(" build Compile a local package and all of its dependencies") + // assert read-manifest prints the right one-line description followed by another command, indented. + .with_stdout_contains(" read-manifest Print a JSON representation of a Cargo.toml manifest.") + .run(); } #[test] @@ -94,9 +84,7 @@ fn list_command_looks_at_path() { let mut path = path(); path.push(proj.root().join("path-test")); let path = env::join_paths(path.iter()).unwrap(); - let mut p = cargo_process("-v --list"); - let output = p.env("PATH", &path); - let output = output.exec_with_output().unwrap(); + let output = cargo_process("-v --list").env("PATH", &path).exec_with_output().unwrap(); let output = str::from_utf8(&output.stdout).unwrap(); assert!( output.contains("\n 1 "), @@ -122,9 +110,7 @@ fn list_command_resolves_symlinks() { let mut path = path(); path.push(proj.root().join("path-test")); let path = env::join_paths(path.iter()).unwrap(); - let mut p = cargo_process("-v --list"); - let output = p.env("PATH", &path); - let output = output.exec_with_output().unwrap(); + let output = cargo_process("-v --list").env("PATH", &path).exec_with_output().unwrap(); let output = str::from_utf8(&output.stdout).unwrap(); assert!( output.contains("\n 2 "), diff --git a/tests/testsuite/concurrent.rs b/tests/testsuite/concurrent.rs index 4dbb1a96db0..abdf5d23b6f 100644 --- a/tests/testsuite/concurrent.rs +++ b/tests/testsuite/concurrent.rs @@ -43,8 +43,8 @@ fn multiple_installs() { let b = b.wait_with_output().unwrap(); let a = a.join().unwrap(); - assert_that(a, execs()); - assert_that(b, execs()); + execs().run_output(&a); + execs().run_output(&b); assert_that(cargo_home(), has_installed_exe("foo")); assert_that(cargo_home(), has_installed_exe("bar")); @@ -72,8 +72,8 @@ fn concurrent_installs() { assert!(!str::from_utf8(&a.stderr).unwrap().contains(LOCKED_BUILD)); assert!(!str::from_utf8(&b.stderr).unwrap().contains(LOCKED_BUILD)); - assert_that(a, execs()); - assert_that(b, execs()); + execs().run_output(&a); + execs().run_output(&b); assert_that(cargo_home(), has_installed_exe("foo")); assert_that(cargo_home(), has_installed_exe("bar")); @@ -106,16 +106,14 @@ fn one_install_should_be_bad() { } else { (b, a) }; - assert_that( - bad, - execs().with_status(101).with_stderr_contains( + execs() + .with_status(101) + .with_stderr_contains( "[ERROR] binary `foo[..]` already exists in destination as part of `[..]`", - ), - ); - assert_that( - good, - execs().with_stderr_contains("warning: be sure to add `[..]` to your PATH [..]"), - ); + ).run_output(&bad); + execs() + .with_stderr_contains("warning: be sure to add `[..]` to your PATH [..]") + .run_output(&good); assert_that(cargo_home(), has_installed_exe("foo")); } @@ -170,8 +168,8 @@ fn multiple_registry_fetches() { let b = b.wait_with_output().unwrap(); let a = a.join().unwrap(); - assert_that(a, execs()); - assert_that(b, execs()); + execs().run_output(&a); + execs().run_output(&b); let suffix = env::consts::EXE_SUFFIX; assert_that( @@ -258,8 +256,8 @@ fn git_same_repo_different_tags() { let b = b.wait_with_output().unwrap(); let a = a.join().unwrap(); - assert_that(a, execs()); - assert_that(b, execs()); + execs().run_output(&a); + execs().run_output(&b); } #[test] @@ -337,8 +335,8 @@ fn git_same_branch_different_revs() { let b = b.wait_with_output().unwrap(); let a = a.join().unwrap(); - assert_that(a, execs()); - assert_that(b, execs()); + execs().run_output(&a); + execs().run_output(&b); } #[test] @@ -360,8 +358,8 @@ fn same_project() { let b = b.wait_with_output().unwrap(); let a = a.join().unwrap(); - assert_that(a, execs()); - assert_that(b, execs()); + execs().run_output(&a); + execs().run_output(&b); } // Make sure that if Cargo dies while holding a lock that it's released and the @@ -425,7 +423,7 @@ fn killing_cargo_releases_the_lock() { // We killed `a`, so it shouldn't succeed, but `b` should have succeeded. assert!(!a.status.success()); - assert_that(b, execs()); + execs().run_output(&b); } #[test] @@ -446,24 +444,20 @@ fn debug_release_ok() { let b = b.wait_with_output().unwrap(); let a = a.join().unwrap(); - assert_that( - a, - execs().with_stderr( + execs() + .with_stderr( "\ [COMPILING] foo v0.0.1 [..] [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", - ), - ); - assert_that( - b, - execs().with_stderr( + ).run_output(&a); + execs() + .with_stderr( "\ [COMPILING] foo v0.0.1 [..] [FINISHED] release [optimized] target(s) in [..] ", - ), - ); + ).run_output(&b); } #[test] @@ -519,6 +513,6 @@ fn no_deadlock_with_git_dependencies() { for _ in 0..n_concurrent_builds { let result = rx.recv_timeout(Duration::from_secs(30)).expect("Deadlock!"); - assert_that(result, execs()) + execs().run_output(&result); } } diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index e6e491f84f0..350b3c725d7 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -1,6 +1,5 @@ -use cargo::util::process; use support::hamcrest::{assert_that, existing_file}; -use support::{basic_bin_manifest, basic_manifest, cross_compile, execs, project}; +use support::{basic_bin_manifest, basic_manifest, cross_compile, project}; use support::{is_nightly, rustc_host}; #[test] @@ -46,7 +45,7 @@ fn simple_cross() { p.cargo("build -v --target").arg(&target).run(); assert_that(&p.target_bin(&target, "foo"), existing_file()); - assert_that(process(&p.target_bin(&target, "foo")), execs()); + p.process(&p.target_bin(&target, "foo")).run(); } #[test] @@ -101,7 +100,7 @@ fn simple_cross_config() { p.cargo("build -v").run(); assert_that(&p.target_bin(&target, "foo"), existing_file()); - assert_that(process(&p.target_bin(&target, "foo")), execs()); + p.process(&p.target_bin(&target, "foo")).run(); } #[test] @@ -134,7 +133,7 @@ fn simple_deps() { p.cargo("build --target").arg(&target).run(); assert_that(&p.target_bin(&target, "foo"), existing_file()); - assert_that(process(&p.target_bin(&target, "foo")), execs()); + p.process(&p.target_bin(&target, "foo")).run(); } #[test] @@ -222,7 +221,7 @@ fn plugin_deps() { foo.cargo("build --target").arg(&target).run(); assert_that(&foo.target_bin(&target, "foo"), existing_file()); - assert_that(process(&foo.target_bin(&target, "foo")), execs()); + foo.process(&foo.target_bin(&target, "foo")).run(); } #[test] @@ -319,7 +318,7 @@ fn plugin_to_the_max() { foo.cargo("build -v --target").arg(&target).run(); assert_that(&foo.target_bin(&target, "foo"), existing_file()); - assert_that(process(&foo.target_bin(&target, "foo")), execs()); + foo.process(&foo.target_bin(&target, "foo")).run(); } #[test] diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index f0725e89cc4..55c398c7f5d 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -3,7 +3,6 @@ use std::io::Read; use std::str; use support; -use cargo::util::ProcessError; use glob::glob; use support::hamcrest::{assert_that, existing_dir, existing_file, is_not}; use support::paths::CargoPathExt; @@ -652,23 +651,11 @@ fn output_not_captured() { ", ).build(); - let error = p.cargo("doc").exec_with_output().err().unwrap(); - if let Ok(perr) = error.downcast::() { - let output = perr.output.unwrap(); - let stderr = str::from_utf8(&output.stderr).unwrap(); - - assert!(stderr.contains("☃"), "no snowman\n{}", stderr); - assert!( - stderr.contains("unknown start of token"), - "no message{}", - stderr - ); - } else { - assert!( - false, - "an error kind other than ProcessErrorKind was encountered" - ); - } + p.cargo("doc") + .with_status(101) + .with_stderr_contains("1 | ☃") + .with_stderr_contains(r"error: unknown start of token: \u{2603}") + .run(); } #[test] diff --git a/tests/testsuite/features.rs b/tests/testsuite/features.rs index 9962d1d02ba..a0657258820 100644 --- a/tests/testsuite/features.rs +++ b/tests/testsuite/features.rs @@ -1,10 +1,9 @@ use std::fs::File; use std::io::prelude::*; -use support::hamcrest::assert_that; use support::paths::CargoPathExt; use support::registry::Package; -use support::{basic_manifest, execs, project}; +use support::{basic_manifest, project}; #[test] fn invalid1() { @@ -423,7 +422,7 @@ fn no_feature_doesnt_build() { ", dir = p.url() )).run(); - assert_that(p.process(&p.bin("foo")), execs().with_stdout("")); + p.process(&p.bin("foo")).with_stdout("").run(); p.cargo("build --features bar") .with_stderr(format!( @@ -434,7 +433,7 @@ fn no_feature_doesnt_build() { ", dir = p.url() )).run(); - assert_that(p.process(&p.bin("foo")), execs().with_stdout("bar\n")); + p.process(&p.bin("foo")).with_stdout("bar\n").run(); } #[test] @@ -478,7 +477,7 @@ fn default_feature_pulled_in() { ", dir = p.url() )).run(); - assert_that(p.process(&p.bin("foo")), execs().with_stdout("bar\n")); + p.process(&p.bin("foo")).with_stdout("bar\n").run(); p.cargo("build --no-default-features") .with_stderr(format!( @@ -488,7 +487,7 @@ fn default_feature_pulled_in() { ", dir = p.url() )).run(); - assert_that(p.process(&p.bin("foo")), execs().with_stdout("")); + p.process(&p.bin("foo")).with_stdout("").run(); } #[test] diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 37b18ff2eb9..570833a174e 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -5,7 +5,7 @@ use support::hamcrest::{assert_that, existing_file}; use support::paths::CargoPathExt; use support::registry::Package; use support::sleep_ms; -use support::{basic_manifest, execs, path2url, project}; +use support::{basic_manifest, path2url, project}; #[test] fn modifying_and_moving() { @@ -435,7 +435,7 @@ fn changing_bin_features_caches_targets() { [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", ).run(); - assert_that(foo_proc("off1"), execs().with_stdout("feature off")); + foo_proc("off1").with_stdout("feature off").run(); p.cargo("build --features foo") .with_stderr( @@ -444,7 +444,7 @@ fn changing_bin_features_caches_targets() { [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", ).run(); - assert_that(foo_proc("on1"), execs().with_stdout("feature on")); + foo_proc("on1").with_stdout("feature on").run(); /* Targets should be cached from the first build */ @@ -454,7 +454,7 @@ fn changing_bin_features_caches_targets() { [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", ).run(); - assert_that(foo_proc("off2"), execs().with_stdout("feature off")); + foo_proc("off2").with_stdout("feature off").run(); p.cargo("build --features foo") .with_stderr( @@ -462,7 +462,7 @@ fn changing_bin_features_caches_targets() { [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] ", ).run(); - assert_that(foo_proc("on2"), execs().with_stdout("feature on")); + foo_proc("on2").with_stdout("feature on").run(); } #[test] diff --git a/tests/testsuite/git.rs b/tests/testsuite/git.rs index 5e9bd44412b..4c8c8765eed 100644 --- a/tests/testsuite/git.rs +++ b/tests/testsuite/git.rs @@ -7,11 +7,10 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::thread; -use cargo::util::process; use support::hamcrest::{assert_that, existing_file}; use support::paths::{self, CargoPathExt}; use support::sleep_ms; -use support::{basic_lib_manifest, basic_manifest, execs, git, main_file, path2url, project}; +use support::{basic_lib_manifest, basic_manifest, git, main_file, path2url, project}; #[test] fn cargo_compile_simple_git_dep() { @@ -68,10 +67,10 @@ fn cargo_compile_simple_git_dep() { assert_that(&project.bin("foo"), existing_file()); - assert_that( - process(&project.bin("foo")), - execs().with_stdout("hello world\n"), - ); + project + .process(&project.bin("foo")) + .with_stdout("hello world\n") + .run(); } #[test] @@ -205,10 +204,9 @@ fn cargo_compile_offline_with_cached_git_dep() { assert_that(&p.bin("foo"), existing_file()); - assert_that( - process(&p.bin("foo")), - execs().with_stdout("hello from cached git repo rev2\n"), - ); + p.process(&p.bin("foo")) + .with_stdout("hello from cached git repo rev2\n") + .run(); File::create(&p.root().join("Cargo.toml")) .unwrap() @@ -228,14 +226,10 @@ fn cargo_compile_offline_with_cached_git_dep() { ).as_bytes(), ).unwrap(); - let _out = p - .cargo("build -Zoffline") - .masquerade_as_nightly_cargo() - .exec_with_output(); - assert_that( - process(&p.bin("foo")), - execs().with_stdout("hello from cached git repo rev1\n"), - ); + p.cargo("build -Zoffline").masquerade_as_nightly_cargo().run(); + p.process(&p.bin("foo")) + .with_stdout("hello from cached git repo rev1\n") + .run(); } #[test] @@ -301,10 +295,10 @@ fn cargo_compile_git_dep_branch() { assert_that(&project.bin("foo"), existing_file()); - assert_that( - process(&project.bin("foo")), - execs().with_stdout("hello world\n"), - ); + project + .process(&project.bin("foo")) + .with_stdout("hello world\n") + .run(); } #[test] @@ -374,10 +368,10 @@ fn cargo_compile_git_dep_tag() { assert_that(&project.bin("foo"), existing_file()); - assert_that( - process(&project.bin("foo")), - execs().with_stdout("hello world\n"), - ); + project + .process(&project.bin("foo")) + .with_stdout("hello world\n") + .run(); project.cargo("build").run(); } @@ -451,11 +445,11 @@ fn cargo_compile_with_nested_paths() { &main_file(r#""{}", dep1::hello()"#, &["dep1"]), ).build(); - p.cargo("build").exec_with_output().unwrap(); + p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("hello world\n")); + p.process(&p.bin("foo")).with_stdout("hello world\n").run(); } #[test] @@ -500,11 +494,11 @@ fn cargo_compile_with_malformed_nested_paths() { &main_file(r#""{}", dep1::hello()"#, &["dep1"]), ).build(); - p.cargo("build").exec_with_output().unwrap(); + p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("hello world\n")); + p.process(&p.bin("foo")).with_stdout("hello world\n").run(); } #[test] @@ -566,14 +560,13 @@ fn cargo_compile_with_meta_package() { ), ).build(); - p.cargo("build").exec_with_output().unwrap(); + p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that( - process(&p.bin("foo")), - execs().with_stdout("this is dep1 this is dep2\n"), - ); + p.process(&p.bin("foo")) + .with_stdout("this is dep1 this is dep2\n") + .run(); } #[test] @@ -700,7 +693,7 @@ fn two_revs_same_deps() { foo.cargo("build -v").run(); assert_that(&foo.bin("foo"), existing_file()); - assert_that(foo.process(&foo.bin("foo")), execs()); + foo.process(&foo.bin("foo")).run(); } #[test] @@ -1173,7 +1166,7 @@ fn stale_cached_version() { ).build(); foo.cargo("build").run(); - assert_that(foo.process(&foo.bin("foo")), execs()); + foo.process(&foo.bin("foo")).run(); // Update the repo, and simulate someone else updating the lockfile and then // us pulling it down. @@ -1223,7 +1216,7 @@ fn stale_cached_version() { bar = bar.url(), foo = foo.url() )).run(); - assert_that(foo.process(&foo.bin("foo")), execs()); + foo.process(&foo.bin("foo")).run(); } #[test] @@ -1631,7 +1624,7 @@ fn git_dep_build_cmd() { p.cargo("build").run(); - assert_that(process(&p.bin("foo")), execs().with_stdout("0\n")); + p.process(&p.bin("foo")).with_stdout("0\n").run(); // Touching bar.rs.in should cause the `build` command to run again. fs::File::create(&p.root().join("bar/src/bar.rs.in")) @@ -1641,7 +1634,7 @@ fn git_dep_build_cmd() { p.cargo("build").run(); - assert_that(process(&p.bin("foo")), execs().with_stdout("1\n")); + p.process(&p.bin("foo")).with_stdout("1\n").run(); } #[test] diff --git a/tests/testsuite/jobserver.rs b/tests/testsuite/jobserver.rs index 29156007cf6..d2d03330722 100644 --- a/tests/testsuite/jobserver.rs +++ b/tests/testsuite/jobserver.rs @@ -2,8 +2,7 @@ use std::net::TcpListener; use std::process::Command; use std::thread; -use support::hamcrest::assert_that; -use support::{cargo_exe, execs, project}; +use support::{cargo_exe, project}; #[test] fn jobserver_exists() { @@ -150,13 +149,11 @@ all: drop((a2, a3)); }); - assert_that( - p.process(make) - .env("CARGO", cargo_exe()) - .env("ADDR", addr.to_string()) - .arg("-j2"), - execs(), - ); + p.process(make) + .env("CARGO", cargo_exe()) + .env("ADDR", addr.to_string()) + .arg("-j2") + .run(); child.join().unwrap(); } @@ -181,15 +178,15 @@ all: ", ).build(); - assert_that( - p.process(make).env("CARGO", cargo_exe()).arg("-j2"), - execs().with_stderr( + p.process(make) + .env("CARGO", cargo_exe()) + .arg("-j2") + .with_stderr( "\ warning: a `-j` argument was passed to Cargo but Cargo is also configured \ with an external jobserver in its environment, ignoring the `-j` parameter [COMPILING] [..] [FINISHED] [..] ", - ), - ); + ).run(); } diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/out_dir.rs index 7dd610b4e5d..2700e528d2c 100644 --- a/tests/testsuite/out_dir.rs +++ b/tests/testsuite/out_dir.rs @@ -2,10 +2,8 @@ use std::env; use std::fs::{self, File}; use std::path::Path; -use support::hamcrest::assert_that; - -use support::{basic_manifest, execs, project}; -use support::{process, sleep_ms}; +use support::sleep_ms; +use support::{basic_manifest, project}; #[test] fn binary_with_debug() { @@ -186,13 +184,11 @@ fn replaces_artifacts() { p.cargo("build -Z unstable-options --out-dir out") .masquerade_as_nightly_cargo() .run(); - assert_that( - process( - &p.root() - .join(&format!("out/foo{}", env::consts::EXE_SUFFIX)), - ), - execs().with_stdout("foo"), - ); + p.process( + &p.root() + .join(&format!("out/foo{}", env::consts::EXE_SUFFIX)), + ).with_stdout("foo") + .run(); sleep_ms(1000); p.change_file("src/main.rs", r#"fn main() { println!("bar") }"#); @@ -200,13 +196,11 @@ fn replaces_artifacts() { p.cargo("build -Z unstable-options --out-dir out") .masquerade_as_nightly_cargo() .run(); - assert_that( - process( - &p.root() - .join(&format!("out/foo{}", env::consts::EXE_SUFFIX)), - ), - execs().with_stdout("bar"), - ); + p.process( + &p.root() + .join(&format!("out/foo{}", env::consts::EXE_SUFFIX)), + ).with_stdout("bar") + .run(); } fn check_dir_contents( diff --git a/tests/testsuite/path.rs b/tests/testsuite/path.rs index 51dacaf1269..a24e35dec92 100644 --- a/tests/testsuite/path.rs +++ b/tests/testsuite/path.rs @@ -1,12 +1,11 @@ use std::fs::{self, File}; use std::io::prelude::*; -use cargo::util::process; use support::hamcrest::{assert_that, existing_file, is_not}; use support::paths::{self, CargoPathExt}; use support::registry::Package; use support::sleep_ms; -use support::{basic_lib_manifest, basic_manifest, execs, main_file, project}; +use support::{basic_lib_manifest, basic_manifest, main_file, project}; #[test] #[cfg(not(windows))] // I have no idea why this is failing spuriously on @@ -79,7 +78,7 @@ fn cargo_compile_with_nested_deps_shorthand() { assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("test passed\n")); + p.process(&p.bin("foo")).with_stdout("test passed\n").run(); println!("cleaning"); p.cargo("clean -v").with_stdout("").run(); @@ -241,7 +240,7 @@ fn cargo_compile_with_transitive_dev_deps() { assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("zoidberg\n")); + p.process(&p.bin("foo")).with_stdout("zoidberg\n").run(); } #[test] @@ -698,7 +697,7 @@ fn path_dep_build_cmd() { assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("0\n")); + p.process(&p.bin("foo")).with_stdout("0\n").run(); // Touching bar.rs.in should cause the `build` command to run again. { @@ -718,7 +717,7 @@ fn path_dep_build_cmd() { p.url() )).run(); - assert_that(process(&p.bin("foo")), execs().with_stdout("1\n")); + p.process(&p.bin("foo")).with_stdout("1\n").run(); } #[test] diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index bca79508345..6866c3c6efd 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -775,7 +775,7 @@ fn run_from_executable_folder() { .build(); let cwd = p.root().join("target").join("debug"); - p.cargo("build").exec_with_output().unwrap(); + p.cargo("build").run(); p.cargo("run") .cwd(cwd) diff --git a/tests/testsuite/support/mod.rs b/tests/testsuite/support/mod.rs index 2da3ef36a88..7eb7eb1fc76 100644 --- a/tests/testsuite/support/mod.rs +++ b/tests/testsuite/support/mod.rs @@ -374,10 +374,10 @@ impl Project { /// p.process(&p.bin("foo")), /// execs().with_stdout("bar\n"), /// ); - pub fn process>(&self, program: T) -> ProcessBuilder { + pub fn process>(&self, program: T) -> Execs { let mut p = ::support::process(program); p.cwd(self.root()); - p + execs().with_process_builder(p) } /// Create a `ProcessBuilder` to run cargo. @@ -385,9 +385,11 @@ impl Project { /// Example: /// p.cargo("build --bin foo").run(); pub fn cargo(&self, cmd: &str) -> Execs { - let mut p = self.process(&cargo_exe()); - split_and_add_args(&mut p, cmd); - execs().with_process_builder(p) + let mut execs = self.process(&cargo_exe()); + if let Some(ref mut p) = execs.process_builder { + split_and_add_args(p, cmd); + } + execs } /// Returns the contents of `Cargo.lock`. @@ -514,8 +516,6 @@ pub fn cargo_exe() -> PathBuf { cargo_dir().join(format!("cargo{}", env::consts::EXE_SUFFIX)) } -/// Returns an absolute path in the filesystem that `path` points to. The -/// returned path does not contain any symlinks in its hierarchy. /* * * ===== Matchers ===== @@ -708,13 +708,15 @@ impl Execs { self } - pub fn exec_with_output(&self) -> CargoResult { + pub fn exec_with_output(&mut self) -> CargoResult { + self.ran = true; // TODO avoid unwrap let p = (&self.process_builder).clone().unwrap(); p.exec_with_output() } - pub fn build_command(&self) -> Command { + pub fn build_command(&mut self) -> Command { + self.ran = true; // TODO avoid unwrap let p = (&self.process_builder).clone().unwrap(); p.build_command() @@ -730,12 +732,18 @@ impl Execs { pub fn run(&mut self) { self.ran = true; let p = (&self.process_builder).clone().unwrap(); - // ham::assert_that(p, self) if let Err(e) = self.match_process(&p) { panic!("\nExpected: {:?}\n but: {}", self, e) } } + pub fn run_output(&mut self, output: &Output) { + self.ran = true; + if let Err(e) = self.match_output(output) { + panic!("\nExpected: {:?}\n but: {}", self, e) + } + } + fn match_process(&self, process: &ProcessBuilder) -> ham::MatchResult { println!("running {}", process); let res = if self.stream_output { @@ -1119,8 +1127,7 @@ impl Execs { impl Drop for Execs { fn drop(&mut self) { if !self.ran { - // TODO: Re-enable when everything goes through Execs#run - // panic!("forgot to run this command"); + panic!("forgot to run this command"); } } } @@ -1260,42 +1267,6 @@ impl fmt::Debug for Execs { } } -impl ham::Matcher for Execs { - fn matches(&self, process: ProcessBuilder) -> ham::MatchResult { - self.match_process(&process) - } -} - -impl<'t> ham::Matcher for &'t mut Execs { - fn matches(&self, process: ProcessBuilder) -> ham::MatchResult { - self.match_process(&process) - } -} - -impl<'a> ham::Matcher<&'a mut ProcessBuilder> for Execs { - fn matches(&self, process: &'a mut ProcessBuilder) -> ham::MatchResult { - self.match_process(process) - } -} - -impl<'a, 't> ham::Matcher<&'a mut ProcessBuilder> for &'t mut Execs { - fn matches(&self, process: &'a mut ProcessBuilder) -> ham::MatchResult { - self.match_process(process) - } -} - -impl ham::Matcher for Execs { - fn matches(&self, output: Output) -> ham::MatchResult { - self.match_output(&output) - } -} - -impl<'t> ham::Matcher for &'t mut Execs { - fn matches(&self, output: Output) -> ham::MatchResult { - self.match_output(&output) - } -} - pub fn execs() -> Execs { Execs { ran: false, diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 9b1c7db6756..908167fbe56 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -1,13 +1,11 @@ use std::fs::File; use std::io::prelude::*; -use std::str; use cargo; -use cargo::util::process; use support::hamcrest::{assert_that, existing_file, is_not}; use support::paths::CargoPathExt; use support::registry::Package; -use support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, cargo_exe, execs, project}; +use support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, cargo_exe, project}; use support::{is_nightly, rustc_host, sleep_ms}; #[test] @@ -34,7 +32,7 @@ fn cargo_test_simple() { p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("hello\n")); + p.process(&p.bin("foo")).with_stdout("hello\n").run(); p.cargo("test") .with_stderr(format!( @@ -137,7 +135,7 @@ fn cargo_test_overflow_checks() { p.cargo("build --release").run(); assert_that(&p.release_bin("foo"), existing_file()); - assert_that(process(&p.release_bin("foo")), execs().with_stdout("")); + p.process(&p.release_bin("foo")).with_stdout("").run(); } #[test] @@ -188,23 +186,11 @@ fn many_similar_names() { "#, ).build(); - let output = p.cargo("test -v").exec_with_output().unwrap(); - let output = str::from_utf8(&output.stdout).unwrap(); - assert!( - output.contains("test bin_test"), - "bin_test missing\n{}", - output - ); - assert!( - output.contains("test lib_test"), - "lib_test missing\n{}", - output - ); - assert!( - output.contains("test test_test"), - "test_test missing\n{}", - output - ); + p.cargo("test -v") + .with_stdout_contains("test bin_test ... ok") + .with_stdout_contains("test lib_test ... ok") + .with_stdout_contains("test test_test ... ok") + .run(); } #[test] @@ -231,7 +217,7 @@ fn cargo_test_failing_test_in_bin() { p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("hello\n")); + p.process(&p.bin("foo")).with_stdout("hello\n").run(); p.cargo("test") .with_stderr(format!( @@ -276,7 +262,7 @@ fn cargo_test_failing_test_in_test() { p.cargo("build").run(); assert_that(&p.bin("foo"), existing_file()); - assert_that(process(&p.bin("foo")), execs().with_stdout("hello\n")); + p.process(&p.bin("foo")).with_stdout("hello\n").run(); p.cargo("test") .with_stderr(format!( @@ -1004,18 +990,10 @@ fn bin_there_for_integration() { "#, ).build(); - let output = p.cargo("test -v").exec_with_output().unwrap(); - let output = str::from_utf8(&output.stdout).unwrap(); - assert!( - output.contains("main_test ... ok"), - "no main_test\n{}", - output - ); - assert!( - output.contains("test_test ... ok"), - "no test_test\n{}", - output - ); + p.cargo("test -v") + .with_stdout_contains("test main_test ... ok") + .with_stdout_contains("test test_test ... ok") + .run(); } #[test] @@ -1722,10 +1700,9 @@ fn example_bin_same_name() { assert_that(&p.bin("foo"), is_not(existing_file())); assert_that(&p.bin("examples/foo"), existing_file()); - assert_that( - p.process(&p.bin("examples/foo")), - execs().with_stdout("example\n"), - ); + p.process(&p.bin("examples/foo")) + .with_stdout("example\n") + .run(); p.cargo("run") .with_stderr(