]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/builder/tests.rs
Rollup merge of #68050 - Centril:canon-error, r=Mark-Simulacrum
[rust.git] / src / bootstrap / builder / tests.rs
1 use super::*;
2 use crate::config::Config;
3 use std::thread;
4
5 use pretty_assertions::assert_eq;
6
7 fn configure(host: &[&str], target: &[&str]) -> Config {
8     let mut config = Config::default_opts();
9     // don't save toolstates
10     config.save_toolstates = None;
11     config.skip_only_host_steps = false;
12     config.dry_run = true;
13     // try to avoid spurious failures in dist where we create/delete each others file
14     let dir = config
15         .out
16         .join("tmp-rustbuild-tests")
17         .join(&thread::current().name().unwrap_or("unknown").replace(":", "-"));
18     t!(fs::create_dir_all(&dir));
19     config.out = dir;
20     config.build = INTERNER.intern_str("A");
21     config.hosts = vec![config.build]
22         .clone()
23         .into_iter()
24         .chain(host.iter().map(|s| INTERNER.intern_str(s)))
25         .collect::<Vec<_>>();
26     config.targets = config
27         .hosts
28         .clone()
29         .into_iter()
30         .chain(target.iter().map(|s| INTERNER.intern_str(s)))
31         .collect::<Vec<_>>();
32     config
33 }
34
35 fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
36     v.into_iter().map(|(a, _)| a).collect::<Vec<_>>()
37 }
38
39 #[test]
40 fn dist_baseline() {
41     let build = Build::new(configure(&[], &[]));
42     let mut builder = Builder::new(&build);
43     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
44
45     let a = INTERNER.intern_str("A");
46
47     assert_eq!(first(builder.cache.all::<dist::Docs>()), &[dist::Docs { host: a },]);
48     assert_eq!(first(builder.cache.all::<dist::Mingw>()), &[dist::Mingw { host: a },]);
49     assert_eq!(
50         first(builder.cache.all::<dist::Rustc>()),
51         &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },]
52     );
53     assert_eq!(
54         first(builder.cache.all::<dist::Std>()),
55         &[dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },]
56     );
57     assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
58 }
59
60 #[test]
61 fn dist_with_targets() {
62     let build = Build::new(configure(&[], &["B"]));
63     let mut builder = Builder::new(&build);
64     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
65
66     let a = INTERNER.intern_str("A");
67     let b = INTERNER.intern_str("B");
68
69     assert_eq!(
70         first(builder.cache.all::<dist::Docs>()),
71         &[dist::Docs { host: a }, dist::Docs { host: b },]
72     );
73     assert_eq!(
74         first(builder.cache.all::<dist::Mingw>()),
75         &[dist::Mingw { host: a }, dist::Mingw { host: b },]
76     );
77     assert_eq!(
78         first(builder.cache.all::<dist::Rustc>()),
79         &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },]
80     );
81     assert_eq!(
82         first(builder.cache.all::<dist::Std>()),
83         &[
84             dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
85             dist::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
86         ]
87     );
88     assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
89 }
90
91 #[test]
92 fn dist_with_hosts() {
93     let build = Build::new(configure(&["B"], &[]));
94     let mut builder = Builder::new(&build);
95     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
96
97     let a = INTERNER.intern_str("A");
98     let b = INTERNER.intern_str("B");
99
100     assert_eq!(
101         first(builder.cache.all::<dist::Docs>()),
102         &[dist::Docs { host: a }, dist::Docs { host: b },]
103     );
104     assert_eq!(
105         first(builder.cache.all::<dist::Mingw>()),
106         &[dist::Mingw { host: a }, dist::Mingw { host: b },]
107     );
108     assert_eq!(
109         first(builder.cache.all::<dist::Rustc>()),
110         &[
111             dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
112             dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
113         ]
114     );
115     assert_eq!(
116         first(builder.cache.all::<dist::Std>()),
117         &[
118             dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
119             dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
120         ]
121     );
122     assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
123 }
124
125 #[test]
126 fn dist_only_cross_host() {
127     let a = INTERNER.intern_str("A");
128     let b = INTERNER.intern_str("B");
129     let mut build = Build::new(configure(&["B"], &[]));
130     build.config.docs = false;
131     build.config.extended = true;
132     build.hosts = vec![b];
133     let mut builder = Builder::new(&build);
134     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
135
136     assert_eq!(
137         first(builder.cache.all::<dist::Rustc>()),
138         &[dist::Rustc { compiler: Compiler { host: b, stage: 2 } },]
139     );
140     assert_eq!(
141         first(builder.cache.all::<compile::Rustc>()),
142         &[
143             compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
144             compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
145         ]
146     );
147 }
148
149 #[test]
150 fn dist_with_targets_and_hosts() {
151     let build = Build::new(configure(&["B"], &["C"]));
152     let mut builder = Builder::new(&build);
153     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
154
155     let a = INTERNER.intern_str("A");
156     let b = INTERNER.intern_str("B");
157     let c = INTERNER.intern_str("C");
158
159     assert_eq!(
160         first(builder.cache.all::<dist::Docs>()),
161         &[dist::Docs { host: a }, dist::Docs { host: b }, dist::Docs { host: c },]
162     );
163     assert_eq!(
164         first(builder.cache.all::<dist::Mingw>()),
165         &[dist::Mingw { host: a }, dist::Mingw { host: b }, dist::Mingw { host: c },]
166     );
167     assert_eq!(
168         first(builder.cache.all::<dist::Rustc>()),
169         &[
170             dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
171             dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
172         ]
173     );
174     assert_eq!(
175         first(builder.cache.all::<dist::Std>()),
176         &[
177             dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
178             dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
179             dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
180         ]
181     );
182     assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
183 }
184
185 #[test]
186 fn dist_with_target_flag() {
187     let mut config = configure(&["B"], &["C"]);
188     config.skip_only_host_steps = true; // as-if --target=C was passed
189     let build = Build::new(config);
190     let mut builder = Builder::new(&build);
191     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
192
193     let a = INTERNER.intern_str("A");
194     let b = INTERNER.intern_str("B");
195     let c = INTERNER.intern_str("C");
196
197     assert_eq!(
198         first(builder.cache.all::<dist::Docs>()),
199         &[dist::Docs { host: a }, dist::Docs { host: b }, dist::Docs { host: c },]
200     );
201     assert_eq!(
202         first(builder.cache.all::<dist::Mingw>()),
203         &[dist::Mingw { host: a }, dist::Mingw { host: b }, dist::Mingw { host: c },]
204     );
205     assert_eq!(first(builder.cache.all::<dist::Rustc>()), &[]);
206     assert_eq!(
207         first(builder.cache.all::<dist::Std>()),
208         &[
209             dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
210             dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
211             dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
212         ]
213     );
214     assert_eq!(first(builder.cache.all::<dist::Src>()), &[]);
215 }
216
217 #[test]
218 fn dist_with_same_targets_and_hosts() {
219     let build = Build::new(configure(&["B"], &["B"]));
220     let mut builder = Builder::new(&build);
221     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
222
223     let a = INTERNER.intern_str("A");
224     let b = INTERNER.intern_str("B");
225
226     assert_eq!(
227         first(builder.cache.all::<dist::Docs>()),
228         &[dist::Docs { host: a }, dist::Docs { host: b },]
229     );
230     assert_eq!(
231         first(builder.cache.all::<dist::Mingw>()),
232         &[dist::Mingw { host: a }, dist::Mingw { host: b },]
233     );
234     assert_eq!(
235         first(builder.cache.all::<dist::Rustc>()),
236         &[
237             dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
238             dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
239         ]
240     );
241     assert_eq!(
242         first(builder.cache.all::<dist::Std>()),
243         &[
244             dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
245             dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
246         ]
247     );
248     assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
249     assert_eq!(
250         first(builder.cache.all::<compile::Std>()),
251         &[
252             compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
253             compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
254             compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
255             compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
256             compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
257         ]
258     );
259     assert_eq!(
260         first(builder.cache.all::<compile::Assemble>()),
261         &[
262             compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
263             compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
264             compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
265             compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } },
266         ]
267     );
268 }
269
270 #[test]
271 fn build_default() {
272     let build = Build::new(configure(&["B"], &["C"]));
273     let mut builder = Builder::new(&build);
274     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
275
276     let a = INTERNER.intern_str("A");
277     let b = INTERNER.intern_str("B");
278     let c = INTERNER.intern_str("C");
279
280     assert_eq!(
281         first(builder.cache.all::<compile::Std>()),
282         &[
283             compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
284             compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
285             compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
286             compile::Std { compiler: Compiler { host: b, stage: 2 }, target: a },
287             compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
288             compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
289             compile::Std { compiler: Compiler { host: b, stage: 2 }, target: b },
290             compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
291             compile::Std { compiler: Compiler { host: b, stage: 2 }, target: c },
292         ]
293     );
294     assert!(!builder.cache.all::<compile::Assemble>().is_empty());
295     assert_eq!(
296         first(builder.cache.all::<compile::Rustc>()),
297         &[
298             compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
299             compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a },
300             compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: a },
301             compile::Rustc { compiler: Compiler { host: b, stage: 2 }, target: a },
302             compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
303             compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: b },
304             compile::Rustc { compiler: Compiler { host: b, stage: 2 }, target: b },
305         ]
306     );
307 }
308
309 #[test]
310 fn build_with_target_flag() {
311     let mut config = configure(&["B"], &["C"]);
312     config.skip_only_host_steps = true;
313     let build = Build::new(config);
314     let mut builder = Builder::new(&build);
315     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
316
317     let a = INTERNER.intern_str("A");
318     let b = INTERNER.intern_str("B");
319     let c = INTERNER.intern_str("C");
320
321     assert_eq!(
322         first(builder.cache.all::<compile::Std>()),
323         &[
324             compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
325             compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
326             compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
327             compile::Std { compiler: Compiler { host: b, stage: 2 }, target: a },
328             compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
329             compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
330             compile::Std { compiler: Compiler { host: b, stage: 2 }, target: b },
331             compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
332             compile::Std { compiler: Compiler { host: b, stage: 2 }, target: c },
333         ]
334     );
335     assert_eq!(
336         first(builder.cache.all::<compile::Assemble>()),
337         &[
338             compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
339             compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
340             compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
341             compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } },
342         ]
343     );
344     assert_eq!(
345         first(builder.cache.all::<compile::Rustc>()),
346         &[
347             compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
348             compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a },
349             compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
350         ]
351     );
352 }
353
354 #[test]
355 fn test_with_no_doc_stage0() {
356     let mut config = configure(&[], &[]);
357     config.stage = Some(0);
358     config.cmd = Subcommand::Test {
359         paths: vec!["src/libstd".into()],
360         test_args: vec![],
361         rustc_args: vec![],
362         fail_fast: true,
363         doc_tests: DocTests::No,
364         bless: false,
365         compare_mode: None,
366         rustfix_coverage: false,
367         pass: None,
368     };
369
370     let build = Build::new(config);
371     let mut builder = Builder::new(&build);
372
373     let host = INTERNER.intern_str("A");
374
375     builder
376         .run_step_descriptions(&[StepDescription::from::<test::Crate>()], &["src/libstd".into()]);
377
378     // Ensure we don't build any compiler artifacts.
379     assert!(!builder.cache.contains::<compile::Rustc>());
380     assert_eq!(
381         first(builder.cache.all::<test::Crate>()),
382         &[test::Crate {
383             compiler: Compiler { host, stage: 0 },
384             target: host,
385             mode: Mode::Std,
386             test_kind: test::TestKind::Test,
387             krate: INTERNER.intern_str("std"),
388         },]
389     );
390 }
391
392 #[test]
393 fn test_exclude() {
394     let mut config = configure(&[], &[]);
395     config.exclude = vec!["src/tools/tidy".into()];
396     config.cmd = Subcommand::Test {
397         paths: Vec::new(),
398         test_args: Vec::new(),
399         rustc_args: Vec::new(),
400         fail_fast: true,
401         doc_tests: DocTests::No,
402         bless: false,
403         compare_mode: None,
404         rustfix_coverage: false,
405         pass: None,
406     };
407
408     let build = Build::new(config);
409     let builder = Builder::new(&build);
410     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
411
412     // Ensure we have really excluded tidy
413     assert!(!builder.cache.contains::<test::Tidy>());
414
415     // Ensure other tests are not affected.
416     assert!(builder.cache.contains::<test::RustdocUi>());
417 }