1 use std
::collections
::HashSet
;
4 use std
::io
::prelude
::*;
5 use std
::io
::BufReader
;
6 use std
::path
::{Path, PathBuf}
;
10 use crate::common
::{CompareMode, Config, Debugger, FailMode, Mode, PanicStrategy, PassMode}
;
12 use crate::{extract_cdb_version, extract_gdb_version}
;
17 /// The result of parse_cfg_name_directive.
18 #[derive(Clone, Copy, PartialEq, Debug)]
19 enum ParsedNameDirective
{
26 /// Properties which must be known very early, before actually running
29 pub struct EarlyProps
{
31 pub aux_crate
: Vec
<(String
, String
)>,
32 pub revisions
: Vec
<String
>,
36 pub fn from_file(config
: &Config
, testfile
: &Path
) -> Self {
37 let file
= File
::open(testfile
).expect("open test file to parse earlyprops");
38 Self::from_reader(config
, testfile
, file
)
41 pub fn from_reader
<R
: Read
>(config
: &Config
, testfile
: &Path
, rdr
: R
) -> Self {
42 let mut props
= EarlyProps
::default();
43 iter_header(testfile
, rdr
, &mut |_
, ln
| {
44 if let Some(s
) = config
.parse_aux_build(ln
) {
47 if let Some(ac
) = config
.parse_aux_crate(ln
) {
48 props
.aux_crate
.push(ac
);
50 config
.parse_and_update_revisions(ln
, &mut props
.revisions
);
56 #[derive(Clone, Debug)]
57 pub struct TestProps
{
58 // Lines that should be expected, in order, on standard out
59 pub error_patterns
: Vec
<String
>,
60 // Extra flags to pass to the compiler
61 pub compile_flags
: Vec
<String
>,
62 // Extra flags to pass when the compiled code is run (such as --bench)
63 pub run_flags
: Option
<String
>,
64 // If present, the name of a file that this test should match when
66 pub pp_exact
: Option
<PathBuf
>,
67 // Other crates that should be compiled (typically from the same
68 // directory as the test, but for backwards compatibility reasons
69 // we also check the auxiliary directory)
70 pub aux_builds
: Vec
<String
>,
71 // Similar to `aux_builds`, but a list of NAME=somelib.rs of dependencies
72 // to build and pass with the `--extern` flag.
73 pub aux_crates
: Vec
<(String
, String
)>,
74 // Environment settings to use for compiling
75 pub rustc_env
: Vec
<(String
, String
)>,
76 // Environment variables to unset prior to compiling.
77 // Variables are unset before applying 'rustc_env'.
78 pub unset_rustc_env
: Vec
<String
>,
79 // Environment settings to use during execution
80 pub exec_env
: Vec
<(String
, String
)>,
81 // Lines to check if they appear in the expected debugger output
82 pub check_lines
: Vec
<String
>,
83 // Build documentation for all specified aux-builds as well
84 pub build_aux_docs
: bool
,
85 // Flag to force a crate to be built with the host architecture
87 // Check stdout for error-pattern output as well as stderr
88 pub check_stdout
: bool
,
89 // Check stdout & stderr for output of run-pass test
90 pub check_run_results
: bool
,
91 // For UI tests, allows compiler to generate arbitrary output to stdout
92 pub dont_check_compiler_stdout
: bool
,
93 // For UI tests, allows compiler to generate arbitrary output to stderr
94 pub dont_check_compiler_stderr
: bool
,
95 // Don't force a --crate-type=dylib flag on the command line
97 // Set this for example if you have an auxiliary test file that contains
98 // a proc-macro and needs `#![crate_type = "proc-macro"]`. This ensures
99 // that the aux file is compiled as a `proc-macro` and not as a `dylib`.
100 pub no_prefer_dynamic
: bool
,
101 // Run -Zunpretty expanded when running pretty printing tests
102 pub pretty_expanded
: bool
,
103 // Which pretty mode are we testing with, default to 'normal'
104 pub pretty_mode
: String
,
105 // Only compare pretty output and don't try compiling
106 pub pretty_compare_only
: bool
,
107 // Patterns which must not appear in the output of a cfail test.
108 pub forbid_output
: Vec
<String
>,
109 // Revisions to test for incremental compilation.
110 pub revisions
: Vec
<String
>,
111 // Directory (if any) to use for incremental compilation. This is
112 // not set by end-users; rather it is set by the incremental
113 // testing harness and used when generating compilation
114 // arguments. (In particular, it propagates to the aux-builds.)
115 pub incremental_dir
: Option
<PathBuf
>,
116 // How far should the test proceed while still passing.
117 pass_mode
: Option
<PassMode
>,
118 // Ignore `--pass` overrides from the command line for this test.
120 // How far this test should proceed to start failing.
121 pub fail_mode
: Option
<FailMode
>,
122 // rustdoc will test the output of the `--test` option
123 pub check_test_line_numbers_match
: bool
,
124 // customized normalization rules
125 pub normalize_stdout
: Vec
<(String
, String
)>,
126 pub normalize_stderr
: Vec
<(String
, String
)>,
127 pub failure_status
: i32,
128 // Whether or not `rustfix` should apply the `CodeSuggestion`s of this test and compile the
129 // resulting Rust code.
130 pub run_rustfix
: bool
,
131 // If true, `rustfix` will only apply `MachineApplicable` suggestions.
132 pub rustfix_only_machine_applicable
: bool
,
133 pub assembly_output
: Option
<String
>,
134 // If true, the test is expected to ICE
135 pub should_ice
: bool
,
136 // If true, the stderr is expected to be different across bit-widths.
137 pub stderr_per_bitwidth
: bool
,
141 pub fn new() -> Self {
143 error_patterns
: vec
![],
144 compile_flags
: vec
![],
151 unset_rustc_env
: vec
![],
154 build_aux_docs
: false,
157 check_run_results
: false,
158 dont_check_compiler_stdout
: false,
159 dont_check_compiler_stderr
: false,
160 no_prefer_dynamic
: false,
161 pretty_expanded
: false,
162 pretty_mode
: "normal".to_string(),
163 pretty_compare_only
: false,
164 forbid_output
: vec
![],
165 incremental_dir
: None
,
169 check_test_line_numbers_match
: false,
170 normalize_stdout
: vec
![],
171 normalize_stderr
: vec
![],
174 rustfix_only_machine_applicable
: false,
175 assembly_output
: None
,
177 stderr_per_bitwidth
: false,
181 pub fn from_aux_file(&self, testfile
: &Path
, cfg
: Option
<&str>, config
: &Config
) -> Self {
182 let mut props
= TestProps
::new();
184 // copy over select properties to the aux build:
185 props
.incremental_dir
= self.incremental_dir
.clone();
186 props
.load_from(testfile
, cfg
, config
);
191 pub fn from_file(testfile
: &Path
, cfg
: Option
<&str>, config
: &Config
) -> Self {
192 let mut props
= TestProps
::new();
193 props
.load_from(testfile
, cfg
, config
);
195 match (props
.pass_mode
, props
.fail_mode
) {
196 (None
, None
) => props
.fail_mode
= Some(FailMode
::Check
),
197 (Some(_
), None
) | (None
, Some(_
)) => {}
198 (Some(_
), Some(_
)) => panic
!("cannot use a *-fail and *-pass mode together"),
204 /// Loads properties from `testfile` into `props`. If a property is
205 /// tied to a particular revision `foo` (indicated by writing
206 /// `//[foo]`), then the property is ignored unless `cfg` is
208 fn load_from(&mut self, testfile
: &Path
, cfg
: Option
<&str>, config
: &Config
) {
209 if !testfile
.is_dir() {
210 let file
= File
::open(testfile
).unwrap();
212 iter_header(testfile
, file
, &mut |revision
, ln
| {
213 if revision
.is_some() && revision
!= cfg
{
217 if let Some(ep
) = config
.parse_error_pattern(ln
) {
218 self.error_patterns
.push(ep
);
221 if let Some(flags
) = config
.parse_compile_flags(ln
) {
222 self.compile_flags
.extend(flags
.split_whitespace().map(|s
| s
.to_owned()));
225 if let Some(edition
) = config
.parse_edition(ln
) {
226 self.compile_flags
.push(format
!("--edition={}", edition
));
227 if edition
== "2021" {
228 self.compile_flags
.push("-Zunstable-options".to_string());
232 config
.parse_and_update_revisions(ln
, &mut self.revisions
);
234 if self.run_flags
.is_none() {
235 self.run_flags
= config
.parse_run_flags(ln
);
238 if self.pp_exact
.is_none() {
239 self.pp_exact
= config
.parse_pp_exact(ln
, testfile
);
242 if !self.should_ice
{
243 self.should_ice
= config
.parse_should_ice(ln
);
246 if !self.build_aux_docs
{
247 self.build_aux_docs
= config
.parse_build_aux_docs(ln
);
250 if !self.force_host
{
251 self.force_host
= config
.parse_force_host(ln
);
254 if !self.check_stdout
{
255 self.check_stdout
= config
.parse_check_stdout(ln
);
258 if !self.check_run_results
{
259 self.check_run_results
= config
.parse_check_run_results(ln
);
262 if !self.dont_check_compiler_stdout
{
263 self.dont_check_compiler_stdout
= config
.parse_dont_check_compiler_stdout(ln
);
266 if !self.dont_check_compiler_stderr
{
267 self.dont_check_compiler_stderr
= config
.parse_dont_check_compiler_stderr(ln
);
270 if !self.no_prefer_dynamic
{
271 self.no_prefer_dynamic
= config
.parse_no_prefer_dynamic(ln
);
274 if !self.pretty_expanded
{
275 self.pretty_expanded
= config
.parse_pretty_expanded(ln
);
278 if let Some(m
) = config
.parse_pretty_mode(ln
) {
279 self.pretty_mode
= m
;
282 if !self.pretty_compare_only
{
283 self.pretty_compare_only
= config
.parse_pretty_compare_only(ln
);
286 if let Some(ab
) = config
.parse_aux_build(ln
) {
287 self.aux_builds
.push(ab
);
290 if let Some(ac
) = config
.parse_aux_crate(ln
) {
291 self.aux_crates
.push(ac
);
294 if let Some(ee
) = config
.parse_env(ln
, "exec-env") {
295 self.exec_env
.push(ee
);
298 if let Some(ee
) = config
.parse_env(ln
, "rustc-env") {
299 self.rustc_env
.push(ee
);
302 if let Some(ev
) = config
.parse_name_value_directive(ln
, "unset-rustc-env") {
303 self.unset_rustc_env
.push(ev
);
306 if let Some(cl
) = config
.parse_check_line(ln
) {
307 self.check_lines
.push(cl
);
310 if let Some(of
) = config
.parse_forbid_output(ln
) {
311 self.forbid_output
.push(of
);
314 if !self.check_test_line_numbers_match
{
315 self.check_test_line_numbers_match
=
316 config
.parse_check_test_line_numbers_match(ln
);
319 self.update_pass_mode(ln
, cfg
, config
);
320 self.update_fail_mode(ln
, config
);
322 if !self.ignore_pass
{
323 self.ignore_pass
= config
.parse_ignore_pass(ln
);
326 if let Some(rule
) = config
.parse_custom_normalization(ln
, "normalize-stdout") {
327 self.normalize_stdout
.push(rule
);
329 if let Some(rule
) = config
.parse_custom_normalization(ln
, "normalize-stderr") {
330 self.normalize_stderr
.push(rule
);
333 if let Some(code
) = config
.parse_failure_status(ln
) {
334 self.failure_status
= code
;
337 if !self.run_rustfix
{
338 self.run_rustfix
= config
.parse_run_rustfix(ln
);
341 if !self.rustfix_only_machine_applicable
{
342 self.rustfix_only_machine_applicable
=
343 config
.parse_rustfix_only_machine_applicable(ln
);
346 if self.assembly_output
.is_none() {
347 self.assembly_output
= config
.parse_assembly_output(ln
);
350 if !self.stderr_per_bitwidth
{
351 self.stderr_per_bitwidth
= config
.parse_stderr_per_bitwidth(ln
);
356 if self.failure_status
== -1 {
357 self.failure_status
= 1;
360 self.failure_status
= 101;
363 for key
in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
364 if let Ok(val
) = env
::var(key
) {
365 if self.exec_env
.iter().find(|&&(ref x
, _
)| x
== key
).is_none() {
366 self.exec_env
.push(((*key
).to_owned(), val
))
372 fn update_fail_mode(&mut self, ln
: &str, config
: &Config
) {
373 let check_ui
= |mode
: &str| {
374 if config
.mode
!= Mode
::Ui
{
375 panic
!("`{}-fail` header is only supported in UI tests", mode
);
378 if config
.mode
== Mode
::Ui
&& config
.parse_name_directive(ln
, "compile-fail") {
379 panic
!("`compile-fail` header is useless in UI tests");
381 let fail_mode
= if config
.parse_name_directive(ln
, "check-fail") {
383 Some(FailMode
::Check
)
384 } else if config
.parse_name_directive(ln
, "build-fail") {
386 Some(FailMode
::Build
)
387 } else if config
.parse_name_directive(ln
, "run-fail") {
393 match (self.fail_mode
, fail_mode
) {
394 (None
, Some(_
)) => self.fail_mode
= fail_mode
,
395 (Some(_
), Some(_
)) => panic
!("multiple `*-fail` headers in a single test"),
400 fn update_pass_mode(&mut self, ln
: &str, revision
: Option
<&str>, config
: &Config
) {
401 let check_no_run
= |s
| {
402 if config
.mode
!= Mode
::Ui
&& config
.mode
!= Mode
::Incremental
{
403 panic
!("`{}` header is only supported in UI and incremental tests", s
);
405 if config
.mode
== Mode
::Incremental
406 && !revision
.map_or(false, |r
| r
.starts_with("cfail"))
407 && !self.revisions
.iter().all(|r
| r
.starts_with("cfail"))
409 panic
!("`{}` header is only supported in `cfail` incremental tests", s
);
412 let pass_mode
= if config
.parse_name_directive(ln
, "check-pass") {
413 check_no_run("check-pass");
414 Some(PassMode
::Check
)
415 } else if config
.parse_name_directive(ln
, "build-pass") {
416 check_no_run("build-pass");
417 Some(PassMode
::Build
)
418 } else if config
.parse_name_directive(ln
, "run-pass") {
419 if config
.mode
!= Mode
::Ui
{
420 panic
!("`run-pass` header is only supported in UI tests")
426 match (self.pass_mode
, pass_mode
) {
427 (None
, Some(_
)) => self.pass_mode
= pass_mode
,
428 (Some(_
), Some(_
)) => panic
!("multiple `*-pass` headers in a single test"),
433 pub fn pass_mode(&self, config
: &Config
) -> Option
<PassMode
> {
434 if !self.ignore_pass
&& self.fail_mode
.is_none() && config
.mode
== Mode
::Ui
{
435 if let (mode @
Some(_
), Some(_
)) = (config
.force_pass_mode
, self.pass_mode
) {
442 // does not consider CLI override for pass mode
443 pub fn local_pass_mode(&self) -> Option
<PassMode
> {
448 fn iter_header
<R
: Read
>(testfile
: &Path
, rdr
: R
, it
: &mut dyn FnMut(Option
<&str>, &str)) {
449 if testfile
.is_dir() {
453 let comment
= if testfile
.extension().map(|e
| e
== "rs") == Some(true) { "//" }
else { "#" }
;
455 let mut rdr
= BufReader
::new(rdr
);
456 let mut ln
= String
::new();
460 if rdr
.read_line(&mut ln
).unwrap() == 0 {
464 // Assume that any directives will be found before the first
465 // module or function. This doesn't seem to be an optimization
466 // with a warm page cache. Maybe with a cold one.
468 if ln
.starts_with("fn") || ln
.starts_with("mod") {
470 } else if ln
.starts_with(comment
) && ln
[comment
.len()..].trim_start().starts_with('
['
) {
471 // A comment like `//[foo]` is specific to revision `foo`
472 if let Some(close_brace
) = ln
.find('
]'
) {
473 let open_brace
= ln
.find('
['
).unwrap();
474 let lncfg
= &ln
[open_brace
+ 1..close_brace
];
475 it(Some(lncfg
), ln
[(close_brace
+ 1)..].trim_start());
477 panic
!("malformed condition directive: expected `{}[foo]`, found `{}`", comment
, ln
)
479 } else if ln
.starts_with(comment
) {
480 it(None
, ln
[comment
.len()..].trim_start());
486 fn parse_should_ice(&self, line
: &str) -> bool
{
487 self.parse_name_directive(line
, "should-ice")
489 fn parse_error_pattern(&self, line
: &str) -> Option
<String
> {
490 self.parse_name_value_directive(line
, "error-pattern")
493 fn parse_forbid_output(&self, line
: &str) -> Option
<String
> {
494 self.parse_name_value_directive(line
, "forbid-output")
497 fn parse_aux_build(&self, line
: &str) -> Option
<String
> {
498 self.parse_name_value_directive(line
, "aux-build").map(|r
| r
.trim().to_string())
501 fn parse_aux_crate(&self, line
: &str) -> Option
<(String
, String
)> {
502 self.parse_name_value_directive(line
, "aux-crate").map(|r
| {
503 let mut parts
= r
.trim().splitn(2, '
='
);
505 parts
.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(),
506 parts
.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(),
511 fn parse_compile_flags(&self, line
: &str) -> Option
<String
> {
512 self.parse_name_value_directive(line
, "compile-flags")
515 fn parse_and_update_revisions(&self, line
: &str, existing
: &mut Vec
<String
>) {
516 if let Some(raw
) = self.parse_name_value_directive(line
, "revisions") {
517 let mut duplicates
: HashSet
<_
> = existing
.iter().cloned().collect();
518 for revision
in raw
.split_whitespace().map(|r
| r
.to_string()) {
519 if !duplicates
.insert(revision
.clone()) {
520 panic
!("Duplicate revision: `{}` in line `{}`", revision
, raw
);
522 existing
.push(revision
);
527 fn parse_run_flags(&self, line
: &str) -> Option
<String
> {
528 self.parse_name_value_directive(line
, "run-flags")
531 fn parse_check_line(&self, line
: &str) -> Option
<String
> {
532 self.parse_name_value_directive(line
, "check")
535 fn parse_force_host(&self, line
: &str) -> bool
{
536 self.parse_name_directive(line
, "force-host")
539 fn parse_build_aux_docs(&self, line
: &str) -> bool
{
540 self.parse_name_directive(line
, "build-aux-docs")
543 fn parse_check_stdout(&self, line
: &str) -> bool
{
544 self.parse_name_directive(line
, "check-stdout")
547 fn parse_check_run_results(&self, line
: &str) -> bool
{
548 self.parse_name_directive(line
, "check-run-results")
551 fn parse_dont_check_compiler_stdout(&self, line
: &str) -> bool
{
552 self.parse_name_directive(line
, "dont-check-compiler-stdout")
555 fn parse_dont_check_compiler_stderr(&self, line
: &str) -> bool
{
556 self.parse_name_directive(line
, "dont-check-compiler-stderr")
559 fn parse_no_prefer_dynamic(&self, line
: &str) -> bool
{
560 self.parse_name_directive(line
, "no-prefer-dynamic")
563 fn parse_pretty_expanded(&self, line
: &str) -> bool
{
564 self.parse_name_directive(line
, "pretty-expanded")
567 fn parse_pretty_mode(&self, line
: &str) -> Option
<String
> {
568 self.parse_name_value_directive(line
, "pretty-mode")
571 fn parse_pretty_compare_only(&self, line
: &str) -> bool
{
572 self.parse_name_directive(line
, "pretty-compare-only")
575 fn parse_failure_status(&self, line
: &str) -> Option
<i32> {
576 match self.parse_name_value_directive(line
, "failure-status") {
577 Some(code
) => code
.trim().parse
::<i32>().ok(),
582 fn parse_check_test_line_numbers_match(&self, line
: &str) -> bool
{
583 self.parse_name_directive(line
, "check-test-line-numbers-match")
586 fn parse_ignore_pass(&self, line
: &str) -> bool
{
587 self.parse_name_directive(line
, "ignore-pass")
590 fn parse_stderr_per_bitwidth(&self, line
: &str) -> bool
{
591 self.parse_name_directive(line
, "stderr-per-bitwidth")
594 fn parse_assembly_output(&self, line
: &str) -> Option
<String
> {
595 self.parse_name_value_directive(line
, "assembly-output").map(|r
| r
.trim().to_string())
598 fn parse_env(&self, line
: &str, name
: &str) -> Option
<(String
, String
)> {
599 self.parse_name_value_directive(line
, name
).map(|nv
| {
600 // nv is either FOO or FOO=BAR
601 let mut strs
: Vec
<String
> = nv
.splitn(2, '
='
).map(str::to_owned
).collect();
604 1 => (strs
.pop().unwrap(), String
::new()),
606 let end
= strs
.pop().unwrap();
607 (strs
.pop().unwrap(), end
)
609 n
=> panic
!("Expected 1 or 2 strings, not {}", n
),
614 fn parse_pp_exact(&self, line
: &str, testfile
: &Path
) -> Option
<PathBuf
> {
615 if let Some(s
) = self.parse_name_value_directive(line
, "pp-exact") {
616 Some(PathBuf
::from(&s
))
617 } else if self.parse_name_directive(line
, "pp-exact") {
618 testfile
.file_name().map(PathBuf
::from
)
624 fn parse_custom_normalization(&self, mut line
: &str, prefix
: &str) -> Option
<(String
, String
)> {
625 if self.parse_cfg_name_directive(line
, prefix
) == ParsedNameDirective
::Match
{
626 let from
= parse_normalization_string(&mut line
)?
;
627 let to
= parse_normalization_string(&mut line
)?
;
634 fn parse_needs_matching_clang(&self, line
: &str) -> bool
{
635 self.parse_name_directive(line
, "needs-matching-clang")
638 fn parse_needs_profiler_support(&self, line
: &str) -> bool
{
639 self.parse_name_directive(line
, "needs-profiler-support")
642 /// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
643 /// or `normalize-stderr-32bit`.
644 fn parse_cfg_name_directive(&self, line
: &str, prefix
: &str) -> ParsedNameDirective
{
645 if !line
.as_bytes().starts_with(prefix
.as_bytes()) {
646 return ParsedNameDirective
::NoMatch
;
648 if line
.as_bytes().get(prefix
.len()) != Some(&b'
-'
) {
649 return ParsedNameDirective
::NoMatch
;
652 let name
= line
[prefix
.len() + 1..].split(&['
:'
, ' '
][..]).next().unwrap();
654 let is_match
= name
== "test" ||
655 self.target
== name
|| // triple
656 util
::matches_os(&self.target
, name
) || // target
657 util
::matches_env(&self.target
, name
) || // env
658 self.target
.ends_with(name
) || // target and env
659 name
== util
::get_arch(&self.target
) || // architecture
660 name
== util
::get_pointer_width(&self.target
) || // pointer width
661 name
== self.stage_id
.split('
-'
).next().unwrap() || // stage
662 name
== self.channel
|| // channel
663 (self.target
!= self.host
&& name
== "cross-compile") ||
664 (name
== "endian-big" && util
::is_big_endian(&self.target
)) ||
665 (self.remote_test_client
.is_some() && name
== "remote") ||
666 match self.compare_mode
{
667 Some(CompareMode
::Nll
) => name
== "compare-mode-nll",
668 Some(CompareMode
::Polonius
) => name
== "compare-mode-polonius",
669 Some(CompareMode
::Chalk
) => name
== "compare-mode-chalk",
670 Some(CompareMode
::SplitDwarf
) => name
== "compare-mode-split-dwarf",
671 Some(CompareMode
::SplitDwarfSingle
) => name
== "compare-mode-split-dwarf-single",
674 (cfg
!(debug_assertions
) && name
== "debug") ||
675 match self.debugger
{
676 Some(Debugger
::Cdb
) => name
== "cdb",
677 Some(Debugger
::Gdb
) => name
== "gdb",
678 Some(Debugger
::Lldb
) => name
== "lldb",
682 if is_match { ParsedNameDirective::Match }
else { ParsedNameDirective::NoMatch }
685 fn has_cfg_prefix(&self, line
: &str, prefix
: &str) -> bool
{
686 // returns whether this line contains this prefix or not. For prefix
687 // "ignore", returns true if line says "ignore-x86_64", "ignore-arch",
688 // "ignore-android" etc.
689 line
.starts_with(prefix
) && line
.as_bytes().get(prefix
.len()) == Some(&b'
-'
)
692 fn parse_name_directive(&self, line
: &str, directive
: &str) -> bool
{
693 // Ensure the directive is a whole word. Do not match "ignore-x86" when
694 // the line says "ignore-x86_64".
695 line
.starts_with(directive
)
696 && matches
!(line
.as_bytes().get(directive
.len()), None
| Some(&b' '
) | Some(&b'
:'
))
699 pub fn parse_name_value_directive(&self, line
: &str, directive
: &str) -> Option
<String
> {
700 let colon
= directive
.len();
701 if line
.starts_with(directive
) && line
.as_bytes().get(colon
) == Some(&b'
:'
) {
702 let value
= line
[(colon
+ 1)..].to_owned();
703 debug
!("{}: {}", directive
, value
);
704 Some(expand_variables(value
, self))
710 pub fn find_rust_src_root(&self) -> Option
<PathBuf
> {
711 let mut path
= self.src_base
.clone();
712 let path_postfix
= Path
::new("src/etc/lldb_batchmode.py");
715 if path
.join(&path_postfix
).is_file() {
723 fn parse_run_rustfix(&self, line
: &str) -> bool
{
724 self.parse_name_directive(line
, "run-rustfix")
727 fn parse_rustfix_only_machine_applicable(&self, line
: &str) -> bool
{
728 self.parse_name_directive(line
, "rustfix-only-machine-applicable")
731 fn parse_edition(&self, line
: &str) -> Option
<String
> {
732 self.parse_name_value_directive(line
, "edition")
736 fn expand_variables(mut value
: String
, config
: &Config
) -> String
{
737 const CWD
: &str = "{{cwd}}";
738 const SRC_BASE
: &str = "{{src-base}}";
739 const BUILD_BASE
: &str = "{{build-base}}";
741 if value
.contains(CWD
) {
742 let cwd
= env
::current_dir().unwrap();
743 value
= value
.replace(CWD
, &cwd
.to_string_lossy());
746 if value
.contains(SRC_BASE
) {
747 value
= value
.replace(SRC_BASE
, &config
.src_base
.to_string_lossy());
750 if value
.contains(BUILD_BASE
) {
751 value
= value
.replace(BUILD_BASE
, &config
.build_base
.to_string_lossy());
757 /// Finds the next quoted string `"..."` in `line`, and extract the content from it. Move the `line`
758 /// variable after the end of the quoted string.
763 /// let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
764 /// let first = parse_normalization_string(&mut s);
765 /// assert_eq!(first, Some("something (32 bits)".to_owned()));
766 /// assert_eq!(s, " -> \"something ($WORD bits)\".");
768 fn parse_normalization_string(line
: &mut &str) -> Option
<String
> {
769 // FIXME support escapes in strings.
770 let begin
= line
.find('
"')? + 1;
771 let end = line[begin..].find('"'
)?
+ begin
;
772 let result
= line
[begin
..end
].to_owned();
773 *line
= &line
[end
+ 1..];
777 pub fn extract_llvm_version(version
: &str) -> Option
<u32> {
778 let pat
= |c
: char| !c
.is_ascii_digit() && c
!= '
.'
;
779 let version_without_suffix
= match version
.find(pat
) {
780 Some(pos
) => &version
[..pos
],
783 let components
: Vec
<u32> = version_without_suffix
785 .map(|s
| s
.parse().expect("Malformed version component"))
787 let version
= match *components
{
789 [a
, b
] => a
* 10_000 + b
* 100,
790 [a
, b
, c
] => a
* 10_000 + b
* 100 + c
,
791 _
=> panic
!("Malformed version"),
796 /// Takes a directive of the form "<version1> [- <version2>]",
797 /// returns the numeric representation of <version1> and <version2> as
798 /// tuple: (<version1> as u32, <version2> as u32)
800 /// If the <version2> part is omitted, the second component of the tuple
801 /// is the same as <version1>.
802 fn extract_version_range
<F
>(line
: &str, parse
: F
) -> Option
<(u32, u32)>
804 F
: Fn(&str) -> Option
<u32>,
806 let mut splits
= line
.splitn(2, "- ").map(str::trim
);
807 let min
= splits
.next().unwrap();
808 if min
.ends_with('
-'
) {
812 let max
= splits
.next();
818 let min
= parse(min
)?
;
819 let max
= match max
{
820 Some(max
) if max
.is_empty() => return None
,
821 Some(max
) => parse(max
)?
,
828 pub fn make_test_description
<R
: Read
>(
830 name
: test
::TestName
,
834 ) -> test
::TestDesc
{
835 let mut ignore
= false;
836 let mut should_fail
= false;
838 let rustc_has_profiler_support
= env
::var_os("RUSTC_PROFILER_SUPPORT").is_some();
839 let rustc_has_sanitizer_support
= env
::var_os("RUSTC_SANITIZER_SUPPORT").is_some();
840 let has_asm_support
= util
::has_asm_support(&config
.target
);
841 let has_asan
= util
::ASAN_SUPPORTED_TARGETS
.contains(&&*config
.target
);
842 let has_lsan
= util
::LSAN_SUPPORTED_TARGETS
.contains(&&*config
.target
);
843 let has_msan
= util
::MSAN_SUPPORTED_TARGETS
.contains(&&*config
.target
);
844 let has_tsan
= util
::TSAN_SUPPORTED_TARGETS
.contains(&&*config
.target
);
845 let has_hwasan
= util
::HWASAN_SUPPORTED_TARGETS
.contains(&&*config
.target
);
846 // for `-Z gcc-ld=lld`
847 let has_rust_lld
= config
850 .join(&config
.target
)
853 .join(if config
.host
.contains("windows") { "ld.exe" }
else { "ld" }
)
855 iter_header(path
, src
, &mut |revision
, ln
| {
856 if revision
.is_some() && revision
!= cfg
{
859 ignore
= match config
.parse_cfg_name_directive(ln
, "ignore") {
860 ParsedNameDirective
::Match
=> true,
861 ParsedNameDirective
::NoMatch
=> ignore
,
863 if config
.has_cfg_prefix(ln
, "only") {
864 ignore
= match config
.parse_cfg_name_directive(ln
, "only") {
865 ParsedNameDirective
::Match
=> ignore
,
866 ParsedNameDirective
::NoMatch
=> true,
869 ignore
|= ignore_llvm(config
, ln
);
871 config
.run_clang_based_tests_with
.is_none() && config
.parse_needs_matching_clang(ln
);
872 ignore
|= !has_asm_support
&& config
.parse_name_directive(ln
, "needs-asm-support");
873 ignore
|= !rustc_has_profiler_support
&& config
.parse_needs_profiler_support(ln
);
874 ignore
|= !config
.run_enabled() && config
.parse_name_directive(ln
, "needs-run-enabled");
875 ignore
|= !rustc_has_sanitizer_support
876 && config
.parse_name_directive(ln
, "needs-sanitizer-support");
877 ignore
|= !has_asan
&& config
.parse_name_directive(ln
, "needs-sanitizer-address");
878 ignore
|= !has_lsan
&& config
.parse_name_directive(ln
, "needs-sanitizer-leak");
879 ignore
|= !has_msan
&& config
.parse_name_directive(ln
, "needs-sanitizer-memory");
880 ignore
|= !has_tsan
&& config
.parse_name_directive(ln
, "needs-sanitizer-thread");
881 ignore
|= !has_hwasan
&& config
.parse_name_directive(ln
, "needs-sanitizer-hwaddress");
882 ignore
|= config
.target_panic
== PanicStrategy
::Abort
883 && config
.parse_name_directive(ln
, "needs-unwind");
884 ignore
|= config
.target
== "wasm32-unknown-unknown" && config
.parse_check_run_results(ln
);
885 ignore
|= config
.debugger
== Some(Debugger
::Cdb
) && ignore_cdb(config
, ln
);
886 ignore
|= config
.debugger
== Some(Debugger
::Gdb
) && ignore_gdb(config
, ln
);
887 ignore
|= config
.debugger
== Some(Debugger
::Lldb
) && ignore_lldb(config
, ln
);
888 ignore
|= !has_rust_lld
&& config
.parse_name_directive(ln
, "needs-rust-lld");
889 should_fail
|= config
.parse_name_directive(ln
, "should-fail");
892 // The `should-fail` annotation doesn't apply to pretty tests,
893 // since we run the pretty printer across all tests by default.
894 // If desired, we could add a `should-fail-pretty` annotation.
895 let should_panic
= match config
.mode
{
896 crate::common
::Pretty
=> test
::ShouldPanic
::No
,
897 _
if should_fail
=> test
::ShouldPanic
::Yes
,
898 _
=> test
::ShouldPanic
::No
,
908 test_type
: test
::TestType
::Unknown
,
912 fn ignore_cdb(config
: &Config
, line
: &str) -> bool
{
913 if let Some(actual_version
) = config
.cdb_version
{
914 if let Some(min_version
) = line
.strip_prefix("min-cdb-version:").map(str::trim
) {
915 let min_version
= extract_cdb_version(min_version
).unwrap_or_else(|| {
916 panic
!("couldn't parse version range: {:?}", min_version
);
919 // Ignore if actual version is smaller than the minimum
921 return actual_version
< min_version
;
927 fn ignore_gdb(config
: &Config
, line
: &str) -> bool
{
928 if let Some(actual_version
) = config
.gdb_version
{
929 if let Some(rest
) = line
.strip_prefix("min-gdb-version:").map(str::trim
) {
930 let (start_ver
, end_ver
) = extract_version_range(rest
, extract_gdb_version
)
932 panic
!("couldn't parse version range: {:?}", rest
);
935 if start_ver
!= end_ver
{
936 panic
!("Expected single GDB version")
938 // Ignore if actual version is smaller than the minimum
940 return actual_version
< start_ver
;
941 } else if let Some(rest
) = line
.strip_prefix("ignore-gdb-version:").map(str::trim
) {
942 let (min_version
, max_version
) = extract_version_range(rest
, extract_gdb_version
)
944 panic
!("couldn't parse version range: {:?}", rest
);
947 if max_version
< min_version
{
948 panic
!("Malformed GDB version range: max < min")
951 return actual_version
>= min_version
&& actual_version
<= max_version
;
957 fn ignore_lldb(config
: &Config
, line
: &str) -> bool
{
958 if let Some(actual_version
) = config
.lldb_version
{
959 if let Some(min_version
) = line
.strip_prefix("min-lldb-version:").map(str::trim
) {
960 let min_version
= min_version
.parse().unwrap_or_else(|e
| {
961 panic
!("Unexpected format of LLDB version string: {}\n{:?}", min_version
, e
);
963 // Ignore if actual version is smaller the minimum required
965 actual_version
< min_version
967 line
.starts_with("rust-lldb") && !config
.lldb_native_rust
974 fn ignore_llvm(config
: &Config
, line
: &str) -> bool
{
975 if config
.system_llvm
&& line
.starts_with("no-system-llvm") {
978 if let Some(needed_components
) =
979 config
.parse_name_value_directive(line
, "needs-llvm-components")
981 let components
: HashSet
<_
> = config
.llvm_components
.split_whitespace().collect();
982 if let Some(missing_component
) = needed_components
984 .find(|needed_component
| !components
.contains(needed_component
))
986 if env
::var_os("COMPILETEST_NEEDS_ALL_LLVM_COMPONENTS").is_some() {
987 panic
!("missing LLVM component: {}", missing_component
);
992 if let Some(actual_version
) = config
.llvm_version
{
993 if let Some(rest
) = line
.strip_prefix("min-llvm-version:").map(str::trim
) {
994 let min_version
= extract_llvm_version(rest
).unwrap();
995 // Ignore if actual version is smaller the minimum required
997 actual_version
< min_version
998 } else if let Some(rest
) = line
.strip_prefix("min-system-llvm-version:").map(str::trim
) {
999 let min_version
= extract_llvm_version(rest
).unwrap();
1000 // Ignore if using system LLVM and actual version
1001 // is smaller the minimum required version
1002 config
.system_llvm
&& actual_version
< min_version
1003 } else if let Some(rest
) = line
.strip_prefix("ignore-llvm-version:").map(str::trim
) {
1004 // Syntax is: "ignore-llvm-version: <version1> [- <version2>]"
1005 let (v_min
, v_max
) =
1006 extract_version_range(rest
, extract_llvm_version
).unwrap_or_else(|| {
1007 panic
!("couldn't parse version range: {:?}", rest
);
1010 panic
!("Malformed LLVM version range: max < min")
1012 // Ignore if version lies inside of range.
1013 actual_version
>= v_min
&& actual_version
<= v_max