1
1
//! Tests for `[env]` config.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use cargo_test_support:: basic_manifest;
4
+ use cargo_test_support:: str;
6
5
use cargo_test_support:: { basic_bin_manifest, project} ;
7
6
8
7
#[ cargo_test]
@@ -29,8 +28,11 @@ fn env_basic() {
29
28
. build ( ) ;
30
29
31
30
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
+ "# ] ] )
34
36
. run ( ) ;
35
37
}
36
38
@@ -56,7 +58,16 @@ fn env_invalid() {
56
58
57
59
p. cargo ( "check" )
58
60
. 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
+ "# ] ] )
60
71
. run ( ) ;
61
72
}
62
73
@@ -80,9 +91,11 @@ fn env_no_disallowed() {
80
91
) ;
81
92
p. cargo ( "check" )
82
93
. 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
+ "
86
99
) )
87
100
. run ( ) ;
88
101
}
@@ -118,9 +131,12 @@ fn env_force() {
118
131
. env ( "ENV_TEST_FORCED" , "from-env" )
119
132
. env ( "ENV_TEST_UNFORCED" , "from-env" )
120
133
. 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
+ "# ] ] )
124
140
. run ( ) ;
125
141
}
126
142
@@ -181,7 +197,10 @@ fn env_no_override() {
181
197
. build ( ) ;
182
198
183
199
p. cargo ( "run" )
184
- . with_stdout_contains ( "CARGO_PKG_NAME:unchanged" )
200
+ . with_stdout_data ( str![ [ r#"
201
+ CARGO_PKG_NAME:unchanged
202
+
203
+ "# ] ] )
185
204
. run ( ) ;
186
205
}
187
206
@@ -231,16 +250,28 @@ fn env_applied_to_target_info_discovery_rustc() {
231
250
232
251
p. cargo ( "run" )
233
252
. 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
+ "# ] ] )
236
261
. run ( ) ;
237
262
238
263
// Ensure wrapper also maintains the same overridden priority for envs.
239
264
p. cargo ( "clean" ) . run ( ) ;
240
265
p. cargo ( "run" )
241
266
. env ( "ENV_TEST" , "from-env" )
242
267
. 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
+ "# ] ] )
245
276
. run ( ) ;
246
277
}
0 commit comments