Skip to content

Commit c13a394

Browse files
committed
Auto merge of #14044 - heisen-li:build_script_env, r=epage
test: migrate build_script_env to snapbox ### What does this PR try to resolve? part of #14039.
2 parents 30e5580 + 2d10bd5 commit c13a394

File tree

1 file changed

+125
-68
lines changed

1 file changed

+125
-68
lines changed

tests/testsuite/build_script_env.rs

Lines changed: 125 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Tests for build.rs rerun-if-env-changed and rustc-env
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::basic_manifest;
64
use cargo_test_support::project;
75
use cargo_test_support::sleep_ms;
6+
use cargo_test_support::str;
87

98
#[cargo_test]
109
fn rerun_if_env_changes() {
@@ -21,42 +20,42 @@ fn rerun_if_env_changes() {
2120
.build();
2221

2322
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+
"#]])
3028
.run();
3129
p.cargo("check")
3230
.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+
"#]])
3936
.run();
4037
p.cargo("check")
4138
.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+
"#]])
4844
.run();
4945
p.cargo("check")
5046
.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+
"#]])
5251
.run();
52+
5353
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+
"#]])
6059
.run();
6160
}
6261

@@ -77,36 +76,36 @@ fn rerun_if_env_or_file_changes() {
7776
.build();
7877

7978
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+
"#]])
8684
.run();
8785
p.cargo("check")
8886
.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+
"#]])
9592
.run();
9693
p.cargo("check")
9794
.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+
"#]])
9999
.run();
100100
sleep_ms(1000);
101101
p.change_file("foo", "// modified");
102102
p.cargo("check")
103103
.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+
"#]])
110109
.run();
111110
}
112111

@@ -127,10 +126,13 @@ fn rustc_bootstrap() {
127126
.build();
128127
// RUSTC_BOOTSTRAP unset on stable should error
129128
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+
"#]])
134136
.with_status(101)
135137
.run();
136138
// nightly should warn whether or not RUSTC_BOOTSTRAP is set
@@ -139,20 +141,33 @@ fn rustc_bootstrap() {
139141
// NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc
140142
// (this matters when tests are being run with a beta or stable cargo)
141143
.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+
"#]])
143151
.run();
144152
// RUSTC_BOOTSTRAP set to the name of the library should warn
145153
p.cargo("check")
146154
.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+
"#]])
148161
.run();
149162
// RUSTC_BOOTSTRAP set to some random value should error
150163
p.cargo("check")
151164
.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+
"#]])
156171
.with_status(101)
157172
.run();
158173

@@ -171,13 +186,23 @@ fn rustc_bootstrap() {
171186
// NOTE: uses RUSTC_BOOTSTRAP so it will be propagated to rustc
172187
// (this matters when tests are being run with a beta or stable cargo)
173188
.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+
"#]])
175196
.run();
176197
// RUSTC_BOOTSTRAP conditionally set when there's no library should error (regardless of the value)
177198
p.cargo("check")
178199
.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+
"#]])
181206
.with_status(101)
182207
.run();
183208
}
@@ -194,7 +219,12 @@ fn build_script_env_verbose() {
194219
.build();
195220

196221
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+
)
198228
.run();
199229
}
200230

@@ -227,8 +257,14 @@ fn build_script_sees_cfg_target_feature() {
227257
.build();
228258

229259
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+
)
232268
.run();
233269
}
234270
}
@@ -258,9 +294,15 @@ fn cfg_paradox() {
258294
.build();
259295

260296
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+
)
264306
.run();
265307
}
266308

@@ -318,10 +360,25 @@ fn rustc_cfg_with_and_without_value() {
318360

319361
let mut check = p.cargo("check -vv");
320362
#[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+
);
322369
#[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+
);
324376
#[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+
);
326383
check.run();
327384
}

0 commit comments

Comments
 (0)