]> git.lizzy.rs Git - rust.git/blob - src/tools/compiletest/src/header/tests.rs
Auto merge of #67885 - tobithiel:fix_group_lint_allow_override, r=Mark-Simulacrum
[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 ignore_target() {
114     let mut config = config();
115     config.target = "x86_64-unknown-linux-gnu".to_owned();
116
117     assert!(parse_rs(&config, "// ignore-x86_64-unknown-linux-gnu").ignore);
118     assert!(parse_rs(&config, "// ignore-x86_64").ignore);
119     assert!(parse_rs(&config, "// ignore-linux").ignore);
120     assert!(parse_rs(&config, "// ignore-gnu").ignore);
121     assert!(parse_rs(&config, "// ignore-64bit").ignore);
122
123     assert!(!parse_rs(&config, "// ignore-i686").ignore);
124     assert!(!parse_rs(&config, "// ignore-windows").ignore);
125     assert!(!parse_rs(&config, "// ignore-msvc").ignore);
126     assert!(!parse_rs(&config, "// ignore-32bit").ignore);
127 }
128
129 #[test]
130 fn only_target() {
131     let mut config = config();
132     config.target = "x86_64-pc-windows-gnu".to_owned();
133
134     assert!(parse_rs(&config, "// only-i686").ignore);
135     assert!(parse_rs(&config, "// only-linux").ignore);
136     assert!(parse_rs(&config, "// only-msvc").ignore);
137     assert!(parse_rs(&config, "// only-32bit").ignore);
138
139     assert!(!parse_rs(&config, "// only-x86_64-pc-windows-gnu").ignore);
140     assert!(!parse_rs(&config, "// only-x86_64").ignore);
141     assert!(!parse_rs(&config, "// only-windows").ignore);
142     assert!(!parse_rs(&config, "// only-gnu").ignore);
143     assert!(!parse_rs(&config, "// only-64bit").ignore);
144 }
145
146 #[test]
147 fn stage() {
148     let mut config = config();
149     config.stage_id = "stage1".to_owned();
150
151     assert!(parse_rs(&config, "// ignore-stage1").ignore);
152     assert!(!parse_rs(&config, "// ignore-stage2").ignore);
153 }
154
155 #[test]
156 fn cross_compile() {
157     let mut config = config();
158     config.host = "x86_64-apple-darwin".to_owned();
159     config.target = "wasm32-unknown-unknown".to_owned();
160     assert!(parse_rs(&config, "// ignore-cross-compile").ignore);
161
162     config.target = config.host.clone();
163     assert!(!parse_rs(&config, "// ignore-cross-compile").ignore);
164 }
165
166 #[test]
167 fn debugger() {
168     let mut config = config();
169     config.debugger = None;
170     assert!(!parse_rs(&config, "// ignore-cdb").ignore);
171
172     config.debugger = Some(Debugger::Cdb);
173     assert!(parse_rs(&config, "// ignore-cdb").ignore);
174
175     config.debugger = Some(Debugger::Gdb);
176     assert!(parse_rs(&config, "// ignore-gdb").ignore);
177
178     config.debugger = Some(Debugger::Lldb);
179     assert!(parse_rs(&config, "// ignore-lldb").ignore);
180 }