Skip to content

Commit

Permalink
test: migrate cargo_env_config to snapbox
Browse files Browse the repository at this point in the history
  • Loading branch information
heisen-li committed Jun 21, 2024
1 parent 2068175 commit f90dfec
Showing 1 changed file with 47 additions and 16 deletions.
63 changes: 47 additions & 16 deletions tests/testsuite/cargo_env_config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Tests for `[env]` config.

#![allow(deprecated)]

use cargo_test_support::basic_manifest;
use cargo_test_support::str;
use cargo_test_support::{basic_bin_manifest, project};

#[cargo_test]
Expand All @@ -29,8 +28,11 @@ fn env_basic() {
.build();

p.cargo("run")
.with_stdout_contains("compile-time:Hello")
.with_stdout_contains("run-time:Hello")
.with_stdout_data(str![[r#"
compile-time:Hello
run-time:Hello
"#]])
.run();
}

Expand All @@ -56,7 +58,16 @@ fn env_invalid() {

p.cargo("check")
.with_status(101)
.with_stderr_contains("[..]could not load config key `env.ENV_TEST_BOOL`")
.with_stderr_data(str![[r#"
[ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `env.ENV_TEST_BOOL`
Caused by:
error in [ROOT]/foo/.cargo/config.toml: could not load config key `env.ENV_TEST_BOOL`
Caused by:
invalid type: boolean `false`, expected a string or map
"#]])
.run();
}

Expand All @@ -80,9 +91,11 @@ fn env_no_disallowed() {
);
p.cargo("check")
.with_status(101)
.with_stderr(&format!(
"[ERROR] setting the `{disallowed}` environment variable \
is not supported in the `[env]` configuration table"
.with_stderr_data(format!(
"\
[ERROR] setting the `{disallowed}` environment variable \
is not supported in the `[env]` configuration table
"
))
.run();
}
Expand Down Expand Up @@ -118,9 +131,12 @@ fn env_force() {
.env("ENV_TEST_FORCED", "from-env")
.env("ENV_TEST_UNFORCED", "from-env")
.env("ENV_TEST_UNFORCED_DEFAULT", "from-env")
.with_stdout_contains("ENV_TEST_FORCED:from-config")
.with_stdout_contains("ENV_TEST_UNFORCED:from-env")
.with_stdout_contains("ENV_TEST_UNFORCED_DEFAULT:from-env")
.with_stdout_data(str![[r#"
ENV_TEST_FORCED:from-config
ENV_TEST_UNFORCED:from-env
ENV_TEST_UNFORCED_DEFAULT:from-env
"#]])
.run();
}

Expand Down Expand Up @@ -181,7 +197,10 @@ fn env_no_override() {
.build();

p.cargo("run")
.with_stdout_contains("CARGO_PKG_NAME:unchanged")
.with_stdout_data(str![[r#"
CARGO_PKG_NAME:unchanged
"#]])
.run();
}

Expand Down Expand Up @@ -231,16 +250,28 @@ fn env_applied_to_target_info_discovery_rustc() {

p.cargo("run")
.env("RUSTC_WORKSPACE_WRAPPER", wrapper)
.with_stderr_contains("WRAPPER ENV_TEST:from-config")
.with_stderr_contains("MAIN ENV_TEST:from-config")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.5.0 ([ROOT]/foo)
WRAPPER ENV_TEST:from-config
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo[EXE]`
MAIN ENV_TEST:from-config
"#]])
.run();

// Ensure wrapper also maintains the same overridden priority for envs.
p.cargo("clean").run();
p.cargo("run")
.env("ENV_TEST", "from-env")
.env("RUSTC_WORKSPACE_WRAPPER", wrapper)
.with_stderr_contains("WRAPPER ENV_TEST:from-env")
.with_stderr_contains("MAIN ENV_TEST:from-env")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.5.0 ([ROOT]/foo)
WRAPPER ENV_TEST:from-env
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo[EXE]`
MAIN ENV_TEST:from-env
"#]])
.run();
}

0 comments on commit f90dfec

Please sign in to comment.