]> git.proxmox.com Git - cargo.git/commitdiff
Assert that we don't build test project twice.
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 15 Feb 2017 14:16:41 +0000 (17:16 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 15 Feb 2017 20:29:57 +0000 (23:29 +0300)
That may work on linux and fail on windows, so it's better to proactively verify it.

18 files changed:
tests/build-script.rs
tests/build.rs
tests/cargotest/support/mod.rs
tests/check.rs
tests/clean.rs
tests/cross-compile.rs
tests/doc.rs
tests/features.rs
tests/metadata.rs
tests/package.rs
tests/path.rs
tests/proc-macro.rs
tests/profiles.rs
tests/publish.rs
tests/registry.rs
tests/run.rs
tests/test.rs
tests/version.rs

index 3d7056ba0b7d2bd50f0d55e22a414171a4dba909..c2d887f23af2f0f7b4a5133c3df1d250fe6f5eb7 100644 (file)
@@ -926,7 +926,9 @@ fn code_generation() {
                 ").unwrap();
             }
         "#);
-    assert_that(p.cargo_process("run"),
+    p.build();
+
+    assert_that(p.cargo("run"),
                 execs().with_status(0)
                        .with_stderr("\
 [COMPILING] foo v0.5.0 (file://[..])
@@ -936,7 +938,7 @@ fn code_generation() {
 Hello, World!
 "));
 
-    assert_that(p.cargo_process("test"),
+    assert_that(p.cargo("test"),
                 execs().with_status(0));
 }
 
index 5d012b862fcca685c2ced1e293f30ce8e7a7421e..721ec3478b75cf00972b4f870207d755e1b8daa1 100644 (file)
@@ -40,15 +40,16 @@ fn cargo_compile_incremental() {
     let p = project("foo")
         .file("Cargo.toml", &basic_bin_manifest("foo"))
         .file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
+    p.build();
 
     assert_that(
-        p.cargo_process("build").arg("-v").env("CARGO_INCREMENTAL", "1"),
+        p.cargo("build").arg("-v").env("CARGO_INCREMENTAL", "1"),
         execs().with_stderr_contains(
             "[RUNNING] `rustc [..] -Zincremental=[..][/]target[/]debug[/]incremental`\n")
             .with_status(0));
 
     assert_that(
-        p.cargo_process("test").arg("-v").env("CARGO_INCREMENTAL", "1"),
+        p.cargo("test").arg("-v").env("CARGO_INCREMENTAL", "1"),
         execs().with_stderr_contains(
             "[RUNNING] `rustc [..] -Zincremental=[..][/]target[/]debug[/]incremental`\n")
                .with_status(0));
@@ -700,22 +701,23 @@ fn cargo_compile_with_filename() {
         .file("examples/a.rs", r#"
             fn main() { println!("example"); }
         "#);
+    p.build();
 
-    assert_that(p.cargo_process("build").arg("--bin").arg("bin.rs"),
+    assert_that(p.cargo("build").arg("--bin").arg("bin.rs"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no bin target named `bin.rs`"));
 
-    assert_that(p.cargo_process("build").arg("--bin").arg("a.rs"),
+    assert_that(p.cargo("build").arg("--bin").arg("a.rs"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no bin target named `a.rs`
 
 Did you mean `a`?"));
 
-    assert_that(p.cargo_process("build").arg("--example").arg("example.rs"),
+    assert_that(p.cargo("build").arg("--example").arg("example.rs"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no example target named `example.rs`"));
 
-    assert_that(p.cargo_process("build").arg("--example").arg("a.rs"),
+    assert_that(p.cargo("build").arg("--example").arg("a.rs"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no example target named `a.rs`
 
@@ -814,9 +816,10 @@ fn cargo_default_env_metadata_env_var() {
             crate_type = ["dylib"]
         "#)
         .file("bar/src/lib.rs", "// hello");
+    p.build();
 
     // No metadata on libbar since it's a dylib path dependency
-    assert_that(p.cargo_process("build").arg("-v"),
+    assert_that(p.cargo("build").arg("-v"),
                 execs().with_status(0).with_stderr(&format!("\
 [COMPILING] bar v0.0.1 ({url}/bar)
 [RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
@@ -840,10 +843,10 @@ prefix = env::consts::DLL_PREFIX,
 suffix = env::consts::DLL_SUFFIX,
 )));
 
-    assert_that(p.cargo_process("clean"), execs().with_status(0));
+    assert_that(p.cargo("clean"), execs().with_status(0));
 
     // If you set the env-var, then we expect metadata on libbar
-    assert_that(p.cargo_process("build").arg("-v").env("__CARGO_DEFAULT_LIB_METADATA", "1"),
+    assert_that(p.cargo("build").arg("-v").env("__CARGO_DEFAULT_LIB_METADATA", "1"),
                 execs().with_status(0).with_stderr(&format!("\
 [COMPILING] bar v0.0.1 ({url}/bar)
 [RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
@@ -1447,15 +1450,16 @@ fn deletion_causes_failure() {
             authors = []
         "#)
         .file("bar/src/lib.rs", "");
+    p.build();
 
-    assert_that(p.cargo_process("build"), execs().with_status(0));
-    let p = p.file("Cargo.toml", r#"
-            [package]
-            name = "foo"
-            version = "0.0.1"
-            authors = []
-        "#);
-    assert_that(p.cargo_process("build"), execs().with_status(101));
+    assert_that(p.cargo("build"), execs().with_status(0));
+    p.change_file("Cargo.toml", r#"
+        [package]
+        name = "foo"
+        version = "0.0.1"
+        authors = []
+    "#);
+    assert_that(p.cargo("build"), execs().with_status(101));
 }
 
 #[test]
@@ -2356,7 +2360,6 @@ fn build_multiple_packages() {
                 doctest = false
         "#)
         .file("d2/src/main.rs", "fn main() { println!(\"d2\"); }");
-    p.build();
 
     assert_that(p.cargo_process("build").arg("-p").arg("d1").arg("-p").arg("d2")
                                         .arg("-p").arg("foo"),
@@ -2408,12 +2411,12 @@ fn invalid_spec() {
         .file("d1/src/main.rs", "fn main() { println!(\"d1\"); }");
     p.build();
 
-    assert_that(p.cargo_process("build").arg("-p").arg("notAValidDep"),
+    assert_that(p.cargo("build").arg("-p").arg("notAValidDep"),
                 execs().with_status(101).with_stderr("\
 [ERROR] package id specification `notAValidDep` matched no packages
 "));
 
-    assert_that(p.cargo_process("build").arg("-p").arg("d1").arg("-p").arg("notAValidDep"),
+    assert_that(p.cargo("build").arg("-p").arg("d1").arg("-p").arg("notAValidDep"),
                 execs().with_status(101).with_stderr("\
 [ERROR] package id specification `notAValidDep` matched no packages
 "));
@@ -2456,22 +2459,23 @@ fn panic_abort_compiles_with_panic_abort() {
 
 #[test]
 fn explicit_color_config_is_propagated_to_rustc() {
-    let mut p = project("foo");
-    p = p
-    .file("Cargo.toml", r#"
-            [package]
-
-            name = "test"
-            version = "0.0.0"
-            authors = []
-        "#)
-    .file("src/lib.rs", "");
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+                [package]
 
-    assert_that(p.cargo_process("build").arg("-v").arg("--color").arg("always"),
+                name = "test"
+                version = "0.0.0"
+                authors = []
+            "#)
+        .file("src/lib.rs", "");
+    p.build();
+    assert_that(p.cargo("build").arg("-v").arg("--color").arg("always"),
                 execs().with_status(0).with_stderr_contains(
                     "[..]rustc [..] src[/]lib.rs --color always[..]"));
 
-    assert_that(p.cargo_process("build").arg("-v").arg("--color").arg("never"),
+    assert_that(p.cargo("clean"), execs().with_status(0));
+
+    assert_that(p.cargo("build").arg("-v").arg("--color").arg("never"),
                 execs().with_status(0).with_stderr("\
 [COMPILING] test v0.0.0 ([..])
 [RUNNING] `rustc [..] --color never [..]`
@@ -2576,7 +2580,6 @@ fn wrong_message_format_option() {
     let p = project("foo")
         .file("Cargo.toml", &basic_bin_manifest("foo"))
         .file("src/main.rs", "fn main() {}");
-    p.build();
 
     assert_that(p.cargo_process("build").arg("--message-format").arg("XML"),
                 execs().with_status(1)
@@ -2659,7 +2662,6 @@ fn cargo_build_empty_target() {
     let p = project("foo")
         .file("Cargo.toml", &basic_bin_manifest("foo"))
         .file("src/main.rs", "fn main() {}");
-    p.build();
 
     assert_that(p.cargo_process("build").arg("--target").arg(""),
                 execs().with_status(101)
@@ -2690,7 +2692,6 @@ fn build_all_workspace() {
         .file("bar/src/lib.rs", r#"
             pub fn bar() {}
         "#);
-    p.build();
 
     assert_that(p.cargo_process("build")
                  .arg("--all"),
@@ -2723,7 +2724,6 @@ fn build_all_virtual_manifest() {
         .file("bar/src/lib.rs", r#"
             pub fn bar() {}
         "#);
-    p.build();
 
     // The order in which foo and bar are built is not guaranteed
     assert_that(p.cargo_process("build")
@@ -2754,7 +2754,6 @@ fn build_all_member_dependency_same_name() {
         .file("a/src/lib.rs", r#"
             pub fn a() {}
         "#);
-    p.build();
 
     Package::new("a", "0.1.0").publish();
 
index 054d35cf73e433ed4fabca59ead4957f90e82095..ecc3e017de68bea6db1daeef338d96271954c4ae 100644 (file)
@@ -1,3 +1,4 @@
+use std::cell::Cell;
 use std::env;
 use std::error::Error;
 use std::ffi::OsStr;
@@ -95,7 +96,8 @@ pub struct ProjectBuilder {
     name: String,
     root: PathBuf,
     files: Vec<FileBuilder>,
-    symlinks: Vec<SymlinkBuilder>
+    symlinks: Vec<SymlinkBuilder>,
+    is_build: Cell<bool>,
 }
 
 impl ProjectBuilder {
@@ -104,7 +106,8 @@ impl ProjectBuilder {
             name: name.to_string(),
             root: root,
             files: vec![],
-            symlinks: vec![]
+            symlinks: vec![],
+            is_build: Cell::new(false),
         }
     }
 
@@ -159,6 +162,9 @@ impl ProjectBuilder {
     }
 
     pub fn cargo(&self, cmd: &str) -> ProcessBuilder {
+        assert!(self.is_build.get(),
+                "call `.build()` before calling `.cargo()`, \
+                 or use `.cargo_process()`");
         let mut p = self.process(&cargo_dir().join("cargo"));
         p.arg(cmd);
         return p;
@@ -175,6 +181,11 @@ impl ProjectBuilder {
         self
     }
 
+    pub fn change_file(&self, path: &str, body: &str) {
+        assert!(self.is_build.get());
+        FileBuilder::new(self.root.join(path), body).mk()
+    }
+
     pub fn symlink<T: AsRef<Path>>(mut self, dst: T,
                                    src: T) -> ProjectBuilder {
         self.symlinks.push(SymlinkBuilder::new(self.root.join(dst),
@@ -184,6 +195,9 @@ impl ProjectBuilder {
 
     // TODO: return something different than a ProjectBuilder
     pub fn build(&self) -> &ProjectBuilder {
+        assert!(!self.is_build.get(),
+                "can `.build()` project only once");
+        self.is_build.set(true);
         // First, clean the directory if it already exists
         self.rm_root();
 
index b01d88e952d95daa848e7577b56caedfff635c81..4685bb6d6364904fafac6a8906a54e199f7f0f75 100644 (file)
@@ -163,6 +163,8 @@ fn check_build() {
                 ::bar::baz();
             }
         "#);
+    foo.build();
+
     let bar = project("bar")
         .file("Cargo.toml", r#"
             [package]
@@ -175,9 +177,9 @@ fn check_build() {
         "#);
     bar.build();
 
-    assert_that(foo.cargo_process("check"),
+    assert_that(foo.cargo("check"),
                 execs().with_status(0));
-    assert_that(foo.cargo_process("build"),
+    assert_that(foo.cargo("build"),
                 execs().with_status(0));
 }
 
@@ -203,6 +205,8 @@ fn build_check() {
                 ::bar::baz();
             }
         "#);
+    foo.build();
+
     let bar = project("bar")
         .file("Cargo.toml", r#"
             [package]
@@ -215,9 +219,9 @@ fn build_check() {
         "#);
     bar.build();
 
-    assert_that(foo.cargo_process("build"),
+    assert_that(foo.cargo("build"),
                 execs().with_status(0));
-    assert_that(foo.cargo_process("check"),
+    assert_that(foo.cargo("check"),
                 execs().with_status(0));
 }
 
@@ -240,7 +244,6 @@ fn issue_3418() {
         "#)
         .file("src/lib.rs", "")
         .file("src/main.rs", "fn main() {}");
-    foo.build();
 
     assert_that(foo.cargo_process("check").arg("-v"),
                 execs().with_status(0)
index bd7dec002c2b04913d81e5551b5d6a9f5081196c..76e28ecf8db2ed0c00a1bee3e87662c9f63e7c9f 100644 (file)
@@ -74,7 +74,6 @@ fn clean_multiple_packages() {
                 name = "d2"
         "#)
         .file("d2/src/main.rs", "fn main() { println!(\"d2\"); }");
-    p.build();
 
     assert_that(p.cargo_process("build").arg("-p").arg("d1").arg("-p").arg("d2")
                                         .arg("-p").arg("foo"),
@@ -120,7 +119,7 @@ fn clean_release() {
         .file("a/src/lib.rs", "");
     p.build();
 
-    assert_that(p.cargo_process("build").arg("--release"),
+    assert_that(p.cargo("build").arg("--release"),
                 execs().with_status(0));
 
     assert_that(p.cargo("clean").arg("-p").arg("foo"),
@@ -164,7 +163,7 @@ fn build_script() {
         .file("a/src/lib.rs", "");
     p.build();
 
-    assert_that(p.cargo_process("build").env("FIRST", "1"),
+    assert_that(p.cargo("build").env("FIRST", "1"),
                 execs().with_status(0));
     assert_that(p.cargo("clean").arg("-p").arg("foo"),
                 execs().with_status(0));
@@ -203,7 +202,7 @@ fn clean_git() {
         .file("src/main.rs", "fn main() {}");
     p.build();
 
-    assert_that(p.cargo_process("build"),
+    assert_that(p.cargo("build"),
                 execs().with_status(0));
     assert_that(p.cargo("clean").arg("-p").arg("dep"),
                 execs().with_status(0).with_stdout(""));
@@ -228,7 +227,7 @@ fn registry() {
 
     Package::new("bar", "0.1.0").publish();
 
-    assert_that(p.cargo_process("build"),
+    assert_that(p.cargo("build"),
                 execs().with_status(0));
     assert_that(p.cargo("clean").arg("-p").arg("bar"),
                 execs().with_status(0).with_stdout(""));
index 6ab9ed2ad181cbdbb1d50719f32ed1ceac5f657c..5569a850f8a9b5fc16ac74f1d481917fe43c9b16 100644 (file)
@@ -582,6 +582,7 @@ fn no_cross_doctests() {
             //! assert!(true);
             //! ```
         "#);
+    p.build();
 
     let host_output = format!("\
 [COMPILING] foo v0.0.0 ({foo})
@@ -591,13 +592,13 @@ fn no_cross_doctests() {
 ", foo = p.url());
 
     println!("a");
-    assert_that(p.cargo_process("test"),
+    assert_that(p.cargo("test"),
                 execs().with_status(0)
                        .with_stderr(&host_output));
 
     println!("b");
     let target = host();
-    assert_that(p.cargo_process("test").arg("--target").arg(&target),
+    assert_that(p.cargo("test").arg("--target").arg(&target),
                 execs().with_status(0)
                        .with_stderr(&format!("\
 [COMPILING] foo v0.0.0 ({foo})
@@ -608,7 +609,7 @@ fn no_cross_doctests() {
 
     println!("c");
     let target = alternate();
-    assert_that(p.cargo_process("test").arg("--target").arg(&target),
+    assert_that(p.cargo("test").arg("--target").arg(&target),
                 execs().with_status(0)
                        .with_stderr(&format!("\
 [COMPILING] foo v0.0.0 ({foo})
@@ -1046,8 +1047,9 @@ fn platform_specific_variables_reflected_in_build_scripts() {
             fn main() { println!("cargo:val=1") }
         "#)
         .file("d2/src/lib.rs", "");
+    p.build();
 
-    assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0));
-    assert_that(p.cargo_process("build").arg("-v").arg("--target").arg(&target),
+    assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
+    assert_that(p.cargo("build").arg("-v").arg("--target").arg(&target),
                 execs().with_status(0));
 }
index f58d57db0bfad23965e17b7aa635064f05850125..e28ede20936eb8b4f4feb4c3ae8bfd36b8f4336f 100644 (file)
@@ -561,13 +561,15 @@ fn rerun_when_dir_removed() {
             /// dox
             pub fn foo() {}
         "#);
-    assert_that(p.cargo_process("doc"),
+    p.build();
+
+    assert_that(p.cargo("doc"),
                 execs().with_status(0));
     assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
 
     fs::remove_dir_all(p.root().join("target/doc/foo")).unwrap();
 
-    assert_that(p.cargo_process("doc"),
+    assert_that(p.cargo("doc"),
                 execs().with_status(0));
     assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
 }
@@ -643,7 +645,6 @@ fn doc_all_workspace() {
         .file("bar/src/lib.rs", r#"
             pub fn bar() {}
         "#);
-    p.build();
 
     // The order in which bar is compiled or documented is not deterministic
     assert_that(p.cargo_process("doc")
@@ -677,7 +678,6 @@ fn doc_all_virtual_manifest() {
         .file("bar/src/lib.rs", r#"
             pub fn bar() {}
         "#);
-    p.build();
 
     // The order in which foo and bar are documented is not guaranteed
     assert_that(p.cargo_process("doc")
@@ -705,7 +705,6 @@ fn doc_all_member_dependency_same_name() {
         .file("a/src/lib.rs", r#"
             pub fn a() {}
         "#);
-    p.build();
 
     Package::new("a", "0.1.0").publish();
 
index d024802ead8704210e762e2a33c5af08c12a67fa..0c53b921837ce6b936c3f904762cca970b346801 100644 (file)
@@ -106,20 +106,21 @@ fn invalid4() {
             authors = []
         "#)
         .file("bar/src/lib.rs", "");
+    p.build();
 
-    assert_that(p.cargo_process("build"),
+    assert_that(p.cargo("build"),
                 execs().with_status(101).with_stderr("\
 [ERROR] Package `bar v0.0.1 ([..])` does not have these features: `bar`
 "));
 
-    let p = p.file("Cargo.toml", r#"
-            [project]
-            name = "foo"
-            version = "0.0.1"
-            authors = []
-        "#);
+    p.change_file("Cargo.toml", r#"
+        [project]
+        name = "foo"
+        version = "0.0.1"
+        authors = []
+    "#);
 
-    assert_that(p.cargo_process("build").arg("--features").arg("test"),
+    assert_that(p.cargo("build").arg("--features").arg("test"),
                 execs().with_status(101).with_stderr("\
 [ERROR] Package `foo v0.0.1 ([..])` does not have these features: `test`
 "));
@@ -938,25 +939,26 @@ fn dep_feature_in_cmd_line() {
             #[cfg(feature = "some-feat")]
             pub fn test() { print!("test"); }
         "#);
+    p.build();
 
     // The foo project requires that feature "some-feat" in "bar" is enabled.
     // Building without any features enabled should fail:
-    assert_that(p.cargo_process("build"),
+    assert_that(p.cargo("build"),
                 execs().with_status(101));
 
     // We should be able to enable the feature "derived-feat", which enables "some-feat",
     // on the command line. The feature is enabled, thus building should be successful:
-    assert_that(p.cargo_process("build").arg("--features").arg("derived/derived-feat"),
+    assert_that(p.cargo("build").arg("--features").arg("derived/derived-feat"),
                 execs().with_status(0));
 
     // Trying to enable features of transitive dependencies is an error
-    assert_that(p.cargo_process("build").arg("--features").arg("bar/some-feat"),
+    assert_that(p.cargo("build").arg("--features").arg("bar/some-feat"),
                 execs().with_status(101).with_stderr("\
 [ERROR] Package `foo v0.0.1 ([..])` does not have these features: `bar`
 "));
 
     // Hierarchical feature specification should still be disallowed
-    assert_that(p.cargo_process("build").arg("--features").arg("derived/bar/some-feat"),
+    assert_that(p.cargo("build").arg("--features").arg("derived/bar/some-feat"),
                 execs().with_status(101).with_stderr("\
 [ERROR] feature names may not contain slashes: `bar/some-feat`
 "));
index f7dbbc414f10e2d14d42e6192b44a6f9e1ae4010..ad775f1f9e590a5ac958e802ded2c6038747bf9e 100644 (file)
@@ -390,7 +390,6 @@ fn workspace_metadata() {
         .file("bar/src/lib.rs", "")
         .file("baz/Cargo.toml", &basic_lib_manifest("baz"))
         .file("baz/src/lib.rs", "");
-    p.build();
 
     assert_that(p.cargo_process("metadata"), execs().with_status(0).with_json(r#"
     {
@@ -465,7 +464,6 @@ fn workspace_metadata_no_deps() {
         .file("bar/src/lib.rs", "")
         .file("baz/Cargo.toml", &basic_lib_manifest("baz"))
         .file("baz/src/lib.rs", "");
-    p.build();
 
     assert_that(p.cargo_process("metadata").arg("--no-deps"), execs().with_status(0).with_json(r#"
     {
index 0e03df5cf1ad79d445421a96cdc3cc11db126dc9..64a1f2f916d52cfea5685cf3f4d3bc12e9d76e74 100644 (file)
@@ -6,7 +6,7 @@ extern crate hamcrest;
 extern crate tar;
 extern crate cargo;
 
-use std::fs::{File, OpenOptions};
+use std::fs::File;
 use std::io::prelude::*;
 use std::path::{Path, PathBuf};
 
@@ -546,6 +546,9 @@ Caused by:
 
 #[test]
 fn do_not_package_if_repository_is_dirty() {
+    let p = project("foo");
+    p.build();
+
     // Create a Git repository containing a minimal Rust project.
     git::repo(&paths::root().join("foo"))
         .file("Cargo.toml", r#"
@@ -562,10 +565,17 @@ fn do_not_package_if_repository_is_dirty() {
         .build();
 
     // Modify Cargo.toml without committing the change.
-    let p = project("foo");
-    let manifest_path = p.root().join("Cargo.toml");
-    let mut manifest = t!(OpenOptions::new().append(true).open(manifest_path));
-    t!(writeln!(manifest, ""));
+    p.change_file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            license = "MIT"
+            description = "foo"
+            documentation = "foo"
+            homepage = "foo"
+            repository = "foo"
+            # change
+    "#);
 
     assert_that(p.cargo("package"),
                 execs().with_status(101)
index 5ac929dde5554117be1de842b2fbdc5fc0b9d791..b0d9adb265885fd5b7b7995e4d53d40cd2de41d6 100644 (file)
@@ -259,8 +259,7 @@ fn cargo_compile_with_transitive_dev_deps() {
 
 #[test]
 fn no_rebuild_dependency() {
-    let mut p = project("foo");
-    p = p
+    let p = project("foo")
         .file("Cargo.toml", r#"
             [project]
 
@@ -301,16 +300,6 @@ fn no_rebuild_dependency() {
     // This time we shouldn't compile bar
     assert_that(p.cargo("build"),
                 execs().with_stdout(""));
-    p.root().move_into_the_past();
-
-    p.build(); // rebuild the files (rewriting them in the process)
-    assert_that(p.cargo("build"),
-                execs().with_stderr(&format!("[COMPILING] bar v0.5.0 ({}/bar)\n\
-                                             [COMPILING] foo v0.5.0 ({})\n\
-                                             [FINISHED] dev [unoptimized + debuginfo] target(s) \
-                                             in [..]\n",
-                                            p.url(),
-                                            p.url())));
 }
 
 #[test]
index 4ba0a79becc0ee5ef31628b4ef57b23903b4229c..1b44e0ed32eba57a3d0da2a535369cb1e2676b35 100644 (file)
@@ -214,7 +214,6 @@ fn a() {
   assert!(true);
 }
 "#);
-    foo.build();
 
     assert_that(foo.cargo_process("test"),
                 execs().with_status(0)
index cf7c1b31e44372651ff318b8419bec81cba52589..f4295a6dfa3023d6873d148fddada93303717544 100644 (file)
@@ -245,7 +245,6 @@ fn profile_in_non_root_manifest_triggers_a_warning() {
             opt-level = 1
         "#)
         .file("bar/src/main.rs", "fn main() {}");
-    p.build();
 
     assert_that(p.cargo_process("build").cwd(p.root().join("bar")).arg("-v"),
                 execs().with_status(0).with_stderr("\
@@ -277,7 +276,6 @@ fn profile_in_virtual_manifest_works() {
             workspace = ".."
         "#)
         .file("bar/src/main.rs", "fn main() {}");
-    p.build();
 
     assert_that(p.cargo_process("build").cwd(p.root().join("bar")).arg("-v"),
                 execs().with_status(0).with_stderr("\
index fd3558a4e1b232b37979f16d51c8bfc573a81418..35cfc998572b05cf7b89d391b53347b6c3dfdf8b 100644 (file)
@@ -184,6 +184,9 @@ fn unpublishable_crate() {
 #[test]
 fn dont_publish_dirty() {
     setup();
+    let p = project("foo")
+        .file("bar", "");
+    p.build();
 
     repo(&paths::root().join("foo"))
         .file("Cargo.toml", r#"
@@ -200,8 +203,6 @@ fn dont_publish_dirty() {
         .file("src/main.rs", "fn main() {}")
         .build();
 
-    let p = project("foo");
-    t!(File::create(p.root().join("bar")));
     assert_that(p.cargo("publish")
                  .arg("--host").arg(registry().to_string()),
                 execs().with_status(101).with_stderr("\
@@ -218,6 +219,9 @@ to proceed despite this, pass the `--allow-dirty` flag
 fn publish_clean() {
     setup();
 
+    let p = project("foo");
+    p.build();
+
     repo(&paths::root().join("foo"))
         .file("Cargo.toml", r#"
             [project]
@@ -233,7 +237,6 @@ fn publish_clean() {
         .file("src/main.rs", "fn main() {}")
         .build();
 
-    let p = project("foo");
     assert_that(p.cargo("publish")
                  .arg("--host").arg(registry().to_string()),
                 execs().with_status(0));
@@ -243,6 +246,10 @@ fn publish_clean() {
 fn publish_in_sub_repo() {
     setup();
 
+    let p = project("foo")
+        .file("baz", "");
+    p.build();
+
     repo(&paths::root().join("foo"))
         .file("bar/Cargo.toml", r#"
             [project]
@@ -258,8 +265,6 @@ fn publish_in_sub_repo() {
         .file("bar/src/main.rs", "fn main() {}")
         .build();
 
-    let p = project("foo");
-    t!(File::create(p.root().join("baz")));
     assert_that(p.cargo("publish").cwd(p.root().join("bar"))
                  .arg("--host").arg(registry().to_string()),
                 execs().with_status(0));
@@ -269,6 +274,10 @@ fn publish_in_sub_repo() {
 fn publish_when_ignored() {
     setup();
 
+    let p = project("foo")
+        .file("baz", "");
+    p.build();
+
     repo(&paths::root().join("foo"))
         .file("Cargo.toml", r#"
             [project]
@@ -285,8 +294,6 @@ fn publish_when_ignored() {
         .file(".gitignore", "baz")
         .build();
 
-    let p = project("foo");
-    t!(File::create(p.root().join("baz")));
     assert_that(p.cargo("publish")
                  .arg("--host").arg(registry().to_string()),
                 execs().with_status(0));
@@ -296,6 +303,10 @@ fn publish_when_ignored() {
 fn ignore_when_crate_ignored() {
     setup();
 
+    let p = project("foo")
+        .file("bar/baz", "");
+    p.build();
+
     repo(&paths::root().join("foo"))
         .file(".gitignore", "bar")
         .nocommit_file("bar/Cargo.toml", r#"
@@ -310,8 +321,6 @@ fn ignore_when_crate_ignored() {
             repository = "foo"
         "#)
         .nocommit_file("bar/src/main.rs", "fn main() {}");
-    let p = project("foo");
-    t!(File::create(p.root().join("bar/baz")));
     assert_that(p.cargo("publish").cwd(p.root().join("bar"))
                  .arg("--host").arg(registry().to_string()),
                 execs().with_status(0));
@@ -321,6 +330,10 @@ fn ignore_when_crate_ignored() {
 fn new_crate_rejected() {
     setup();
 
+    let p = project("foo")
+        .file("baz", "");
+    p.build();
+
     repo(&paths::root().join("foo"))
         .nocommit_file("Cargo.toml", r#"
             [project]
@@ -334,8 +347,6 @@ fn new_crate_rejected() {
             repository = "foo"
         "#)
         .nocommit_file("src/main.rs", "fn main() {}");
-    let p = project("foo");
-    t!(File::create(p.root().join("baz")));
     assert_that(p.cargo("publish")
                  .arg("--host").arg(registry().to_string()),
                 execs().with_status(101));
index 2fc2a0489156233bc379c776be2bfc0eb6412b71..c84d28cdd6b8d9b11be20b01ca37dabc39874a27 100644 (file)
@@ -31,10 +31,11 @@ fn simple() {
             bar = ">= 0.0.0"
         "#)
         .file("src/main.rs", "fn main() {}");
+    p.build();
 
     Package::new("bar", "0.0.1").publish();
 
-    assert_that(p.cargo_process("build"),
+    assert_that(p.cargo("build"),
                 execs().with_status(0).with_stderr(&format!("\
 [UPDATING] registry `{reg}`
 [DOWNLOADING] bar v0.0.1 (registry file://[..])
@@ -45,16 +46,16 @@ fn simple() {
         dir = p.url(),
         reg = registry::registry())));
 
+    assert_that(p.cargo("clean"), execs().with_status(0));
+
     // Don't download a second time
-    assert_that(p.cargo_process("build"),
+    assert_that(p.cargo("build"),
                 execs().with_status(0).with_stderr(&format!("\
-[UPDATING] registry `{reg}`
 [COMPILING] bar v0.0.1
 [COMPILING] foo v0.0.1 ({dir})
 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
 ",
-        dir = p.url(),
-        reg = registry::registry())));
+        dir = p.url())));
 }
 
 #[test]
@@ -126,11 +127,12 @@ fn wrong_version() {
             foo = ">= 1.0.0"
         "#)
         .file("src/main.rs", "fn main() {}");
+    p.build();
 
     Package::new("foo", "0.0.1").publish();
     Package::new("foo", "0.0.2").publish();
 
-    assert_that(p.cargo_process("build"),
+    assert_that(p.cargo("build"),
                 execs().with_status(101).with_stderr_contains("\
 [ERROR] no matching package named `foo` found (required by `foo`)
 location searched: registry [..]
@@ -141,7 +143,7 @@ versions found: 0.0.2, 0.0.1
     Package::new("foo", "0.0.3").publish();
     Package::new("foo", "0.0.4").publish();
 
-    assert_that(p.cargo_process("build"),
+    assert_that(p.cargo("build"),
                 execs().with_status(101).with_stderr_contains("\
 [ERROR] no matching package named `foo` found (required by `foo`)
 location searched: registry [..]
index a95dcf01e7508965b51afceb197d5208b6621eae..53252a0682f3d4934cc94ae8d630a5a35d133e5e 100644 (file)
@@ -292,22 +292,23 @@ fn run_with_filename() {
         .file("examples/a.rs", r#"
             fn main() { println!("example"); }
         "#);
+    p.build();
 
-    assert_that(p.cargo_process("run").arg("--bin").arg("bin.rs"),
+    assert_that(p.cargo("run").arg("--bin").arg("bin.rs"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no bin target named `bin.rs`"));
 
-    assert_that(p.cargo_process("run").arg("--bin").arg("a.rs"),
+    assert_that(p.cargo("run").arg("--bin").arg("a.rs"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no bin target named `a.rs`
 
 Did you mean `a`?"));
 
-    assert_that(p.cargo_process("run").arg("--example").arg("example.rs"),
+    assert_that(p.cargo("run").arg("--example").arg("example.rs"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no example target named `example.rs`"));
 
-    assert_that(p.cargo_process("run").arg("--example").arg("a.rs"),
+    assert_that(p.cargo("run").arg("--example").arg("a.rs"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no example target named `a.rs`
 
index 7d2969735e81f4ec24158d667624d3219d238f83..ee87f9b293f0481e559c5cf82496fe2143c30c5a 100644 (file)
@@ -1625,12 +1625,13 @@ fn bad_example() {
             authors = []
         "#)
         .file("src/lib.rs", "");
+    p.build();
 
-    assert_that(p.cargo_process("run").arg("--example").arg("foo"),
+    assert_that(p.cargo("run").arg("--example").arg("foo"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no example target named `foo`
 "));
-    assert_that(p.cargo_process("run").arg("--bin").arg("foo"),
+    assert_that(p.cargo("run").arg("--bin").arg("foo"),
                 execs().with_status(101).with_stderr("\
 [ERROR] no bin target named `foo`
 "));
@@ -2332,8 +2333,9 @@ fn pass_correct_cfgs_flags_to_rustdoc() {
                 authors = []
             "#)
         .file("libs/mock_serde_codegen/src/lib.rs", "");
+    p.build();
 
-    assert_that(p.cargo_process("test")
+    assert_that(p.cargo("test")
                 .arg("--package").arg("feature_a")
                 .arg("--verbose"),
                 execs().with_status(0)
@@ -2341,7 +2343,7 @@ fn pass_correct_cfgs_flags_to_rustdoc() {
 [DOCTEST] feature_a
 [RUNNING] `rustdoc --test [..]mock_serde_codegen[..]`"));
 
-    assert_that(p.cargo_process("test")
+    assert_that(p.cargo("test")
                 .arg("--verbose"),
                 execs().with_status(0)
                        .with_stderr_contains("\
@@ -2406,9 +2408,8 @@ fn test_many_with_features() {
             authors = []
         "#)
         .file("a/src/lib.rs", "");
-    p.build();
 
-    assert_that(p.cargo("test").arg("-v")
+    assert_that(p.cargo_process("test").arg("-v")
                  .arg("-p").arg("a")
                  .arg("-p").arg("foo")
                  .arg("--features").arg("foo"),
@@ -2441,7 +2442,6 @@ fn test_all_workspace() {
             #[test]
             fn bar_test() {}
         "#);
-    p.build();
 
     assert_that(p.cargo_process("test")
                  .arg("--all"),
@@ -2486,7 +2486,6 @@ fn test_all_virtual_manifest() {
             #[test]
             fn b() {}
         "#);
-    p.build();
 
     assert_that(p.cargo_process("test")
                  .arg("--all"),
@@ -2525,7 +2524,6 @@ fn test_all_member_dependency_same_name() {
             #[test]
             fn a() {}
         "#);
-    p.build();
 
     Package::new("a", "0.1.0").publish();
 
index 5ace3fa2276f1213e3320387a346bf991181e327..bc8c0c1b94c83914cc7a5a509059b81651111b89 100644 (file)
@@ -9,12 +9,13 @@ use hamcrest::assert_that;
 #[test]
 fn simple() {
     let p = project("foo");
+    p.build();
 
-    assert_that(p.cargo_process("version"),
+    assert_that(p.cargo("version"),
                 execs().with_status(0).with_stdout(&format!("{}\n",
                                                             cargo::version())));
 
-    assert_that(p.cargo_process("--version"),
+    assert_that(p.cargo("--version"),
                 execs().with_status(0).with_stdout(&format!("{}\n",
                                                             cargo::version())));