]> git.lizzy.rs Git - rust.git/blob - src/tools/compiletest/src/header/tests.rs
Auto merge of #69550 - RalfJung:scalar, r=oli-obk
[rust.git] / src / tools / compiletest / src / header / tests.rs
1 use std::path::Path;
2
3 use crate::common::{Config, Debugger};
4 use crate::header::{parse_normalization_string, EarlyProps};
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).");
30 }
31
32 fn config() -> Config {
33     let args = &[
34         "compiletest",
35         "--mode=ui",
36         "--compile-lib-path=",
37         "--run-lib-path=",
38         "--rustc-path=",
39         "--lldb-python=",
40         "--docck-python=",
41         "--src-base=",
42         "--build-base=",
43         "--stage-id=stage2",
44         "--cc=c",
45         "--cxx=c++",
46         "--cflags=",
47         "--llvm-components=",
48         "--android-cross-path=",
49         "--target=x86_64-unknown-linux-gnu",
50     ];
51     let args = args.iter().map(ToString::to_string).collect();
52     crate::parse_config(args)
53 }
54
55 fn parse_rs(config: &Config, contents: &str) -> EarlyProps {
56     let bytes = contents.as_bytes();
57     EarlyProps::from_reader(config, Path::new("a.rs"), bytes)
58 }
59
60 fn parse_makefile(config: &Config, contents: &str) -> EarlyProps {
61     let bytes = contents.as_bytes();
62     EarlyProps::from_reader(config, Path::new("Makefile"), bytes)
63 }
64
65 #[test]
66 fn should_fail() {
67     let config = config();
68
69     assert!(!parse_rs(&config, "").should_fail);
70     assert!(parse_rs(&config, "// should-fail").should_fail);
71 }
72
73 #[test]
74 fn revisions() {
75     let config = config();
76
77     assert_eq!(parse_rs(&config, "// revisions: a b c").revisions, vec!["a", "b", "c"],);
78     assert_eq!(
79         parse_makefile(&config, "# revisions: hello there").revisions,
80         vec!["hello", "there"],
81     );
82 }
83
84 #[test]
85 fn aux_build() {
86     let config = config();
87
88     assert_eq!(
89         parse_rs(
90             &config,
91             r"
92         // aux-build: a.rs
93         // aux-build: b.rs
94         "
95         )
96         .aux,
97         vec!["a.rs", "b.rs"],
98     );
99 }
100
101 #[test]
102 fn no_system_llvm() {
103     let mut config = config();
104
105     config.system_llvm = false;
106     assert!(!parse_rs(&config, "// no-system-llvm").ignore);
107
108     config.system_llvm = true;
109     assert!(parse_rs(&config, "// no-system-llvm").ignore);
110 }
111
112 #[test]
113 fn llvm_version() {
114     let mut config = config();
115
116     config.llvm_version = Some("8.1.2-rust".to_owned());
117     assert!(parse_rs(&config, "// min-llvm-version 9.0").ignore);
118
119     config.llvm_version = Some("9.0.1-rust-1.43.0-dev".to_owned());
120     assert!(parse_rs(&config, "// min-llvm-version 9.2").ignore);
121
122     config.llvm_version = Some("9.3.1-rust-1.43.0-dev".to_owned());
123     assert!(!parse_rs(&config, "// min-llvm-version 9.2").ignore);
124
125     // FIXME.
126     // config.llvm_version = Some("10.0.0-rust".to_owned());
127     // assert!(!parse_rs(&config, "// min-llvm-version 9.0").ignore);
128 }
129
130 #[test]
131 fn ignore_target() {
132     let mut config = config();
133     config.target = "x86_64-unknown-linux-gnu".to_owned();
134
135     assert!(parse_rs(&config, "// ignore-x86_64-unknown-linux-gnu").ignore);
136     assert!(parse_rs(&config, "// ignore-x86_64").ignore);
137     assert!(parse_rs(&config, "// ignore-linux").ignore);
138     assert!(parse_rs(&config, "// ignore-gnu").ignore);
139     assert!(parse_rs(&config, "// ignore-64bit").ignore);
140
141     assert!(!parse_rs(&config, "// ignore-i686").ignore);
142     assert!(!parse_rs(&config, "// ignore-windows").ignore);
143     assert!(!parse_rs(&config, "// ignore-msvc").ignore);
144     assert!(!parse_rs(&config, "// ignore-32bit").ignore);
145 }
146
147 #[test]
148 fn only_target() {
149     let mut config = config();
150     config.target = "x86_64-pc-windows-gnu".to_owned();
151
152     assert!(parse_rs(&config, "// only-i686").ignore);
153     assert!(parse_rs(&config, "// only-linux").ignore);
154     assert!(parse_rs(&config, "// only-msvc").ignore);
155     assert!(parse_rs(&config, "// only-32bit").ignore);
156
157     assert!(!parse_rs(&config, "// only-x86_64-pc-windows-gnu").ignore);
158     assert!(!parse_rs(&config, "// only-x86_64").ignore);
159     assert!(!parse_rs(&config, "// only-windows").ignore);
160     assert!(!parse_rs(&config, "// only-gnu").ignore);
161     assert!(!parse_rs(&config, "// only-64bit").ignore);
162 }
163
164 #[test]
165 fn stage() {
166     let mut config = config();
167     config.stage_id = "stage1".to_owned();
168
169     assert!(parse_rs(&config, "// ignore-stage1").ignore);
170     assert!(!parse_rs(&config, "// ignore-stage2").ignore);
171 }
172
173 #[test]
174 fn cross_compile() {
175     let mut config = config();
176     config.host = "x86_64-apple-darwin".to_owned();
177     config.target = "wasm32-unknown-unknown".to_owned();
178     assert!(parse_rs(&config, "// ignore-cross-compile").ignore);
179
180     config.target = config.host.clone();
181     assert!(!parse_rs(&config, "// ignore-cross-compile").ignore);
182 }
183
184 #[test]
185 fn debugger() {
186     let mut config = config();
187     config.debugger = None;
188     assert!(!parse_rs(&config, "// ignore-cdb").ignore);
189
190     config.debugger = Some(Debugger::Cdb);
191     assert!(parse_rs(&config, "// ignore-cdb").ignore);
192
193     config.debugger = Some(Debugger::Gdb);
194     assert!(parse_rs(&config, "// ignore-gdb").ignore);
195
196     config.debugger = Some(Debugger::Lldb);
197     assert!(parse_rs(&config, "// ignore-lldb").ignore);
198 }