1
1
//! Tests for build.rs rerun-if-env-changed and rustc-env
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use cargo_test_support:: basic_manifest;
6
4
use cargo_test_support:: project;
7
5
use cargo_test_support:: sleep_ms;
6
+ use cargo_test_support:: str;
8
7
9
8
#[ cargo_test]
10
9
fn rerun_if_env_changes ( ) {
@@ -21,42 +20,42 @@ fn rerun_if_env_changes() {
21
20
. build ( ) ;
22
21
23
22
p. cargo ( "check" )
24
- . with_stderr (
25
- "\
26
- [COMPILING] foo v0.0.1 ([..])
27
- [FINISHED] [..]
28
- " ,
29
- )
23
+ . with_stderr_data ( str![ [ r#"
24
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
25
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
26
+
27
+ "# ] ] )
30
28
. run ( ) ;
31
29
p. cargo ( "check" )
32
30
. env ( "FOO" , "bar" )
33
- . with_stderr (
34
- "\
35
- [COMPILING] foo v0.0.1 ([..])
36
- [FINISHED] [..]
37
- " ,
38
- )
31
+ . with_stderr_data ( str![ [ r#"
32
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
33
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
34
+
35
+ "# ] ] )
39
36
. run ( ) ;
40
37
p. cargo ( "check" )
41
38
. env ( "FOO" , "baz" )
42
- . with_stderr (
43
- "\
44
- [COMPILING] foo v0.0.1 ([..])
45
- [FINISHED] [..]
46
- " ,
47
- )
39
+ . with_stderr_data ( str![ [ r#"
40
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
41
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
42
+
43
+ "# ] ] )
48
44
. run ( ) ;
49
45
p. cargo ( "check" )
50
46
. env ( "FOO" , "baz" )
51
- . with_stderr ( "[FINISHED] [..]" )
47
+ . with_stderr_data ( str![ [ r#"
48
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
49
+
50
+ "# ] ] )
52
51
. run ( ) ;
52
+
53
53
p. cargo ( "check" )
54
- . with_stderr (
55
- "\
56
- [COMPILING] foo v0.0.1 ([..])
57
- [FINISHED] [..]
58
- " ,
59
- )
54
+ . with_stderr_data ( str![ [ r#"
55
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
56
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
57
+
58
+ "# ] ] )
60
59
. run ( ) ;
61
60
}
62
61
@@ -77,36 +76,36 @@ fn rerun_if_env_or_file_changes() {
77
76
. build ( ) ;
78
77
79
78
p. cargo ( "check" )
80
- . with_stderr (
81
- "\
82
- [COMPILING] foo v0.0.1 ([..])
83
- [FINISHED] [..]
84
- " ,
85
- )
79
+ . with_stderr_data ( str![ [ r#"
80
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
81
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
82
+
83
+ "# ] ] )
86
84
. run ( ) ;
87
85
p. cargo ( "check" )
88
86
. env ( "FOO" , "bar" )
89
- . with_stderr (
90
- "\
91
- [COMPILING] foo v0.0.1 ([..])
92
- [FINISHED] [..]
93
- " ,
94
- )
87
+ . with_stderr_data ( str![ [ r#"
88
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
89
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
90
+
91
+ "# ] ] )
95
92
. run ( ) ;
96
93
p. cargo ( "check" )
97
94
. env ( "FOO" , "bar" )
98
- . with_stderr ( "[FINISHED] [..]" )
95
+ . with_stderr_data ( str![ [ r#"
96
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
97
+
98
+ "# ] ] )
99
99
. run ( ) ;
100
100
sleep_ms ( 1000 ) ;
101
101
p. change_file ( "foo" , "// modified" ) ;
102
102
p. cargo ( "check" )
103
103
. env ( "FOO" , "bar" )
104
- . with_stderr (
105
- "\
106
- [COMPILING] foo v0.0.1 ([..])
107
- [FINISHED] [..]
108
- " ,
109
- )
104
+ . with_stderr_data ( str![ [ r#"
105
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
106
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
107
+
108
+ "# ] ] )
110
109
. run ( ) ;
111
110
}
112
111
@@ -127,10 +126,13 @@ fn rustc_bootstrap() {
127
126
. build ( ) ;
128
127
// RUSTC_BOOTSTRAP unset on stable should error
129
128
p. cargo ( "check" )
130
- . with_stderr_contains ( "error: Cannot set `RUSTC_BOOTSTRAP=1` [..]" )
131
- . with_stderr_contains (
132
- "help: [..] set the environment variable `RUSTC_BOOTSTRAP=has_dashes` [..]" ,
133
- )
129
+ . with_stderr_data ( str![ [ r#"
130
+ [COMPILING] has-dashes v0.0.1 ([ROOT]/foo)
131
+ [ERROR] Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`.
132
+ [NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
133
+ [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.
134
+
135
+ "# ] ] )
134
136
. with_status ( 101 )
135
137
. run ( ) ;
136
138
// nightly should warn whether or not RUSTC_BOOTSTRAP is set
@@ -139,20 +141,33 @@ fn rustc_bootstrap() {
139
141
// NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc
140
142
// (this matters when tests are being run with a beta or stable cargo)
141
143
. env ( "RUSTC_BOOTSTRAP" , "1" )
142
- . with_stderr_contains ( "warning: [email protected] : Cannot set `RUSTC_BOOTSTRAP=1` [..]" )
144
+ . with_stderr_data ( str![ [ r#"
145
+ [COMPILING] has-dashes v0.0.1 ([ROOT]/foo)
146
+ [WARNING] [email protected] : Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`.
147
+ [NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
148
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
149
+
150
+ "# ] ] )
143
151
. run ( ) ;
144
152
// RUSTC_BOOTSTRAP set to the name of the library should warn
145
153
p. cargo ( "check" )
146
154
. env ( "RUSTC_BOOTSTRAP" , "has_dashes" )
147
- . with_stderr_contains ( "warning: [email protected] : Cannot set `RUSTC_BOOTSTRAP=1` [..]" )
155
+ . with_stderr_data ( str![ [ r#"
156
+ [WARNING] [email protected] : Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`.
157
+ [NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
158
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
159
+
160
+ "# ] ] )
148
161
. run ( ) ;
149
162
// RUSTC_BOOTSTRAP set to some random value should error
150
163
p. cargo ( "check" )
151
164
. env ( "RUSTC_BOOTSTRAP" , "bar" )
152
- . with_stderr_contains ( "error: Cannot set `RUSTC_BOOTSTRAP=1` [..]" )
153
- . with_stderr_contains (
154
- "help: [..] set the environment variable `RUSTC_BOOTSTRAP=has_dashes` [..]" ,
155
- )
165
+ . with_stderr_data ( str![ [ r#"
166
+ [ERROR] Cannot set `RUSTC_BOOTSTRAP=1` from build script of `has-dashes v0.0.1 ([ROOT]/foo)`.
167
+ [NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
168
+ [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.
169
+
170
+ "# ] ] )
156
171
. with_status ( 101 )
157
172
. run ( ) ;
158
173
@@ -171,13 +186,23 @@ fn rustc_bootstrap() {
171
186
// NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc
172
187
// (this matters when tests are being run with a beta or stable cargo)
173
188
. env ( "RUSTC_BOOTSTRAP" , "1" )
174
- . with_stderr_contains ( "warning: [email protected] : Cannot set `RUSTC_BOOTSTRAP=1` [..]" )
189
+ . with_stderr_data ( str![ [ r#"
190
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
191
+ [WARNING] [email protected] : Cannot set `RUSTC_BOOTSTRAP=1` from build script of `foo v0.0.1 ([ROOT]/foo)`.
192
+ [NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
193
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
194
+
195
+ "# ] ] )
175
196
. run ( ) ;
176
197
// RUSTC_BOOTSTRAP conditionally set when there's no library should error (regardless of the value)
177
198
p. cargo ( "check" )
178
199
. env ( "RUSTC_BOOTSTRAP" , "foo" )
179
- . with_stderr_contains ( "error: Cannot set `RUSTC_BOOTSTRAP=1` [..]" )
180
- . with_stderr_contains ( "help: [..] set the environment variable `RUSTC_BOOTSTRAP=1` [..]" )
200
+ . with_stderr_data ( str![ [ r#"
201
+ [ERROR] Cannot set `RUSTC_BOOTSTRAP=1` from build script of `foo v0.0.1 ([ROOT]/foo)`.
202
+ [NOTE] Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.
203
+ [HELP] If you're sure you want to do this in your project, set the environment variable `RUSTC_BOOTSTRAP=1` before running cargo instead.
204
+
205
+ "# ] ] )
181
206
. with_status ( 101 )
182
207
. run ( ) ;
183
208
}
@@ -194,7 +219,12 @@ fn build_script_env_verbose() {
194
219
. build ( ) ;
195
220
196
221
p. cargo ( "check -vv" )
197
- . with_stderr_contains ( "[RUNNING] `[..]CARGO=[..]build-script-build`" )
222
+ . with_stderr_data (
223
+ "\
224
+ ...
225
+ [RUNNING] `[..]CARGO=[..]build-script-build`
226
+ ..." ,
227
+ )
198
228
. run ( ) ;
199
229
}
200
230
@@ -227,8 +257,14 @@ fn build_script_sees_cfg_target_feature() {
227
257
. build ( ) ;
228
258
229
259
p. cargo ( "check -vv" )
230
- . with_stderr_contains ( "[foo 0.0.1] CARGO_CFG_TARGET_FEATURE=[..]sse4.2[..]" )
231
- . with_stderr_contains ( "[..]-Ctarget-feature=[..]+sse4.2[..]" )
260
+ . with_stderr_data (
261
+ "\
262
+ ...
263
+ [foo 0.0.1] CARGO_CFG_TARGET_FEATURE=[..]sse4.2[..]
264
+ ...
265
+ [..]-Ctarget-feature=[..]+sse4.2[..]
266
+ ..." ,
267
+ )
232
268
. run ( ) ;
233
269
}
234
270
}
@@ -258,9 +294,15 @@ fn cfg_paradox() {
258
294
. build ( ) ;
259
295
260
296
p. cargo ( "check -vv" )
261
- . with_stderr_contains ( "[WARNING] non-trivial mutual dependency between target-specific configuration and RUSTFLAGS" )
262
- . with_stderr_contains ( "[foo 0.0.1] cfg!(bertrand)=true" )
263
- . with_stderr_contains ( "[..]--cfg=bertrand[..]" )
297
+ . with_stderr_data (
298
+ "\
299
+ [WARNING] non-trivial mutual dependency between target-specific configuration and RUSTFLAGS
300
+ ...
301
+ [foo 0.0.1] cfg!(bertrand)=true
302
+ ...
303
+ [..]--cfg=bertrand[..]
304
+ ..." ,
305
+ )
264
306
. run ( ) ;
265
307
}
266
308
@@ -318,10 +360,25 @@ fn rustc_cfg_with_and_without_value() {
318
360
319
361
let mut check = p. cargo ( "check -vv" ) ;
320
362
#[ cfg( target_has_atomic = "64" ) ]
321
- check. with_stderr_contains ( "[foo 0.0.1] CARGO_CFG_TARGET_HAS_ATOMIC=Ok(\" [..]64[..]\" )" ) ;
363
+ check. with_stderr_data (
364
+ "\
365
+ ...
366
+ [foo 0.0.1] CARGO_CFG_TARGET_HAS_ATOMIC=Ok(\" [..]64[..]\" )
367
+ ..." ,
368
+ ) ;
322
369
#[ cfg( windows) ]
323
- check. with_stderr_contains ( "[foo 0.0.1] CARGO_CFG_WINDOWS=Ok(\" \" )" ) ;
370
+ check. with_stderr_data (
371
+ "\
372
+ ...
373
+ [foo 0.0.1] CARGO_CFG_WINDOWS=Ok(\" \" )
374
+ ..." ,
375
+ ) ;
324
376
#[ cfg( unix) ]
325
- check. with_stderr_contains ( "[foo 0.0.1] CARGO_CFG_UNIX=Ok(\" \" )" ) ;
377
+ check. with_stderr_data (
378
+ "\
379
+ ...
380
+ [foo 0.0.1] CARGO_CFG_UNIX=Ok(\" \" )
381
+ ..." ,
382
+ ) ;
326
383
check. run ( ) ;
327
384
}
0 commit comments