]> git.proxmox.com Git - rustc.git/blame - src/tools/compiletest/src/header/tests.rs
New upstream version 1.49.0~beta.4+dfsg1
[rustc.git] / src / tools / compiletest / src / header / tests.rs
CommitLineData
74b04a01
XL
1use std::path::Path;
2
3use crate::common::{Config, Debugger};
4use crate::header::{parse_normalization_string, EarlyProps};
416331ca
XL
5
6#[test]
7fn 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
38fn config() -> Config {
39 let args = &[
40 "compiletest",
41 "--mode=ui",
29967ef6 42 "--suite=ui",
74b04a01
XL
43 "--compile-lib-path=",
44 "--run-lib-path=",
45 "--rustc-path=",
46 "--lldb-python=",
47 "--docck-python=",
48 "--src-base=",
49 "--build-base=",
50 "--stage-id=stage2",
51 "--cc=c",
52 "--cxx=c++",
53 "--cflags=",
54 "--llvm-components=",
55 "--android-cross-path=",
56 "--target=x86_64-unknown-linux-gnu",
57 ];
58 let args = args.iter().map(ToString::to_string).collect();
59 crate::parse_config(args)
60}
61
62fn parse_rs(config: &Config, contents: &str) -> EarlyProps {
63 let bytes = contents.as_bytes();
64 EarlyProps::from_reader(config, Path::new("a.rs"), bytes)
65}
66
67fn parse_makefile(config: &Config, contents: &str) -> EarlyProps {
68 let bytes = contents.as_bytes();
69 EarlyProps::from_reader(config, Path::new("Makefile"), bytes)
70}
71
72#[test]
73fn should_fail() {
74 let config = config();
75
76 assert!(!parse_rs(&config, "").should_fail);
77 assert!(parse_rs(&config, "// should-fail").should_fail);
78}
79
80#[test]
81fn revisions() {
82 let config = config();
83
84 assert_eq!(parse_rs(&config, "// revisions: a b c").revisions, vec!["a", "b", "c"],);
85 assert_eq!(
86 parse_makefile(&config, "# revisions: hello there").revisions,
87 vec!["hello", "there"],
88 );
89}
90
91#[test]
92fn aux_build() {
93 let config = config();
94
95 assert_eq!(
96 parse_rs(
97 &config,
98 r"
99 // aux-build: a.rs
100 // aux-build: b.rs
101 "
102 )
103 .aux,
104 vec!["a.rs", "b.rs"],
105 );
106}
107
108#[test]
109fn no_system_llvm() {
110 let mut config = config();
111
112 config.system_llvm = false;
113 assert!(!parse_rs(&config, "// no-system-llvm").ignore);
114
115 config.system_llvm = true;
116 assert!(parse_rs(&config, "// no-system-llvm").ignore);
117}
118
119#[test]
120fn llvm_version() {
121 let mut config = config();
122
3dfed10e
XL
123 config.llvm_version = Some(80102);
124 assert!(parse_rs(&config, "// min-llvm-version: 9.0").ignore);
74b04a01 125
3dfed10e
XL
126 config.llvm_version = Some(90001);
127 assert!(parse_rs(&config, "// min-llvm-version: 9.2").ignore);
74b04a01 128
3dfed10e
XL
129 config.llvm_version = Some(90301);
130 assert!(!parse_rs(&config, "// min-llvm-version: 9.2").ignore);
74b04a01 131
3dfed10e
XL
132 config.llvm_version = Some(100000);
133 assert!(!parse_rs(&config, "// min-llvm-version: 9.0").ignore);
74b04a01
XL
134}
135
136#[test]
137fn ignore_target() {
138 let mut config = config();
139 config.target = "x86_64-unknown-linux-gnu".to_owned();
140
141 assert!(parse_rs(&config, "// ignore-x86_64-unknown-linux-gnu").ignore);
142 assert!(parse_rs(&config, "// ignore-x86_64").ignore);
143 assert!(parse_rs(&config, "// ignore-linux").ignore);
144 assert!(parse_rs(&config, "// ignore-gnu").ignore);
145 assert!(parse_rs(&config, "// ignore-64bit").ignore);
146
147 assert!(!parse_rs(&config, "// ignore-i686").ignore);
148 assert!(!parse_rs(&config, "// ignore-windows").ignore);
149 assert!(!parse_rs(&config, "// ignore-msvc").ignore);
150 assert!(!parse_rs(&config, "// ignore-32bit").ignore);
151}
152
153#[test]
154fn only_target() {
155 let mut config = config();
156 config.target = "x86_64-pc-windows-gnu".to_owned();
157
158 assert!(parse_rs(&config, "// only-i686").ignore);
159 assert!(parse_rs(&config, "// only-linux").ignore);
160 assert!(parse_rs(&config, "// only-msvc").ignore);
161 assert!(parse_rs(&config, "// only-32bit").ignore);
162
163 assert!(!parse_rs(&config, "// only-x86_64-pc-windows-gnu").ignore);
164 assert!(!parse_rs(&config, "// only-x86_64").ignore);
165 assert!(!parse_rs(&config, "// only-windows").ignore);
166 assert!(!parse_rs(&config, "// only-gnu").ignore);
167 assert!(!parse_rs(&config, "// only-64bit").ignore);
168}
169
170#[test]
171fn stage() {
172 let mut config = config();
173 config.stage_id = "stage1".to_owned();
174
175 assert!(parse_rs(&config, "// ignore-stage1").ignore);
176 assert!(!parse_rs(&config, "// ignore-stage2").ignore);
177}
178
179#[test]
180fn cross_compile() {
181 let mut config = config();
182 config.host = "x86_64-apple-darwin".to_owned();
183 config.target = "wasm32-unknown-unknown".to_owned();
184 assert!(parse_rs(&config, "// ignore-cross-compile").ignore);
185
186 config.target = config.host.clone();
187 assert!(!parse_rs(&config, "// ignore-cross-compile").ignore);
188}
189
190#[test]
191fn debugger() {
192 let mut config = config();
193 config.debugger = None;
194 assert!(!parse_rs(&config, "// ignore-cdb").ignore);
195
196 config.debugger = Some(Debugger::Cdb);
197 assert!(parse_rs(&config, "// ignore-cdb").ignore);
198
199 config.debugger = Some(Debugger::Gdb);
200 assert!(parse_rs(&config, "// ignore-gdb").ignore);
201
202 config.debugger = Some(Debugger::Lldb);
203 assert!(parse_rs(&config, "// ignore-lldb").ignore);
204}
f035d41b
XL
205
206#[test]
207fn sanitizers() {
208 let mut config = config();
209
210 // Target that supports all sanitizers:
211 config.target = "x86_64-unknown-linux-gnu".to_owned();
212 assert!(!parse_rs(&config, "// needs-sanitizer-address").ignore);
213 assert!(!parse_rs(&config, "// needs-sanitizer-leak").ignore);
214 assert!(!parse_rs(&config, "// needs-sanitizer-memory").ignore);
215 assert!(!parse_rs(&config, "// needs-sanitizer-thread").ignore);
216
217 // Target that doesn't support sanitizers:
218 config.target = "wasm32-unknown-emscripten".to_owned();
219 assert!(parse_rs(&config, "// needs-sanitizer-address").ignore);
220 assert!(parse_rs(&config, "// needs-sanitizer-leak").ignore);
221 assert!(parse_rs(&config, "// needs-sanitizer-memory").ignore);
222 assert!(parse_rs(&config, "// needs-sanitizer-thread").ignore);
223}
3dfed10e
XL
224
225#[test]
226fn test_extract_version_range() {
227 use super::{extract_llvm_version, extract_version_range};
228
229 assert_eq!(extract_version_range("1.2.3 - 4.5.6", extract_llvm_version), Some((10203, 40506)));
230 assert_eq!(extract_version_range("0 - 4.5.6", extract_llvm_version), Some((0, 40506)));
231 assert_eq!(extract_version_range("1.2.3 -", extract_llvm_version), None);
232 assert_eq!(extract_version_range("1.2.3 - ", extract_llvm_version), None);
233 assert_eq!(extract_version_range("- 4.5.6", extract_llvm_version), None);
234 assert_eq!(extract_version_range("-", extract_llvm_version), None);
235 assert_eq!(extract_version_range(" - 4.5.6", extract_llvm_version), None);
236 assert_eq!(extract_version_range(" - 4.5.6", extract_llvm_version), None);
237 assert_eq!(extract_version_range("0 -", extract_llvm_version), None);
238}