Skip to content

Commit f25cdf1

Browse files
committed
test: migrate cargo_env_config to snapbox
1 parent 86d9299 commit f25cdf1

File tree

1 file changed

+47
-16
lines changed

1 file changed

+47
-16
lines changed

tests/testsuite/cargo_env_config.rs

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Tests for `[env]` config.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::basic_manifest;
4+
use cargo_test_support::str;
65
use cargo_test_support::{basic_bin_manifest, project};
76

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

3130
p.cargo("run")
32-
.with_stdout_contains("compile-time:Hello")
33-
.with_stdout_contains("run-time:Hello")
31+
.with_stdout_data(str![[r#"
32+
compile-time:Hello
33+
run-time:Hello
34+
35+
"#]])
3436
.run();
3537
}
3638

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

5759
p.cargo("check")
5860
.with_status(101)
59-
.with_stderr_contains("[..]could not load config key `env.ENV_TEST_BOOL`")
61+
.with_stderr_data(str![[r#"
62+
[ERROR] error in [ROOT]/foo/.cargo/config.toml: could not load config key `env.ENV_TEST_BOOL`
63+
64+
Caused by:
65+
error in [ROOT]/foo/.cargo/config.toml: could not load config key `env.ENV_TEST_BOOL`
66+
67+
Caused by:
68+
invalid type: boolean `false`, expected a string or map
69+
70+
"#]])
6071
.run();
6172
}
6273

@@ -80,9 +91,11 @@ fn env_no_disallowed() {
8091
);
8192
p.cargo("check")
8293
.with_status(101)
83-
.with_stderr(&format!(
84-
"[ERROR] setting the `{disallowed}` environment variable \
85-
is not supported in the `[env]` configuration table"
94+
.with_stderr_data(format!(
95+
"\
96+
[ERROR] setting the `{disallowed}` environment variable \
97+
is not supported in the `[env]` configuration table
98+
"
8699
))
87100
.run();
88101
}
@@ -118,9 +131,12 @@ fn env_force() {
118131
.env("ENV_TEST_FORCED", "from-env")
119132
.env("ENV_TEST_UNFORCED", "from-env")
120133
.env("ENV_TEST_UNFORCED_DEFAULT", "from-env")
121-
.with_stdout_contains("ENV_TEST_FORCED:from-config")
122-
.with_stdout_contains("ENV_TEST_UNFORCED:from-env")
123-
.with_stdout_contains("ENV_TEST_UNFORCED_DEFAULT:from-env")
134+
.with_stdout_data(str![[r#"
135+
ENV_TEST_FORCED:from-config
136+
ENV_TEST_UNFORCED:from-env
137+
ENV_TEST_UNFORCED_DEFAULT:from-env
138+
139+
"#]])
124140
.run();
125141
}
126142

@@ -181,7 +197,10 @@ fn env_no_override() {
181197
.build();
182198

183199
p.cargo("run")
184-
.with_stdout_contains("CARGO_PKG_NAME:unchanged")
200+
.with_stdout_data(str![[r#"
201+
CARGO_PKG_NAME:unchanged
202+
203+
"#]])
185204
.run();
186205
}
187206

@@ -231,16 +250,28 @@ fn env_applied_to_target_info_discovery_rustc() {
231250

232251
p.cargo("run")
233252
.env("RUSTC_WORKSPACE_WRAPPER", wrapper)
234-
.with_stderr_contains("WRAPPER ENV_TEST:from-config")
235-
.with_stderr_contains("MAIN ENV_TEST:from-config")
253+
.with_stderr_data(str![[r#"
254+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
255+
WRAPPER ENV_TEST:from-config
256+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
257+
[RUNNING] `target/debug/foo[EXE]`
258+
MAIN ENV_TEST:from-config
259+
260+
"#]])
236261
.run();
237262

238263
// Ensure wrapper also maintains the same overridden priority for envs.
239264
p.cargo("clean").run();
240265
p.cargo("run")
241266
.env("ENV_TEST", "from-env")
242267
.env("RUSTC_WORKSPACE_WRAPPER", wrapper)
243-
.with_stderr_contains("WRAPPER ENV_TEST:from-env")
244-
.with_stderr_contains("MAIN ENV_TEST:from-env")
268+
.with_stderr_data(str![[r#"
269+
[COMPILING] foo v0.5.0 ([ROOT]/foo)
270+
WRAPPER ENV_TEST:from-env
271+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
272+
[RUNNING] `target/debug/foo[EXE]`
273+
MAIN ENV_TEST:from-env
274+
275+
"#]])
245276
.run();
246277
}

0 commit comments

Comments
 (0)