diff --git a/tests/testsuite/build_script_env.rs b/tests/testsuite/build_script_env.rs index c22082137d2e..ba196305cbc0 100644 --- a/tests/testsuite/build_script_env.rs +++ b/tests/testsuite/build_script_env.rs @@ -1,10 +1,9 @@ //! Tests for build.rs rerun-if-env-changed and rustc-env -#![allow(deprecated)] - use cargo_test_support::basic_manifest; use cargo_test_support::project; use cargo_test_support::sleep_ms; +use cargo_test_support::str; #[cargo_test] fn rerun_if_env_changes() { @@ -21,42 +20,42 @@ fn rerun_if_env_changes() { .build(); p.cargo("check") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] [..] -", - ) + .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("check") .env("FOO", "bar") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] [..] -", - ) + .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("check") .env("FOO", "baz") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] [..] -", - ) + .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("check") .env("FOO", "baz") - .with_stderr("[FINISHED] [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); + p.cargo("check") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] [..] -", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -77,36 +76,36 @@ fn rerun_if_env_or_file_changes() { .build(); p.cargo("check") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] [..] -", - ) + .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("check") .env("FOO", "bar") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] [..] -", - ) + .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("check") .env("FOO", "bar") - .with_stderr("[FINISHED] [..]") + .with_stderr_data(str![[r#" +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); sleep_ms(1000); p.change_file("foo", "// modified"); p.cargo("check") .env("FOO", "bar") - .with_stderr( - "\ -[COMPILING] foo v0.0.1 ([..]) -[FINISHED] [..] -", - ) + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); } @@ -127,10 +126,13 @@ fn rustc_bootstrap() { .build(); // RUSTC_BOOTSTRAP unset on stable should error p.cargo("check") - .with_stderr_contains("error: Cannot set `RUSTC_BOOTSTRAP=1` [..]") - .with_stderr_contains( - "help: [..] set the environment variable `RUSTC_BOOTSTRAP=has_dashes` [..]", - ) + .with_stderr_data(str![[r#" +[COMPILING] has-dashes v0.0.1 ([ROOT]/foo) +[ERROR] Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`. +[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project. +[HELP] If you're sure you want to do this in your project, set the environment variable `RUSTC_BOOTSTRAP=has_dashes` before running cargo instead. + +"#]]) .with_status(101) .run(); // nightly should warn whether or not RUSTC_BOOTSTRAP is set @@ -139,20 +141,33 @@ fn rustc_bootstrap() { // NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc // (this matters when tests are being run with a beta or stable cargo) .env("RUSTC_BOOTSTRAP", "1") - .with_stderr_contains("warning: has-dashes@0.0.1: Cannot set `RUSTC_BOOTSTRAP=1` [..]") + .with_stderr_data(str![[r#" +[COMPILING] has-dashes v0.0.1 ([ROOT]/foo) +[WARNING] has-dashes@0.0.1: Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`. +[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project. +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // RUSTC_BOOTSTRAP set to the name of the library should warn p.cargo("check") .env("RUSTC_BOOTSTRAP", "has_dashes") - .with_stderr_contains("warning: has-dashes@0.0.1: Cannot set `RUSTC_BOOTSTRAP=1` [..]") + .with_stderr_data(str![[r#" +[WARNING] has-dashes@0.0.1: Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`. +[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project. +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // RUSTC_BOOTSTRAP set to some random value should error p.cargo("check") .env("RUSTC_BOOTSTRAP", "bar") - .with_stderr_contains("error: Cannot set `RUSTC_BOOTSTRAP=1` [..]") - .with_stderr_contains( - "help: [..] set the environment variable `RUSTC_BOOTSTRAP=has_dashes` [..]", - ) + .with_stderr_data(str![[r#" +[ERROR] Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`. +[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project. +[HELP] If you're sure you want to do this in your project, set the environment variable `RUSTC_BOOTSTRAP=has_dashes` before running cargo instead. + +"#]]) .with_status(101) .run(); @@ -171,17 +186,28 @@ fn rustc_bootstrap() { // NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc // (this matters when tests are being run with a beta or stable cargo) .env("RUSTC_BOOTSTRAP", "1") - .with_stderr_contains("warning: foo@0.0.1: Cannot set `RUSTC_BOOTSTRAP=1` [..]") + .with_stderr_data(str![[r#" +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[WARNING] foo@0.0.1: Cannot set `RUSTC_BOOTSTRAP=1` from build script of `foo v0.0.1 ([ROOT]/foo)`. +[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project. +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) .run(); // RUSTC_BOOTSTRAP conditionally set when there's no library should error (regardless of the value) p.cargo("check") .env("RUSTC_BOOTSTRAP", "foo") - .with_stderr_contains("error: Cannot set `RUSTC_BOOTSTRAP=1` [..]") - .with_stderr_contains("help: [..] set the environment variable `RUSTC_BOOTSTRAP=1` [..]") + .with_stderr_data(str![[r#" +[ERROR] Cannot set `RUSTC_BOOTSTRAP=1` from build script of `foo v0.0.1 ([ROOT]/foo)`. +[NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project. +[HELP] If you're sure you want to do this in your project, set the environment variable `RUSTC_BOOTSTRAP=1` before running cargo instead. + +"#]]) .with_status(101) .run(); } +#[allow(deprecated)] #[cargo_test] fn build_script_env_verbose() { let build_rs = r#" @@ -198,6 +224,7 @@ fn build_script_env_verbose() { .run(); } +#[allow(deprecated)] #[cargo_test] #[cfg(target_arch = "x86_64")] fn build_script_sees_cfg_target_feature() { @@ -237,6 +264,7 @@ fn build_script_sees_cfg_target_feature() { /// what the value of `RUSTFLAGS` should be in this case. We chose to give a /// warning. However, no matter what we do, it's important that build scripts /// and rustc see a consistent picture +#[allow(deprecated)] #[cargo_test] fn cfg_paradox() { let build_rs = r#" @@ -298,6 +326,7 @@ fn cfg_paradox() { /// ``` /// CARGO_CFG_TARGET_THREAD_LOCAL= /// ``` +#[allow(deprecated)] #[cargo_test(nightly, reason = "affected rustc cfg is unstable")] #[cfg(target_arch = "x86_64")] fn rustc_cfg_with_and_without_value() {