diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index c89d86f84cc1..7919c6d1f42e 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1,8 +1,7 @@ //! Tests for fingerprinting (rebuild detection). -#![allow(deprecated)] - use filetime::FileTime; +use snapbox::IntoData; use std::fs::{self, OpenOptions}; use std::io; use std::io::prelude::*; @@ -17,7 +16,7 @@ use cargo_test_support::paths::{self, CargoPathExt}; use cargo_test_support::registry::Package; use cargo_test_support::{ basic_lib_manifest, basic_manifest, is_coarse_mtime, project, rustc_host, rustc_host_env, - sleep_ms, + sleep_ms, str, }; #[cargo_test] @@ -28,34 +27,39 @@ fn modifying_and_moving() { .build(); p.cargo("build") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); - p.cargo("build").with_stderr("[FINISHED] [..]").run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); p.root().move_into_the_past(); p.root().join("target").move_into_the_past(); p.change_file("src/a.rs", "#[allow(unused)]fn main() {}"); - p.cargo("build -v") - .with_stderr( - "\ -[DIRTY] foo v0.0.1 ([CWD]): the file `src/a.rs` has changed ([..]) -[COMPILING] foo v0.0.1 ([CWD]) + p.cargo("build -v").with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the file `src/a.rs` has changed ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc --crate-name foo [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); fs::rename(&p.root().join("src/a.rs"), &p.root().join("src/b.rs")).unwrap(); p.cargo("build") .with_status(101) - .with_stderr_contains("[..]file not found[..]") + .with_stderr_data(str![[r#" +... +[..]file not found[..] +... +"#]]) .run(); } @@ -70,12 +74,11 @@ fn modify_only_some_files() { .build(); p.cargo("build") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("test").run(); sleep_ms(1000); @@ -89,14 +92,13 @@ fn modify_only_some_files() { // Make sure the binary is rebuilt, not the lib p.cargo("build -v") - .with_stderr( - "\ -[DIRTY] foo v0.0.1 ([CWD]): the file `src/b.rs` has changed ([..]) -[COMPILING] foo v0.0.1 ([CWD]) + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the file `src/b.rs` has changed ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc --crate-name foo [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert!(p.bin("foo").is_file()); } @@ -138,15 +140,14 @@ fn rebuild_sub_package_then_while_package() { .build(); p.cargo("build") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 3 packages to latest compatible versions -[COMPILING] b [..] -[COMPILING] a [..] -[COMPILING] foo [..] -[FINISHED] `dev` profile [..] -", - ) +[COMPILING] b v0.0.1 ([ROOT]/foo/b) +[COMPILING] a v0.0.1 ([ROOT]/foo/a) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); if is_coarse_mtime() { @@ -154,36 +155,30 @@ fn rebuild_sub_package_then_while_package() { } p.change_file("b/src/lib.rs", "pub fn b() {}"); - p.cargo("build -pb -v") - .with_stderr( - "\ -[DIRTY] b v0.0.1 ([..]): the file `b/src/lib.rs` has changed ([..]) -[COMPILING] b [..] + p.cargo("build -pb -v").with_stderr_data(str![[r#" +[DIRTY] b v0.0.1 ([ROOT]/foo/b): the file `b/src/lib.rs` has changed ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] b v0.0.1 ([ROOT]/foo/b) [RUNNING] `rustc --crate-name b [..] -[FINISHED] `dev` profile [..] -", - ) - .run(); +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); p.change_file( "src/lib.rs", "extern crate a; extern crate b; pub fn toplevel() {}", ); - p.cargo("build -v") - .with_stderr( - "\ -[FRESH] b [..] -[DIRTY] a [..]: the dependency b was rebuilt ([..]) -[COMPILING] a [..] + p.cargo("build -v").with_stderr_data(str![[r#" +[FRESH] b v0.0.1 ([ROOT]/foo/b) +[DIRTY] a v0.0.1 ([ROOT]/foo/a): the dependency b was rebuilt ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] a v0.0.1 ([ROOT]/foo/a) [RUNNING] `rustc --crate-name a [..] -[DIRTY] foo [..]: the dependency b was rebuilt ([..]) -[COMPILING] foo [..] -[RUNNING] `rustc --crate-name foo [..] -[FINISHED] `dev` profile [..] -", - ) - .run(); +[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency b was rebuilt ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc --crate-name foo [..] src/lib.rs [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); } #[cargo_test] @@ -206,33 +201,42 @@ fn changing_lib_features_caches_targets() { .build(); p.cargo("build") - .with_stderr( - "\ -[..]Compiling foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build --features foo") - .with_stderr( - "\ -[..]Compiling foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); /* Targets should be cached from the first build */ p.cargo("build") - .with_stderr("[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); - p.cargo("build").with_stderr("[FINISHED] [..]").run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); p.cargo("build --features foo") - .with_stderr("[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -256,38 +260,38 @@ fn changing_profiles_caches_targets() { .build(); p.cargo("build") - .with_stderr( - "\ -[..]Compiling foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("test") - .with_stderr( - "\ -[..]Compiling foo v0.0.1 ([..]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target[..]debug[..]deps[..]foo-[..][EXE]) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH]) [DOCTEST] foo -", - ) + +"#]]) .run(); /* Targets should be cached from the first build */ p.cargo("build") - .with_stderr("[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("test foo") - .with_stderr( - "\ -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] [..] (target[..]debug[..]deps[..]foo-[..][EXE]) -", - ) + .with_stderr_data(str![[r#" +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH]) + +"#]]) .run(); } @@ -382,55 +386,63 @@ fn changing_bin_paths_common_target_features_caches_targets() { /* Build and rebuild a/. Ensure dep_crate only builds once */ p.cargo("run") .cwd("a") - .with_stdout("ftest off") - .with_stderr( - "\ + .with_stdout_data(str![[r#" +ftest off + +"#]]) + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[..]Compiling dep_crate v0.0.1 ([..]) -[..]Compiling a v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `[..]target/debug/a[EXE]` -", - ) +[COMPILING] dep_crate v0.0.1 ([ROOT]/foo/dep_crate) +[COMPILING] a v0.0.1 ([ROOT]/foo/a) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `[ROOT]/foo/./target/debug/a` + +"#]]) .run(); p.cargo("clean -p a").cwd("a").run(); p.cargo("run") .cwd("a") - .with_stdout("ftest off") - .with_stderr( - "\ -[..]Compiling a v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `[..]target/debug/a[EXE]` -", - ) + .with_stdout_data(str![[r#" +ftest off + +"#]]) + .with_stderr_data(str![[r#" +[COMPILING] a v0.0.1 ([ROOT]/foo/a) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `[ROOT]/foo/./target/debug/a` + +"#]]) .run(); /* Build and rebuild b/. Ensure dep_crate only builds once */ p.cargo("run") .cwd("b") - .with_stdout("ftest on") - .with_stderr( - "\ + .with_stdout_data(str![[r#" +ftest on + +"#]]) + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[..]Compiling dep_crate v0.0.1 ([..]) -[..]Compiling b v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `[..]target/debug/b[EXE]` -", - ) +[COMPILING] dep_crate v0.0.1 ([ROOT]/foo/dep_crate) +[COMPILING] b v0.0.1 ([ROOT]/foo/b) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `[ROOT]/foo/./target/debug/b` + +"#]]) .run(); p.cargo("clean -p b").cwd("b").run(); p.cargo("run") .cwd("b") - .with_stdout("ftest on") - .with_stderr( - "\ -[..]Compiling b v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `[..]target/debug/b[EXE]` -", - ) + .with_stdout_data(str![[r#" +ftest on + +"#]]) + .with_stderr_data(str![[r#" +[COMPILING] b v0.0.1 ([ROOT]/foo/b) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `[ROOT]/foo/./target/debug/b` + +"#]]) .run(); /* Build a/ package again. If we cache different feature dep builds correctly, @@ -438,14 +450,16 @@ fn changing_bin_paths_common_target_features_caches_targets() { p.cargo("clean -p a").cwd("a").run(); p.cargo("run") .cwd("a") - .with_stdout("ftest off") - .with_stderr( - "\ -[..]Compiling a v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `[..]target/debug/a[EXE]` -", - ) + .with_stdout_data(str![[r#" +ftest off + +"#]]) + .with_stderr_data(str![[r#" +[COMPILING] a v0.0.1 ([ROOT]/foo/a) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `[ROOT]/foo/./target/debug/a` + +"#]]) .run(); /* Build b/ package again. If we cache different feature dep builds correctly, @@ -453,14 +467,16 @@ fn changing_bin_paths_common_target_features_caches_targets() { p.cargo("clean -p b").cwd("b").run(); p.cargo("run") .cwd("b") - .with_stdout("ftest on") - .with_stderr( - "\ -[..]Compiling b v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `[..]target/debug/b[EXE]` -", - ) + .with_stdout_data(str![[r#" +ftest on + +"#]]) + .with_stderr_data(str![[r#" +[COMPILING] b v0.0.1 ([ROOT]/foo/b) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `[ROOT]/foo/./target/debug/b` + +"#]]) .run(); } @@ -492,24 +508,32 @@ fn changing_bin_features_caches_targets() { .build(); p.cargo("build") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); + p.rename_run("foo", "off1") + .with_stdout_data(str![[r#" +feature off + +"#]]) .run(); - p.rename_run("foo", "off1").with_stdout("feature off").run(); p.cargo("build --features foo") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); + p.rename_run("foo", "on1") + .with_stdout_data(str![[r#" +feature on + +"#]]) .run(); - p.rename_run("foo", "on1").with_stdout("feature on").run(); /* Targets should be cached from the first build */ @@ -517,37 +541,51 @@ fn changing_bin_features_caches_targets() { // MSVC does not include hash in binary filename, so it gets recompiled. if cfg!(target_env = "msvc") { - e.with_stderr( - "\ -[DIRTY] foo v0.0.1 ([..]): the list of features changed -[COMPILING] foo[..] -[RUNNING] `rustc [..] -[FINISHED] `dev`[..]", - ); + e.with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency foo was rebuilt ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc --crate-name [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); } else { - e.with_stderr("[FRESH] foo v0.0.1 ([..])\n[FINISHED] `dev`[..]"); + e.with_stderr_data(str![[r#" +[FRESH] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]); } e.run(); - p.rename_run("foo", "off2").with_stdout("feature off").run(); + p.rename_run("foo", "off2") + .with_stdout_data(str![[r#" +feature off + +"#]]) + .run(); let mut e = p.cargo("build --features foo -v"); if cfg!(target_env = "msvc") { - e.with_stderr( - "\ -[DIRTY] foo v0.0.1 ([..]): the list of features changed -[COMPILING] foo[..] + e.with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency foo was rebuilt ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] -[FINISHED] `dev`[..]", - ); +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); } else { - e.with_stderr( - "\ -[FRESH] foo v0.0.1 ([..]) -[FINISHED] `dev`[..]", - ); + e.with_stderr_data(str![[r#" +[FRESH] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]); } e.run(); - p.rename_run("foo", "on2").with_stdout("feature on").run(); + p.rename_run("foo", "on2") + .with_stdout_data(str![[r#" +feature on + +"#]]) + .run(); } #[cargo_test] @@ -573,7 +611,16 @@ fn rebuild_tests_if_lib_changes() { p.cargo("build -v").run(); p.cargo("test -v") .with_status(101) - .with_stderr_contains("[..]cannot find function `foo`[..]") + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency foo was rebuilt ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc --crate-name foo [..] +[RUNNING] `rustc --crate-name foo [..] +error[E0425]: cannot find function `foo` in crate `foo` +... +[WARNING] build failed, waiting for other jobs to finish... + +"#]]) .run(); } @@ -631,16 +678,15 @@ fn no_rebuild_transitive_target_deps() { p.cargo("build").run(); p.cargo("test --no-run") - .with_stderr( - "\ -[COMPILING] c v0.0.1 ([..]) -[COMPILING] b v0.0.1 ([..]) -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..] -[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[..][EXE]) -[EXECUTABLE] tests/foo.rs (target/debug/deps/foo-[..][EXE]) -", - ) + .with_stderr_data(str![[r#" +[COMPILING] c v0.0.1 ([ROOT]/foo/c) +[COMPILING] b v0.0.1 ([ROOT]/foo/b) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH]) +[EXECUTABLE] tests/foo.rs (target/debug/deps/foo-[HASH]) + +"#]]) .run(); } @@ -684,7 +730,12 @@ fn rerun_if_changed_in_dep() { .build(); p.cargo("build").run(); - p.cargo("build").with_stderr("[FINISHED] [..]").run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); } #[cargo_test] @@ -756,27 +807,24 @@ fn same_build_dir_cached_packages() { p.cargo("build") .cwd("a1") - .with_stderr(&format!( - "\ + .with_stderr_data(str![[r#" [LOCKING] 4 packages to latest compatible versions -[COMPILING] d v0.0.1 ({dir}/d) -[COMPILING] c v0.0.1 ({dir}/c) -[COMPILING] b v0.0.1 ({dir}/b) -[COMPILING] a1 v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - dir = p.url().to_file_path().unwrap().to_str().unwrap() - )) +[COMPILING] d v0.0.1 ([ROOT]/foo/d) +[COMPILING] c v0.0.1 ([ROOT]/foo/c) +[COMPILING] b v0.0.1 ([ROOT]/foo/b) +[COMPILING] a1 v0.0.1 ([ROOT]/foo/a1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build") .cwd("a2") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 4 packages to latest compatible versions -[COMPILING] a2 v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +[COMPILING] a2 v0.0.1 ([ROOT]/foo/a2) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -806,8 +854,11 @@ fn no_rebuild_if_build_artifacts_move_backwards_in_time() { p.root().move_into_the_past(); p.cargo("build") - .with_stdout("") - .with_stderr("[FINISHED] [..]") + .with_stdout_data(str![]) + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -838,14 +889,13 @@ fn rebuild_if_build_artifacts_move_forward_in_time() { p.cargo("build") .env("CARGO_LOG", "") - .with_stdout("") - .with_stderr( - "\ -[COMPILING] a v0.0.1 ([..]) -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] [..] -", - ) + .with_stdout_data(str![]) + .with_stderr_data(str![[r#" +[COMPILING] a v0.0.1 ([ROOT]/foo/a) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -874,14 +924,16 @@ fn rebuild_if_environment_changes() { .build(); p.cargo("run") - .with_stdout("old desc") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/foo[EXE]` -", - ) + .with_stdout_data(str![[r#" +old desc + +"#]]) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo` + +"#]]) .run(); p.change_file( @@ -897,16 +949,18 @@ fn rebuild_if_environment_changes() { ); p.cargo("run -v") - .with_stdout("new desc") - .with_stderr( - "\ -[DIRTY] foo v0.0.1 ([CWD]): the metadata changed -[COMPILING] foo v0.0.1 ([CWD]) + .with_stdout_data(str![[r#" +new desc + +"#]]) + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the metadata changed +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -[RUNNING] `target/debug/foo[EXE]` -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `target/debug/foo` + +"#]]) .run(); } @@ -949,7 +1003,10 @@ fn no_rebuild_when_rename_dir() { p.cargo("build") .cwd(&new) - .with_stderr("[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1007,7 +1064,12 @@ fn unused_optional_dep() { .build(); p.cargo("build").run(); - p.cargo("build").with_stderr("[FINISHED] [..]").run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); } #[cargo_test] @@ -1064,7 +1126,12 @@ fn path_dev_dep_registry_updates() { .build(); p.cargo("build").run(); - p.cargo("build").with_stderr("[FINISHED] [..]").run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); } #[cargo_test] @@ -1159,9 +1226,17 @@ fn dont_rebuild_based_on_plugins() { p.cargo("build").run(); p.cargo("build -p baz").run(); - p.cargo("build").with_stderr("[FINISHED] [..]\n").run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); p.cargo("build -p bar") - .with_stderr("[FINISHED] [..]\n") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1189,14 +1264,13 @@ fn reuse_workspace_lib() { p.cargo("build").run(); p.cargo("test -p baz -v --no-run") - .with_stderr( - "\ -[COMPILING] baz v0.1.1 ([..]) -[RUNNING] `rustc[..] --test [..]` -[FINISHED] [..] -[EXECUTABLE] `[..]/target/debug/deps/baz-[..][EXE]` -", - ) + .with_stderr_data(str![[r#" +[COMPILING] baz v0.1.1 ([ROOT]/foo/baz) +[RUNNING] `rustc --crate-name baz [..] +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[EXECUTABLE] `[ROOT]/foo/target/debug/deps/baz-[HASH]` + +"#]]) .run(); } @@ -1240,13 +1314,12 @@ fn reuse_shared_build_dep() { p.cargo("build --workspace").run(); // This should not recompile! p.cargo("build -p foo -v") - .with_stderr( - "\ -[FRESH] shared [..] -[FRESH] foo [..] -[FINISHED] [..] -", - ) + .with_stderr_data(str![[r#" +[FRESH] shared v0.0.1 ([ROOT]/foo/shared) +[FRESH] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1256,41 +1329,41 @@ fn changing_rustflags_is_cached() { // This isn't ever cached, we always have to recompile p.cargo("build") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build -v") .env("RUSTFLAGS", "-C linker=cc") - .with_stderr( - "\ -[DIRTY] foo v0.0.1 ([..]): the rustflags changed -[COMPILING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build -v") - .with_stderr( - "\ -[DIRTY] foo v0.0.1 ([..]): the rustflags changed -[COMPILING] foo v0.0.1 ([..]) -[RUNNING] `rustc [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]", - ) + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc [..] src/lib.rs [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build -v") .env("RUSTFLAGS", "-C linker=cc") - .with_stderr( - "\ -[DIRTY] foo v0.0.1 ([..]): the rustflags changed -[COMPILING] foo v0.0.1 ([..]) + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1317,25 +1390,31 @@ fn update_dependency_mtime_does_not_rebuild() { p.cargo("build -Z mtime-on-use") .masquerade_as_nightly_cargo(&["mtime-on-use"]) .env("RUSTFLAGS", "-C linker=cc") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[COMPILING] bar v0.0.1 ([..]) -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]", - ) +[COMPILING] bar v0.0.1 ([ROOT]/foo/bar) +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // This does not make new files, but it does update the mtime of the dependency. p.cargo("build -p bar -Z mtime-on-use") .masquerade_as_nightly_cargo(&["mtime-on-use"]) .env("RUSTFLAGS", "-C linker=cc") - .with_stderr("[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // This should not recompile! p.cargo("build -Z mtime-on-use") .masquerade_as_nightly_cargo(&["mtime-on-use"]) .env("RUSTFLAGS", "-C linker=cc") - .with_stderr("[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1399,11 +1478,11 @@ fn fingerprint_cleaner_does_not_rebuild() { .run(); p.cargo("build -Z mtime-on-use --features a") .masquerade_as_nightly_cargo(&["mtime-on-use"]) - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); if is_coarse_mtime() { sleep_ms(1000); @@ -1415,22 +1494,28 @@ fn fingerprint_cleaner_does_not_rebuild() { // This does not make new files, but it does update the mtime. p.cargo("build -Z mtime-on-use --features a") .masquerade_as_nightly_cargo(&["mtime-on-use"]) - .with_stderr("[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); fingerprint_cleaner(p.target_debug_dir(), timestamp); // This should not recompile! p.cargo("build -Z mtime-on-use --features a") .masquerade_as_nightly_cargo(&["mtime-on-use"]) - .with_stderr("[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // But this should be cleaned and so need a rebuild p.cargo("build -Z mtime-on-use") .masquerade_as_nightly_cargo(&["mtime-on-use"]) - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1463,19 +1548,18 @@ fn reuse_panic_build_dep_test() { // Check that `bar` is not built twice. It is only needed once (without `panic`). p.cargo("test --lib --no-run -v") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[COMPILING] bar [..] +[COMPILING] bar v0.0.1 ([ROOT]/foo/bar) [RUNNING] `rustc --crate-name bar [..] -[COMPILING] foo [..] +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc --crate-name build_script_build [..] -[RUNNING] [..]build-script-build` -[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--test[..] -[FINISHED] [..] -[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]` -", - ) +[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` +[RUNNING] `rustc --crate-name foo [..] src/lib.rs [..]--test[..] +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[EXECUTABLE] `[ROOT]/foo/target/debug/deps/foo-[HASH]` + +"#]]) .run(); } @@ -1524,18 +1608,20 @@ fn reuse_panic_pm() { // bar is built once without panic (for proc-macro) and once with (for the // normal dependency). p.cargo("build -v") - .with_stderr_unordered( - "\ + .with_stderr_data( + str![[r#" [LOCKING] 3 packages to latest compatible versions -[COMPILING] bar [..] -[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..] -[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C debuginfo=2 [..] -[COMPILING] somepm [..] -[RUNNING] `rustc --crate-name somepm [..] -[COMPILING] foo [..] -[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]-C panic=abort[..] -[FINISHED] [..] -", +[COMPILING] bar v0.0.1 ([ROOT]/foo/bar) +[RUNNING] `rustc --crate-name bar [..] bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..] +[RUNNING] `rustc --crate-name bar [..] bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C debuginfo=2 [..] +[COMPILING] somepm v0.0.1 ([ROOT]/foo/somepm) +[RUNNING] `rustc --crate-name somepm [..]` +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc --crate-name foo [..]-C panic=abort[..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]] + .unordered(), ) .run(); } @@ -1578,32 +1664,28 @@ fn bust_patched_dep() { sleep_ms(1000); } - p.cargo("build -v") - .with_stderr( - "\ -[DIRTY] registry1 v0.1.0 ([..]): the file `reg1new/src/lib.rs` has changed ([..]) -[COMPILING] registry1 v0.1.0 ([..]) -[RUNNING] `rustc [..] + p.cargo("build -v").with_stderr_data(str![[r#" +[DIRTY] registry1 v0.1.0 ([ROOT]/foo/reg1new): the file `reg1new/src/lib.rs` has changed ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] registry1 v0.1.0 ([ROOT]/foo/reg1new) +[RUNNING] `rustc --crate-name registry1 [..] [DIRTY] registry2 v0.1.0: the dependency registry1 was rebuilt [COMPILING] registry2 v0.1.0 -[RUNNING] `rustc [..] -[DIRTY] foo v0.0.1 ([..]): the dependency registry2 was rebuilt -[COMPILING] foo v0.0.1 ([..]) -[RUNNING] `rustc [..] -[FINISHED] [..] -", - ) - .run(); +[RUNNING] `rustc --crate-name registry2 [..] +[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency registry2 was rebuilt +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc --crate-name foo [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); p.cargo("build -v") - .with_stderr( - "\ -[FRESH] registry1 v0.1.0 ([..]) + .with_stderr_data(str![[r#" +[FRESH] registry1 v0.1.0 ([ROOT]/foo/reg1new) [FRESH] registry2 v0.1.0 -[FRESH] foo v0.0.1 ([..]) -[FINISHED] [..] -", - ) +[FRESH] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -1695,28 +1777,24 @@ fn rebuild_on_mid_build_file_modification() { }); p.cargo("build") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [LOCKING] 2 packages to latest compatible versions -[COMPILING] proc_macro_dep v0.1.0 ([..]/proc_macro_dep) -[COMPILING] root v0.1.0 ([..]/root) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) - .run(); +[COMPILING] proc_macro_dep v0.1.0 ([ROOT]/foo/proc_macro_dep) +[COMPILING] root v0.1.0 ([ROOT]/foo/root) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s - p.cargo("build -v") - .with_stderr( - "\ -[FRESH] proc_macro_dep v0.1.0 ([..]/proc_macro_dep) -[DIRTY] root v0.1.0 ([..]/root): the file `root/src/lib.rs` has changed ([..]) -[COMPILING] root v0.1.0 ([..]/root) -[RUNNING] `rustc [..] -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..] -", - ) +"#]]) .run(); + p.cargo("build -v").with_stderr_data(str![[r#" +[FRESH] proc_macro_dep v0.1.0 ([ROOT]/foo/proc_macro_dep) +[DIRTY] root v0.1.0 ([ROOT]/foo/root): the file `root/src/lib.rs` has changed ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[COMPILING] root v0.1.0 ([ROOT]/foo/root) +[RUNNING] `rustc --crate-name root [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]).run(); + t.join().ok().unwrap(); } @@ -1797,7 +1875,29 @@ fn dirty_both_lib_and_test() { // 2 != 1 p.cargo("test --lib") .with_status(101) - .with_stdout_contains("[..]doit assert failure[..]") + .with_stdout_data(str![[r#" + +running 1 test +test t1 ... FAILED + +failures: + +---- t1 stdout ---- +thread 't1' panicked at src/lib.rs:8:21: +assertion `left == right` failed: doit assert failure + left: 2 + right: 1 +... +[NOTE] Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. + + +failures: + t1 + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s + + +"#]]) .run(); if is_coarse_mtime() { @@ -1841,12 +1941,24 @@ fn script_fails_stay_dirty() { } p.change_file("helper.rs", r#"pub fn doit() {panic!("Crash!");}"#); p.cargo("build") - .with_stderr_contains("[..]Crash![..]") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[ERROR] failed to run custom build command for `foo v0.0.1 ([ROOT]/foo)` +... +[..]Crash! +... +"#]]) .with_status(101) .run(); // There was a bug where this second call would be "fresh". p.cargo("build") - .with_stderr_contains("[..]Crash![..]") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[ERROR] failed to run custom build command for `foo v0.0.1 ([ROOT]/foo)` +... +[..]Crash! +... +"#]]) .with_status(101) .run(); } @@ -1957,8 +2069,8 @@ fn simulated_docker_deps_stay_cached() { println!("already zero"); // If it was already truncated, then everything stays fresh. p.cargo("build -v") - .with_stderr_unordered( - "\ + .with_stderr_data( + str![[r#" [FRESH] pathdep [..] [FRESH] regdep [..] [FRESH] regdep_env [..] @@ -1966,7 +2078,9 @@ fn simulated_docker_deps_stay_cached() { [FRESH] regdep_rerun [..] [FRESH] foo [..] [FINISHED] [..] -", + +"#]] + .unordered(), ) .run(); } else { @@ -1981,19 +2095,21 @@ fn simulated_docker_deps_stay_cached() { // in it. It differs between builds because one has nsec=0 and the other // likely has a nonzero nsec. Hence, the rebuild. p.cargo("build -v") - .with_stderr_unordered( - "\ -[FRESH] pathdep [..] + .with_stderr_data( + str![[r#" [FRESH] regdep [..] +[FRESH] pathdep [..] [FRESH] regdep_env [..] -[FRESH] regdep_old_style [..] +[DIRTY] foo v0.1.0 ([ROOT]/foo): the precalculated components changed +[COMPILING] foo v0.1.0 ([ROOT]/foo) [FRESH] regdep_rerun [..] -[DIRTY] foo [..]: the precalculated components changed -[COMPILING] foo [..] -[RUNNING] [..]/foo-[..]/build-script-build[..] -[RUNNING] `rustc --crate-name foo[..] -[FINISHED] [..] -", +[FRESH] regdep_old_style [..] +[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` +[RUNNING] `rustc --crate-name foo [..]` +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]] + .unordered(), ) .run(); } @@ -2029,11 +2145,19 @@ fn metadata_change_invalidates() { .unwrap(); writeln!(file, "{}", attr).unwrap(); p.cargo("build") - .with_stderr_contains("[COMPILING] foo [..]") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } p.cargo("build -v") - .with_stderr_contains("[FRESH] foo[..]") + .with_stderr_data(str![[r#" +[FRESH] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_eq!(p.glob("target/debug/deps/libfoo-*.rlib").count(), 1); } @@ -2052,7 +2176,11 @@ fn edition_change_invalidates() { p.cargo("build").run(); p.change_file("Cargo.toml", &format!("{}edition = \"2018\"", MANIFEST)); p.cargo("build") - .with_stderr_contains("[COMPILING] foo [..]") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.change_file( "Cargo.toml", @@ -2065,10 +2193,18 @@ fn edition_change_invalidates() { ), ); p.cargo("build") - .with_stderr_contains("[COMPILING] foo [..]") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build -v") - .with_stderr_contains("[FRESH] foo[..]") + .with_stderr_data(str![[r#" +[FRESH] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); assert_eq!(p.glob("target/debug/deps/libfoo-*.rlib").count(), 1); } @@ -2129,7 +2265,10 @@ fn rename_with_path_deps() { p.cargo("build") .cwd(&new) - .with_stderr("[FINISHED] [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -2198,7 +2337,10 @@ fn move_target_directory_with_path_deps() { p.cargo("build") .env("CARGO_TARGET_DIR", &new_target) - .with_stderr("[FINISHED] [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -2220,59 +2362,70 @@ fn rerun_if_changes() { .build(); p.cargo("build").run(); - p.cargo("build").with_stderr("[FINISHED] [..]").run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); p.cargo("build -v") .env("FOO", "1") - .with_stderr( - "\ -[DIRTY] foo [..]: the env variable FOO changed -[COMPILING] foo [..] -[RUNNING] `[..]build-script-build` + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the env variable FOO changed +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` [RUNNING] `rustc [..] -[FINISHED] [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build") .env("FOO", "1") - .with_stderr("[FINISHED] [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build -v") .env("FOO", "1") .env("BAR", "1") - .with_stderr( - "\ -[DIRTY] foo [..]: the env variable BAR changed -[COMPILING] foo [..] -[RUNNING] `[..]build-script-build` + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the env variable BAR changed +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` [RUNNING] `rustc [..] -[FINISHED] [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build") .env("FOO", "1") .env("BAR", "1") - .with_stderr("[FINISHED] [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build -v") .env("BAR", "2") - .with_stderr( - "\ -[DIRTY] foo [..]: the env variable FOO changed -[COMPILING] foo [..] -[RUNNING] `[..]build-script-build` + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the env variable FOO changed +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build` [RUNNING] `rustc [..] -[FINISHED] [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build") .env("BAR", "2") - .with_stderr("[FINISHED] [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -2561,16 +2714,15 @@ fn linking_interrupted() { // Build again, shouldn't be fresh. p.cargo("test --test t1 -v") - .with_stderr( - "\ -[DIRTY] foo v0.0.1 ([..]): the config settings changed -[COMPILING] foo [..] + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the config settings changed +[COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc --crate-name foo [..] [RUNNING] `rustc --crate-name t1 [..] -[FINISHED] [..] -[RUNNING] `[..]target/debug/deps/t1-[..][EXE]` -", - ) +[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[RUNNING] `[ROOT]/foo/target/debug/deps/t1-[HASH]` + +"#]]) .run(); } @@ -2607,7 +2759,11 @@ fn lld_is_fresh() { p.cargo("build").run(); p.cargo("build -v") - .with_stderr("[FRESH] foo [..]\n[FINISHED] [..]") + .with_stderr_data(str![[r#" +[FRESH] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -2637,62 +2793,80 @@ fn env_in_code_causes_rebuild() { p.cargo("build").env_remove("FOO").run(); p.cargo("build") .env_remove("FOO") - .with_stderr("[FINISHED] [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build -v") .env("FOO", "bar") - .with_stderr( - "\ -[DIRTY] foo [..]: the environment variable FOO changed -[COMPILING][..] + .with_stderr_data(str![[r#" +[DIRTY] foo v0.1.0 ([ROOT]/foo): the environment variable FOO changed +[COMPILING] foo v0.1.0 ([ROOT]/foo) [RUNNING] `rustc [..] -[FINISHED][..]", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build") .env("FOO", "bar") - .with_stderr("[FINISHED][..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build -v") .env("FOO", "baz") - .with_stderr( - "\ -[DIRTY] foo [..]: the environment variable FOO changed -[COMPILING][..] + .with_stderr_data(str![[r#" +[DIRTY] foo v0.1.0 ([ROOT]/foo): the environment variable FOO changed +[COMPILING] foo v0.1.0 ([ROOT]/foo) [RUNNING] `rustc [..] -[FINISHED][..]", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build") .env("FOO", "baz") - .with_stderr("[FINISHED][..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build -v") .env_remove("FOO") - .with_stderr( - "\ -[DIRTY] foo [..]: the environment variable FOO changed -[COMPILING][..] + .with_stderr_data(str![[r#" +[DIRTY] foo v0.1.0 ([ROOT]/foo): the environment variable FOO changed +[COMPILING] foo v0.1.0 ([ROOT]/foo) [RUNNING] `rustc [..] -[FINISHED][..]", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build") .env_remove("FOO") - .with_stderr("[FINISHED][..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); let interesting = " #!$\nabc\r\\\t\u{8}\r\n"; p.cargo("build").env("FOO", interesting).run(); p.cargo("build") .env("FOO", interesting) - .with_stderr("[FINISHED][..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.cargo("build").env("FOO\nBAR", interesting).run(); p.cargo("build") .env("FOO\nBAR", interesting) - .with_stderr("[FINISHED][..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -2727,7 +2901,12 @@ fn env_build_script_no_rebuild() { .build(); p.cargo("build").run(); - p.cargo("build").with_stderr("[FINISHED] [..]").run(); + p.cargo("build") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); } #[cargo_test] @@ -2759,35 +2938,32 @@ fn cargo_env_changes() { other_cargo() .arg("check") .arg("-v") - .with_stderr( - "\ -[DIRTY] foo v1.0.0 ([..]): the environment variable CARGO changed -[CHECKING] foo [..] + .with_stderr_data(str![[r#" +[DIRTY] foo v1.0.0 ([ROOT]/foo): the environment variable CARGO changed +[CHECKING] foo v1.0.0 ([ROOT]/foo) [RUNNING] `rustc [..] -[FINISHED] [..] -", - ) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // And just to confirm that without using env! it doesn't rebuild. p.change_file("src/main.rs", "fn main() {}"); p.cargo("check") - .with_stderr( - "\ -[CHECKING] foo [..] -[FINISHED] [..] -", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v1.0.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); other_cargo() .arg("check") .arg("-v") - .with_stderr( - "\ -[FRESH] foo [..] -[FINISHED] [..] -", - ) + .with_stderr_data(str![[r#" +[FRESH] foo v1.0.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -2800,13 +2976,13 @@ fn changing_linker() { p.cargo("build --verbose") .env(&linker_env, "nonexistent-linker") .with_status(101) - .with_stderr_contains( - "\ -[COMPILING] foo v0.0.1 ([..]) -[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]` -[ERROR] [..]linker[..] -", - ) + .with_stderr_data(str![[r#" +[DIRTY] foo v0.0.1 ([ROOT]/foo): the config settings changed +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc --crate-name foo [..] -C linker=nonexistent-linker [..]` +[ERROR] linker `nonexistent-linker` not found +... +"#]]) .run(); } @@ -2844,9 +3020,14 @@ fn verify_source_before_recompile() { ); // Sanity check: vendoring works correctly. p.cargo("check --verbose") - .with_stderr_contains( - "[RUNNING] `rustc --crate-name bar --edition=2015 [CWD]/vendor/bar/src/lib.rs[..]", - ) + .with_stderr_data(str![[r#" +[CHECKING] bar v0.1.0 +[RUNNING] `rustc --crate-name bar [..] [ROOT]/foo/vendor/bar/src/lib.rs [..] +[CHECKING] foo v0.1.0 ([ROOT]/foo) +[RUNNING] `rustc --crate-name foo [..] src/lib.rs [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // Now modify vendored crate. p.change_file( @@ -2855,13 +3036,12 @@ fn verify_source_before_recompile() { ); // Should ignore modified sources without any recompile. p.cargo("check --verbose") - .with_stderr( - "\ + .with_stderr_data(str![[r#" [FRESH] bar v0.1.0 -[FRESH] foo v0.1.0 ([CWD]) -[FINISHED] `dev` profile [..] -", - ) +[FRESH] foo v0.1.0 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // Add a `RUSTFLAGS` to trigger a recompile. @@ -2871,15 +3051,14 @@ fn verify_source_before_recompile() { p.cargo("check --verbose") .env("RUSTFLAGS", "-W warnings") .with_status(101) - .with_stderr( - "\ -error: the listed checksum of `[CWD]/vendor/bar/src/lib.rs` has changed: -expected: [..] -actual: [..] + .with_stderr_data(str![[r#" +[ERROR] the listed checksum of `[ROOT]/foo/vendor/bar/src/lib.rs` has changed: +expected: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 +actual: 66e843918c1d4ea8231af814f9f958958808249d4407de01114acb730ecd9bdf -directory sources are not [..] -", - ) +directory sources are not intended to be edited, if modifications are required then it is recommended that `[patch]` is used with a forked copy of the source + +"#]]) .run(); } @@ -2894,21 +3073,21 @@ fn skip_mtime_check_in_selected_cargo_home_subdirs() { let cargo_home = project_root.parent().unwrap().parent().unwrap(); p.cargo("check -v") .env("CARGO_HOME", &cargo_home) - .with_stderr( - "\ -[CHECKING] foo v0.5.0 ([CWD]) -[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..] -[FINISHED] `dev` profile [..]", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.5.0 ([ROOT]/cargo_home/registry/foo) +[RUNNING] `rustc --crate-name foo [..] src/lib.rs [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.change_file("src/lib.rs", "illegal syntax"); p.cargo("check -v") .env("CARGO_HOME", &cargo_home) - .with_stderr( - "\ -[FRESH] foo v0.5.0 ([CWD]) -[FINISHED] `dev` profile [..]", - ) + .with_stderr_data(str![[r#" +[FRESH] foo v0.5.0 ([ROOT]/cargo_home/registry/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -2923,22 +3102,24 @@ fn use_mtime_cache_in_cargo_home() { let cargo_home = project_root.parent().unwrap(); p.cargo("check -v") .env("CARGO_HOME", &cargo_home) - .with_stderr( - "\ -[CHECKING] foo v0.5.0 ([CWD]) -[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..] -[FINISHED] `dev` profile [..]", - ) + .with_stderr_data(str![[r#" +[CHECKING] foo v0.5.0 ([ROOT]/cargo_home/foo) +[RUNNING] `rustc --crate-name foo [..] src/lib.rs [..] src/lib.rs [..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); p.change_file("src/lib.rs", "illegal syntax"); p.cargo("check -v") .env("CARGO_HOME", &cargo_home) .with_status(101) - .with_stderr_contains( - "\ -[DIRTY] foo v0.5.0 ([CWD]): [..] -[CHECKING] foo v0.5.0 ([CWD]) -[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]", - ) + .with_stderr_data(str![[r#" +[DIRTY] foo v0.5.0 ([ROOT]/cargo_home/foo): the file `src/lib.rs` has changed ([DIRTY_REASON_NEW_TIME], [DIRTY_REASON_DIFF] after last build at [DIRTY_REASON_OLD_TIME]) +[CHECKING] foo v0.5.0 ([ROOT]/cargo_home/foo) +[RUNNING] `rustc --crate-name foo [..] src/lib.rs [..] +... +[ERROR] could not compile `foo` (lib) due to 1 previous error +... +"#]]) .run(); }