]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | use std::path::Path; |
2 | ||
3 | use crate::common::{Config, Debugger}; | |
136023e0 | 4 | use crate::header::{make_test_description, parse_normalization_string, EarlyProps}; |
416331ca XL |
5 | |
6 | #[test] | |
7 | fn test_parse_normalization_string() { | |
8 | let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\"."; | |
9 | let first = parse_normalization_string(&mut s); | |
10 | assert_eq!(first, Some("something (32 bits)".to_owned())); | |
11 | assert_eq!(s, " -> \"something ($WORD bits)\"."); | |
12 | ||
13 | // Nothing to normalize (No quotes) | |
14 | let mut s = "normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."; | |
15 | let first = parse_normalization_string(&mut s); | |
16 | assert_eq!(first, None); | |
17 | assert_eq!(s, r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."#); | |
18 | ||
19 | // Nothing to normalize (Only a single quote) | |
20 | let mut s = "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits)."; | |
21 | let first = parse_normalization_string(&mut s); | |
22 | assert_eq!(first, None); | |
23 | assert_eq!(s, "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits)."); | |
24 | ||
25 | // Nothing to normalize (Three quotes) | |
26 | let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)."; | |
27 | let first = parse_normalization_string(&mut s); | |
28 | assert_eq!(first, Some("something (32 bits)".to_owned())); | |
29 | assert_eq!(s, " -> \"something ($WORD bits)."); | |
f035d41b XL |
30 | |
31 | // Nothing to normalize (No quotes, 16-bit) | |
32 | let mut s = "normalize-stderr-16bit: something (16 bits) -> something ($WORD bits)."; | |
33 | let first = parse_normalization_string(&mut s); | |
34 | assert_eq!(first, None); | |
35 | assert_eq!(s, r#"normalize-stderr-16bit: something (16 bits) -> something ($WORD bits)."#); | |
416331ca | 36 | } |
74b04a01 XL |
37 | |
38 | fn config() -> Config { | |
39 | let args = &[ | |
40 | "compiletest", | |
41 | "--mode=ui", | |
29967ef6 | 42 | "--suite=ui", |
74b04a01 XL |
43 | "--compile-lib-path=", |
44 | "--run-lib-path=", | |
04454e1e | 45 | "--python=", |
5869c6ff | 46 | "--jsondocck-path=", |
74b04a01 XL |
47 | "--src-base=", |
48 | "--build-base=", | |
49 | "--stage-id=stage2", | |
50 | "--cc=c", | |
51 | "--cxx=c++", | |
52 | "--cflags=", | |
5099ac24 | 53 | "--cxxflags=", |
74b04a01 XL |
54 | "--llvm-components=", |
55 | "--android-cross-path=", | |
56 | "--target=x86_64-unknown-linux-gnu", | |
17df50a5 | 57 | "--channel=nightly", |
74b04a01 | 58 | ]; |
f2b60f7d FG |
59 | let mut args: Vec<String> = args.iter().map(ToString::to_string).collect(); |
60 | args.push("--rustc-path".to_string()); | |
61 | // This is a subtle/fragile thing. On rust-lang CI, there is no global | |
62 | // `rustc`, and Cargo doesn't offer a convenient way to get the path to | |
63 | // `rustc`. Fortunately bootstrap sets `RUSTC` for us, which is pointing | |
64 | // to the stage0 compiler. | |
65 | // | |
66 | // Otherwise, if you are running compiletests's tests manually, you | |
67 | // probably don't have `RUSTC` set, in which case this falls back to the | |
68 | // global rustc. If your global rustc is too far out of sync with stage0, | |
69 | // then this may cause confusing errors. Or if for some reason you don't | |
70 | // have rustc in PATH, that would also fail. | |
71 | args.push(std::env::var("RUSTC").unwrap_or_else(|_| { | |
72 | eprintln!( | |
73 | "warning: RUSTC not set, using global rustc (are you not running via bootstrap?)" | |
74 | ); | |
75 | "rustc".to_string() | |
76 | })); | |
74b04a01 XL |
77 | crate::parse_config(args) |
78 | } | |
79 | ||
80 | fn parse_rs(config: &Config, contents: &str) -> EarlyProps { | |
81 | let bytes = contents.as_bytes(); | |
82 | EarlyProps::from_reader(config, Path::new("a.rs"), bytes) | |
83 | } | |
84 | ||
136023e0 XL |
85 | fn check_ignore(config: &Config, contents: &str) -> bool { |
86 | let tn = test::DynTestName(String::new()); | |
87 | let p = Path::new("a.rs"); | |
88 | let d = make_test_description(&config, tn, p, std::io::Cursor::new(contents), None); | |
89 | d.ignore | |
90 | } | |
91 | ||
74b04a01 XL |
92 | fn parse_makefile(config: &Config, contents: &str) -> EarlyProps { |
93 | let bytes = contents.as_bytes(); | |
94 | EarlyProps::from_reader(config, Path::new("Makefile"), bytes) | |
95 | } | |
96 | ||
97 | #[test] | |
98 | fn should_fail() { | |
99 | let config = config(); | |
136023e0 XL |
100 | let tn = test::DynTestName(String::new()); |
101 | let p = Path::new("a.rs"); | |
74b04a01 | 102 | |
136023e0 XL |
103 | let d = make_test_description(&config, tn.clone(), p, std::io::Cursor::new(""), None); |
104 | assert_eq!(d.should_panic, test::ShouldPanic::No); | |
105 | let d = make_test_description(&config, tn, p, std::io::Cursor::new("// should-fail"), None); | |
106 | assert_eq!(d.should_panic, test::ShouldPanic::Yes); | |
74b04a01 XL |
107 | } |
108 | ||
109 | #[test] | |
110 | fn revisions() { | |
111 | let config = config(); | |
112 | ||
113 | assert_eq!(parse_rs(&config, "// revisions: a b c").revisions, vec!["a", "b", "c"],); | |
114 | assert_eq!( | |
115 | parse_makefile(&config, "# revisions: hello there").revisions, | |
116 | vec!["hello", "there"], | |
117 | ); | |
118 | } | |
119 | ||
120 | #[test] | |
121 | fn aux_build() { | |
122 | let config = config(); | |
123 | ||
124 | assert_eq!( | |
125 | parse_rs( | |
126 | &config, | |
127 | r" | |
128 | // aux-build: a.rs | |
129 | // aux-build: b.rs | |
130 | " | |
131 | ) | |
132 | .aux, | |
133 | vec!["a.rs", "b.rs"], | |
134 | ); | |
135 | } | |
136 | ||
137 | #[test] | |
138 | fn no_system_llvm() { | |
139 | let mut config = config(); | |
140 | ||
141 | config.system_llvm = false; | |
136023e0 | 142 | assert!(!check_ignore(&config, "// no-system-llvm")); |
74b04a01 XL |
143 | |
144 | config.system_llvm = true; | |
136023e0 | 145 | assert!(check_ignore(&config, "// no-system-llvm")); |
74b04a01 XL |
146 | } |
147 | ||
148 | #[test] | |
149 | fn llvm_version() { | |
150 | let mut config = config(); | |
151 | ||
3dfed10e | 152 | config.llvm_version = Some(80102); |
136023e0 | 153 | assert!(check_ignore(&config, "// min-llvm-version: 9.0")); |
74b04a01 | 154 | |
3dfed10e | 155 | config.llvm_version = Some(90001); |
136023e0 | 156 | assert!(check_ignore(&config, "// min-llvm-version: 9.2")); |
74b04a01 | 157 | |
3dfed10e | 158 | config.llvm_version = Some(90301); |
136023e0 | 159 | assert!(!check_ignore(&config, "// min-llvm-version: 9.2")); |
74b04a01 | 160 | |
3dfed10e | 161 | config.llvm_version = Some(100000); |
136023e0 | 162 | assert!(!check_ignore(&config, "// min-llvm-version: 9.0")); |
74b04a01 XL |
163 | } |
164 | ||
165 | #[test] | |
166 | fn ignore_target() { | |
167 | let mut config = config(); | |
168 | config.target = "x86_64-unknown-linux-gnu".to_owned(); | |
169 | ||
136023e0 XL |
170 | assert!(check_ignore(&config, "// ignore-x86_64-unknown-linux-gnu")); |
171 | assert!(check_ignore(&config, "// ignore-x86_64")); | |
172 | assert!(check_ignore(&config, "// ignore-linux")); | |
173 | assert!(check_ignore(&config, "// ignore-gnu")); | |
174 | assert!(check_ignore(&config, "// ignore-64bit")); | |
74b04a01 | 175 | |
136023e0 XL |
176 | assert!(!check_ignore(&config, "// ignore-i686")); |
177 | assert!(!check_ignore(&config, "// ignore-windows")); | |
178 | assert!(!check_ignore(&config, "// ignore-msvc")); | |
179 | assert!(!check_ignore(&config, "// ignore-32bit")); | |
74b04a01 XL |
180 | } |
181 | ||
182 | #[test] | |
183 | fn only_target() { | |
184 | let mut config = config(); | |
185 | config.target = "x86_64-pc-windows-gnu".to_owned(); | |
186 | ||
3c0e092e | 187 | assert!(check_ignore(&config, "// only-x86")); |
136023e0 XL |
188 | assert!(check_ignore(&config, "// only-linux")); |
189 | assert!(check_ignore(&config, "// only-msvc")); | |
190 | assert!(check_ignore(&config, "// only-32bit")); | |
74b04a01 | 191 | |
136023e0 XL |
192 | assert!(!check_ignore(&config, "// only-x86_64-pc-windows-gnu")); |
193 | assert!(!check_ignore(&config, "// only-x86_64")); | |
194 | assert!(!check_ignore(&config, "// only-windows")); | |
195 | assert!(!check_ignore(&config, "// only-gnu")); | |
196 | assert!(!check_ignore(&config, "// only-64bit")); | |
74b04a01 XL |
197 | } |
198 | ||
199 | #[test] | |
200 | fn stage() { | |
201 | let mut config = config(); | |
202 | config.stage_id = "stage1".to_owned(); | |
203 | ||
136023e0 XL |
204 | assert!(check_ignore(&config, "// ignore-stage1")); |
205 | assert!(!check_ignore(&config, "// ignore-stage2")); | |
74b04a01 XL |
206 | } |
207 | ||
208 | #[test] | |
209 | fn cross_compile() { | |
210 | let mut config = config(); | |
211 | config.host = "x86_64-apple-darwin".to_owned(); | |
212 | config.target = "wasm32-unknown-unknown".to_owned(); | |
136023e0 | 213 | assert!(check_ignore(&config, "// ignore-cross-compile")); |
74b04a01 XL |
214 | |
215 | config.target = config.host.clone(); | |
136023e0 | 216 | assert!(!check_ignore(&config, "// ignore-cross-compile")); |
74b04a01 XL |
217 | } |
218 | ||
219 | #[test] | |
220 | fn debugger() { | |
221 | let mut config = config(); | |
222 | config.debugger = None; | |
136023e0 | 223 | assert!(!check_ignore(&config, "// ignore-cdb")); |
74b04a01 XL |
224 | |
225 | config.debugger = Some(Debugger::Cdb); | |
136023e0 | 226 | assert!(check_ignore(&config, "// ignore-cdb")); |
74b04a01 XL |
227 | |
228 | config.debugger = Some(Debugger::Gdb); | |
136023e0 | 229 | assert!(check_ignore(&config, "// ignore-gdb")); |
74b04a01 XL |
230 | |
231 | config.debugger = Some(Debugger::Lldb); | |
136023e0 | 232 | assert!(check_ignore(&config, "// ignore-lldb")); |
74b04a01 | 233 | } |
f035d41b XL |
234 | |
235 | #[test] | |
236 | fn sanitizers() { | |
237 | let mut config = config(); | |
238 | ||
239 | // Target that supports all sanitizers: | |
240 | config.target = "x86_64-unknown-linux-gnu".to_owned(); | |
136023e0 XL |
241 | assert!(!check_ignore(&config, "// needs-sanitizer-address")); |
242 | assert!(!check_ignore(&config, "// needs-sanitizer-leak")); | |
243 | assert!(!check_ignore(&config, "// needs-sanitizer-memory")); | |
244 | assert!(!check_ignore(&config, "// needs-sanitizer-thread")); | |
f035d41b XL |
245 | |
246 | // Target that doesn't support sanitizers: | |
247 | config.target = "wasm32-unknown-emscripten".to_owned(); | |
136023e0 XL |
248 | assert!(check_ignore(&config, "// needs-sanitizer-address")); |
249 | assert!(check_ignore(&config, "// needs-sanitizer-leak")); | |
250 | assert!(check_ignore(&config, "// needs-sanitizer-memory")); | |
251 | assert!(check_ignore(&config, "// needs-sanitizer-thread")); | |
f035d41b | 252 | } |
3dfed10e | 253 | |
cdc7bbd5 XL |
254 | #[test] |
255 | fn asm_support() { | |
f2b60f7d FG |
256 | let asms = [ |
257 | ("avr-unknown-gnu-atmega328", false), | |
258 | ("i686-unknown-netbsd", true), | |
259 | ("riscv32gc-unknown-linux-gnu", true), | |
260 | ("riscv64imac-unknown-none-elf", true), | |
261 | ("x86_64-unknown-linux-gnu", true), | |
262 | ("i686-unknown-netbsd", true), | |
263 | ]; | |
264 | for (target, has_asm) in asms { | |
265 | let mut config = config(); | |
266 | config.target = target.to_string(); | |
267 | assert_eq!(config.has_asm_support(), has_asm); | |
268 | assert_eq!(check_ignore(&config, "// needs-asm-support"), !has_asm) | |
269 | } | |
cdc7bbd5 XL |
270 | } |
271 | ||
17df50a5 XL |
272 | #[test] |
273 | fn channel() { | |
274 | let mut config = config(); | |
275 | config.channel = "beta".into(); | |
276 | ||
136023e0 XL |
277 | assert!(check_ignore(&config, "// ignore-beta")); |
278 | assert!(check_ignore(&config, "// only-nightly")); | |
279 | assert!(check_ignore(&config, "// only-stable")); | |
17df50a5 | 280 | |
136023e0 XL |
281 | assert!(!check_ignore(&config, "// only-beta")); |
282 | assert!(!check_ignore(&config, "// ignore-nightly")); | |
283 | assert!(!check_ignore(&config, "// ignore-stable")); | |
17df50a5 XL |
284 | } |
285 | ||
3dfed10e XL |
286 | #[test] |
287 | fn test_extract_version_range() { | |
288 | use super::{extract_llvm_version, extract_version_range}; | |
289 | ||
290 | assert_eq!(extract_version_range("1.2.3 - 4.5.6", extract_llvm_version), Some((10203, 40506))); | |
291 | assert_eq!(extract_version_range("0 - 4.5.6", extract_llvm_version), Some((0, 40506))); | |
292 | assert_eq!(extract_version_range("1.2.3 -", extract_llvm_version), None); | |
293 | assert_eq!(extract_version_range("1.2.3 - ", extract_llvm_version), None); | |
294 | assert_eq!(extract_version_range("- 4.5.6", extract_llvm_version), None); | |
295 | assert_eq!(extract_version_range("-", extract_llvm_version), None); | |
296 | assert_eq!(extract_version_range(" - 4.5.6", extract_llvm_version), None); | |
297 | assert_eq!(extract_version_range(" - 4.5.6", extract_llvm_version), None); | |
298 | assert_eq!(extract_version_range("0 -", extract_llvm_version), None); | |
299 | } | |
cdc7bbd5 XL |
300 | |
301 | #[test] | |
302 | #[should_panic(expected = "Duplicate revision: `rpass1` in line ` rpass1 rpass1`")] | |
303 | fn test_duplicate_revisions() { | |
304 | let config = config(); | |
305 | parse_rs(&config, "// revisions: rpass1 rpass1"); | |
306 | } | |
f2b60f7d FG |
307 | |
308 | #[test] | |
309 | fn ignore_arch() { | |
310 | let archs = [ | |
311 | ("x86_64-unknown-linux-gnu", "x86_64"), | |
312 | ("i686-unknown-linux-gnu", "x86"), | |
313 | ("nvptx64-nvidia-cuda", "nvptx64"), | |
314 | ("asmjs-unknown-emscripten", "wasm32"), | |
315 | ("asmjs-unknown-emscripten", "asmjs"), | |
316 | ("thumbv7m-none-eabi", "thumb"), | |
317 | ]; | |
318 | for (target, arch) in archs { | |
319 | let mut config = config(); | |
320 | config.target = target.to_string(); | |
321 | assert!(config.matches_arch(arch), "{target} {arch}"); | |
322 | assert!(check_ignore(&config, &format!("// ignore-{arch}"))); | |
323 | } | |
324 | } | |
325 | ||
326 | #[test] | |
327 | fn matches_os() { | |
328 | let oss = [ | |
329 | ("x86_64-unknown-linux-gnu", "linux"), | |
330 | ("x86_64-fortanix-unknown-sgx", "unknown"), | |
331 | ("wasm32-unknown-unknown", "unknown"), | |
332 | ("x86_64-unknown-none", "none"), | |
333 | ]; | |
334 | for (target, os) in oss { | |
335 | let mut config = config(); | |
336 | config.target = target.to_string(); | |
337 | assert!(config.matches_os(os), "{target} {os}"); | |
338 | assert!(check_ignore(&config, &format!("// ignore-{os}"))); | |
339 | } | |
340 | } | |
341 | ||
342 | #[test] | |
343 | fn matches_env() { | |
344 | let envs = [ | |
345 | ("x86_64-unknown-linux-gnu", "gnu"), | |
346 | ("x86_64-fortanix-unknown-sgx", "sgx"), | |
347 | ("arm-unknown-linux-musleabi", "musl"), | |
348 | ]; | |
349 | for (target, env) in envs { | |
350 | let mut config = config(); | |
351 | config.target = target.to_string(); | |
352 | assert!(config.matches_env(env), "{target} {env}"); | |
353 | assert!(check_ignore(&config, &format!("// ignore-{env}"))); | |
354 | } | |
355 | } | |
356 | ||
357 | #[test] | |
358 | fn matches_abi() { | |
359 | let abis = [ | |
360 | ("aarch64-apple-ios-macabi", "macabi"), | |
361 | ("x86_64-unknown-linux-gnux32", "x32"), | |
362 | ("arm-unknown-linux-gnueabi", "eabi"), | |
363 | ]; | |
364 | for (target, abi) in abis { | |
365 | let mut config = config(); | |
366 | config.target = target.to_string(); | |
367 | assert!(config.matches_abi(abi), "{target} {abi}"); | |
368 | assert!(check_ignore(&config, &format!("// ignore-{abi}"))); | |
369 | } | |
370 | } | |
371 | ||
372 | #[test] | |
373 | fn is_big_endian() { | |
374 | let endians = [ | |
375 | ("x86_64-unknown-linux-gnu", false), | |
376 | ("bpfeb-unknown-none", true), | |
377 | ("m68k-unknown-linux-gnu", true), | |
378 | ("aarch64_be-unknown-linux-gnu", true), | |
379 | ("powerpc64-unknown-linux-gnu", true), | |
380 | ]; | |
381 | for (target, is_big) in endians { | |
382 | let mut config = config(); | |
383 | config.target = target.to_string(); | |
384 | assert_eq!(config.is_big_endian(), is_big, "{target} {is_big}"); | |
385 | assert_eq!(check_ignore(&config, "// ignore-endian-big"), is_big); | |
386 | } | |
387 | } | |
388 | ||
389 | #[test] | |
390 | fn pointer_width() { | |
391 | let widths = [ | |
392 | ("x86_64-unknown-linux-gnu", 64), | |
393 | ("i686-unknown-linux-gnu", 32), | |
394 | ("arm64_32-apple-watchos", 32), | |
395 | ("msp430-none-elf", 16), | |
396 | ]; | |
397 | for (target, width) in widths { | |
398 | let mut config = config(); | |
399 | config.target = target.to_string(); | |
400 | assert_eq!(config.get_pointer_width(), width, "{target} {width}"); | |
401 | assert_eq!(check_ignore(&config, "// ignore-16bit"), width == 16); | |
402 | assert_eq!(check_ignore(&config, "// ignore-32bit"), width == 32); | |
403 | assert_eq!(check_ignore(&config, "// ignore-64bit"), width == 64); | |
404 | } | |
405 | } | |
406 | ||
407 | #[test] | |
408 | fn wasm_special() { | |
409 | let ignores = [ | |
410 | ("wasm32-unknown-unknown", "emscripten", true), | |
411 | ("wasm32-unknown-unknown", "wasm32", true), | |
412 | ("wasm32-unknown-unknown", "wasm32-bare", true), | |
413 | ("wasm32-unknown-unknown", "wasm64", false), | |
414 | ("asmjs-unknown-emscripten", "emscripten", true), | |
415 | ("asmjs-unknown-emscripten", "wasm32", true), | |
416 | ("asmjs-unknown-emscripten", "wasm32-bare", false), | |
417 | ("wasm32-unknown-emscripten", "emscripten", true), | |
418 | ("wasm32-unknown-emscripten", "wasm32", true), | |
419 | ("wasm32-unknown-emscripten", "wasm32-bare", false), | |
420 | ("wasm32-wasi", "emscripten", false), | |
421 | ("wasm32-wasi", "wasm32", true), | |
422 | ("wasm32-wasi", "wasm32-bare", false), | |
423 | ("wasm32-wasi", "wasi", true), | |
424 | ("wasm64-unknown-unknown", "emscripten", false), | |
425 | ("wasm64-unknown-unknown", "wasm32", false), | |
426 | ("wasm64-unknown-unknown", "wasm32-bare", false), | |
427 | ("wasm64-unknown-unknown", "wasm64", true), | |
428 | ]; | |
429 | for (target, pattern, ignore) in ignores { | |
430 | let mut config = config(); | |
431 | config.target = target.to_string(); | |
432 | assert_eq!( | |
433 | check_ignore(&config, &format!("// ignore-{pattern}")), | |
434 | ignore, | |
435 | "{target} {pattern}" | |
436 | ); | |
437 | } | |
438 | } | |
439 | ||
440 | #[test] | |
441 | fn families() { | |
442 | let families = [ | |
443 | ("x86_64-unknown-linux-gnu", "unix"), | |
444 | ("x86_64-pc-windows-gnu", "windows"), | |
445 | ("wasm32-unknown-unknown", "wasm"), | |
446 | ("wasm32-unknown-emscripten", "wasm"), | |
447 | ("wasm32-unknown-emscripten", "unix"), | |
448 | ]; | |
449 | for (target, family) in families { | |
450 | let mut config = config(); | |
451 | config.target = target.to_string(); | |
452 | assert!(config.matches_family(family)); | |
453 | let other = if family == "windows" { "unix" } else { "windows" }; | |
454 | assert!(!config.matches_family(other)); | |
455 | assert!(check_ignore(&config, &format!("// ignore-{family}"))); | |
456 | assert!(!check_ignore(&config, &format!("// ignore-{other}"))); | |
457 | } | |
458 | } |