3 use std
::io
::prelude
::*;
4 use std
::io
::BufReader
;
5 use std
::path
::{Path, PathBuf}
;
9 use crate::common
::{self, CompareMode, Config, Mode, PassMode}
;
11 use crate::extract_gdb_version
;
16 /// Whether to ignore the test.
17 #[derive(Clone, Copy, PartialEq, Debug)]
21 /// Ignore it totally.
23 /// Ignore only the gdb test, but run the lldb test.
25 /// Ignore only the lldb test, but run the gdb test.
30 pub fn can_run_gdb(&self) -> bool
{
31 *self == Ignore
::Run
|| *self == Ignore
::IgnoreLldb
34 pub fn can_run_lldb(&self) -> bool
{
35 *self == Ignore
::Run
|| *self == Ignore
::IgnoreGdb
38 pub fn no_gdb(&self) -> Ignore
{
40 Ignore
::Run
=> Ignore
::IgnoreGdb
,
41 Ignore
::IgnoreGdb
=> Ignore
::IgnoreGdb
,
46 pub fn no_lldb(&self) -> Ignore
{
48 Ignore
::Run
=> Ignore
::IgnoreLldb
,
49 Ignore
::IgnoreLldb
=> Ignore
::IgnoreLldb
,
55 /// The result of parse_cfg_name_directive.
56 #[derive(Clone, Copy, PartialEq, Debug)]
57 enum ParsedNameDirective
{
62 /// Mode was DebugInfoGdbLldb and this matched gdb.
64 /// Mode was DebugInfoGdbLldb and this matched lldb.
68 /// Properties which must be known very early, before actually running
70 pub struct EarlyProps
{
72 pub should_fail
: bool
,
74 pub aux_crate
: Vec
<(String
, String
)>,
75 pub revisions
: Vec
<String
>,
79 pub fn from_file(config
: &Config
, testfile
: &Path
) -> Self {
80 let mut props
= EarlyProps
{
84 aux_crate
: Vec
::new(),
88 if config
.mode
== common
::DebugInfoGdbLldb
{
89 if config
.lldb_python_dir
.is_none() {
90 props
.ignore
= props
.ignore
.no_lldb();
92 if config
.gdb_version
.is_none() {
93 props
.ignore
= props
.ignore
.no_gdb();
95 } else if config
.mode
== common
::DebugInfoCdb
{
96 if config
.cdb
.is_none() {
97 props
.ignore
= Ignore
::Ignore
;
101 let rustc_has_profiler_support
= env
::var_os("RUSTC_PROFILER_SUPPORT").is_some();
102 let rustc_has_sanitizer_support
= env
::var_os("RUSTC_SANITIZER_SUPPORT").is_some();
104 iter_header(testfile
, None
, &mut |ln
| {
105 // we should check if any only-<platform> exists and if it exists
106 // and does not matches the current platform, skip the test
107 if props
.ignore
!= Ignore
::Ignore
{
108 props
.ignore
= match config
.parse_cfg_name_directive(ln
, "ignore") {
109 ParsedNameDirective
::Match
=> Ignore
::Ignore
,
110 ParsedNameDirective
::NoMatch
=> props
.ignore
,
111 ParsedNameDirective
::MatchGdb
=> props
.ignore
.no_gdb(),
112 ParsedNameDirective
::MatchLldb
=> props
.ignore
.no_lldb(),
115 if config
.has_cfg_prefix(ln
, "only") {
116 props
.ignore
= match config
.parse_cfg_name_directive(ln
, "only") {
117 ParsedNameDirective
::Match
=> props
.ignore
,
118 ParsedNameDirective
::NoMatch
=> Ignore
::Ignore
,
119 ParsedNameDirective
::MatchLldb
=> props
.ignore
.no_gdb(),
120 ParsedNameDirective
::MatchGdb
=> props
.ignore
.no_lldb(),
124 if ignore_llvm(config
, ln
) {
125 props
.ignore
= Ignore
::Ignore
;
128 if config
.run_clang_based_tests_with
.is_none() &&
129 config
.parse_needs_matching_clang(ln
) {
130 props
.ignore
= Ignore
::Ignore
;
133 if !rustc_has_profiler_support
&&
134 config
.parse_needs_profiler_support(ln
) {
135 props
.ignore
= Ignore
::Ignore
;
138 if !rustc_has_sanitizer_support
&&
139 config
.parse_needs_sanitizer_support(ln
) {
140 props
.ignore
= Ignore
::Ignore
;
143 if config
.target
== "wasm32-unknown-unknown" && config
.parse_check_run_results(ln
) {
144 props
.ignore
= Ignore
::Ignore
;
148 if (config
.mode
== common
::DebugInfoGdb
|| config
.mode
== common
::DebugInfoGdbLldb
) &&
149 props
.ignore
.can_run_gdb() && ignore_gdb(config
, ln
) {
150 props
.ignore
= props
.ignore
.no_gdb();
153 if (config
.mode
== common
::DebugInfoLldb
|| config
.mode
== common
::DebugInfoGdbLldb
) &&
154 props
.ignore
.can_run_lldb() && ignore_lldb(config
, ln
) {
155 props
.ignore
= props
.ignore
.no_lldb();
158 if let Some(s
) = config
.parse_aux_build(ln
) {
162 if let Some(ac
) = config
.parse_aux_crate(ln
) {
163 props
.aux_crate
.push(ac
);
166 if let Some(r
) = config
.parse_revisions(ln
) {
167 props
.revisions
.extend(r
);
170 props
.should_fail
= props
.should_fail
|| config
.parse_name_directive(ln
, "should-fail");
175 fn ignore_gdb(config
: &Config
, line
: &str) -> bool
{
176 if let Some(actual_version
) = config
.gdb_version
{
177 if line
.starts_with("min-gdb-version") {
178 let (start_ver
, end_ver
) = extract_gdb_version_range(line
);
180 if start_ver
!= end_ver
{
181 panic
!("Expected single GDB version")
183 // Ignore if actual version is smaller the minimum required
185 actual_version
< start_ver
186 } else if line
.starts_with("ignore-gdb-version") {
187 let (min_version
, max_version
) = extract_gdb_version_range(line
);
189 if max_version
< min_version
{
190 panic
!("Malformed GDB version range: max < min")
193 actual_version
>= min_version
&& actual_version
<= max_version
202 // Takes a directive of the form "ignore-gdb-version <version1> [- <version2>]",
203 // returns the numeric representation of <version1> and <version2> as
204 // tuple: (<version1> as u32, <version2> as u32)
205 // If the <version2> part is omitted, the second component of the tuple
206 // is the same as <version1>.
207 fn extract_gdb_version_range(line
: &str) -> (u32, u32) {
208 const ERROR_MESSAGE
: &'
static str = "Malformed GDB version directive";
210 let range_components
= line
.split(&[' '
, '
-'
][..])
211 .filter(|word
| !word
.is_empty())
212 .map(extract_gdb_version
)
213 .skip_while(Option
::is_none
)
214 .take(3) // 3 or more = invalid, so take at most 3.
215 .collect
::<Vec
<Option
<u32>>>();
217 match range_components
.len() {
219 let v
= range_components
[0].unwrap();
223 let v_min
= range_components
[0].unwrap();
224 let v_max
= range_components
[1].expect(ERROR_MESSAGE
);
227 _
=> panic
!(ERROR_MESSAGE
),
231 fn ignore_lldb(config
: &Config
, line
: &str) -> bool
{
232 if let Some(ref actual_version
) = config
.lldb_version
{
233 if line
.starts_with("min-lldb-version") {
234 let min_version
= line
.trim_end()
237 .expect("Malformed lldb version directive");
238 // Ignore if actual version is smaller the minimum required
240 lldb_version_to_int(actual_version
) < lldb_version_to_int(min_version
)
241 } else if line
.starts_with("rust-lldb") && !config
.lldb_native_rust
{
251 fn ignore_llvm(config
: &Config
, line
: &str) -> bool
{
252 if config
.system_llvm
&& line
.starts_with("no-system-llvm") {
255 if let Some(ref actual_version
) = config
.llvm_version
{
256 if line
.starts_with("min-llvm-version") {
257 let min_version
= line
.trim_end()
260 .expect("Malformed llvm version directive");
261 // Ignore if actual version is smaller the minimum required
263 &actual_version
[..] < min_version
264 } else if line
.starts_with("min-system-llvm-version") {
265 let min_version
= line
.trim_end()
268 .expect("Malformed llvm version directive");
269 // Ignore if using system LLVM and actual version
270 // is smaller the minimum required version
271 config
.system_llvm
&& &actual_version
[..] < min_version
272 } else if line
.starts_with("ignore-llvm-version") {
273 // Syntax is: "ignore-llvm-version <version1> [- <version2>]"
274 let range_components
= line
.split(' '
)
275 .skip(1) // Skip the directive.
277 .filter(|word
| !word
.is_empty() && word
!= &"-")
278 .take(3) // 3 or more = invalid, so take at most 3.
279 .collect
::<Vec
<&str>>();
280 match range_components
.len() {
282 &actual_version
[..] == range_components
[0]
285 let v_min
= range_components
[0];
286 let v_max
= range_components
[1];
288 panic
!("Malformed LLVM version range: max < min")
290 // Ignore if version lies inside of range.
291 &actual_version
[..] >= v_min
&& &actual_version
[..] <= v_max
293 _
=> panic
!("Malformed LLVM version directive"),
305 #[derive(Clone, Debug)]
306 pub struct TestProps
{
307 // Lines that should be expected, in order, on standard out
308 pub error_patterns
: Vec
<String
>,
309 // Extra flags to pass to the compiler
310 pub compile_flags
: Vec
<String
>,
311 // Extra flags to pass when the compiled code is run (such as --bench)
312 pub run_flags
: Option
<String
>,
313 // If present, the name of a file that this test should match when
315 pub pp_exact
: Option
<PathBuf
>,
316 // Other crates that should be compiled (typically from the same
317 // directory as the test, but for backwards compatibility reasons
318 // we also check the auxiliary directory)
319 pub aux_builds
: Vec
<String
>,
320 // Similar to `aux_builds`, but a list of NAME=somelib.rs of dependencies
321 // to build and pass with the `--extern` flag.
322 pub aux_crates
: Vec
<(String
, String
)>,
323 // Environment settings to use for compiling
324 pub rustc_env
: Vec
<(String
, String
)>,
325 // Environment variables to unset prior to compiling.
326 // Variables are unset before applying 'rustc_env'.
327 pub unset_rustc_env
: Vec
<String
>,
328 // Environment settings to use during execution
329 pub exec_env
: Vec
<(String
, String
)>,
330 // Lines to check if they appear in the expected debugger output
331 pub check_lines
: Vec
<String
>,
332 // Build documentation for all specified aux-builds as well
333 pub build_aux_docs
: bool
,
334 // Flag to force a crate to be built with the host architecture
335 pub force_host
: bool
,
336 // Check stdout for error-pattern output as well as stderr
337 pub check_stdout
: bool
,
338 // Check stdout & stderr for output of run-pass test
339 pub check_run_results
: bool
,
340 // For UI tests, allows compiler to generate arbitrary output to stdout
341 pub dont_check_compiler_stdout
: bool
,
342 // For UI tests, allows compiler to generate arbitrary output to stderr
343 pub dont_check_compiler_stderr
: bool
,
344 // Don't force a --crate-type=dylib flag on the command line
346 // Set this for example if you have an auxiliary test file that contains
347 // a proc-macro and needs `#![crate_type = "proc-macro"]`. This ensures
348 // that the aux file is compiled as a `proc-macro` and not as a `dylib`.
349 pub no_prefer_dynamic
: bool
,
350 // Run --pretty expanded when running pretty printing tests
351 pub pretty_expanded
: bool
,
352 // Which pretty mode are we testing with, default to 'normal'
353 pub pretty_mode
: String
,
354 // Only compare pretty output and don't try compiling
355 pub pretty_compare_only
: bool
,
356 // Patterns which must not appear in the output of a cfail test.
357 pub forbid_output
: Vec
<String
>,
358 // Revisions to test for incremental compilation.
359 pub revisions
: Vec
<String
>,
360 // Directory (if any) to use for incremental compilation. This is
361 // not set by end-users; rather it is set by the incremental
362 // testing harness and used when generating compilation
363 // arguments. (In particular, it propagates to the aux-builds.)
364 pub incremental_dir
: Option
<PathBuf
>,
365 // How far should the test proceed while still passing.
366 pass_mode
: Option
<PassMode
>,
367 // Ignore `--pass` overrides from the command line for this test.
369 // rustdoc will test the output of the `--test` option
370 pub check_test_line_numbers_match
: bool
,
371 // Do not pass `-Z ui-testing` to UI tests
372 pub disable_ui_testing_normalization
: bool
,
373 // customized normalization rules
374 pub normalize_stdout
: Vec
<(String
, String
)>,
375 pub normalize_stderr
: Vec
<(String
, String
)>,
376 pub failure_status
: i32,
377 // Whether or not `rustfix` should apply the `CodeSuggestion`s of this test and compile the
378 // resulting Rust code.
379 pub run_rustfix
: bool
,
380 // If true, `rustfix` will only apply `MachineApplicable` suggestions.
381 pub rustfix_only_machine_applicable
: bool
,
382 pub assembly_output
: Option
<String
>,
383 // If true, the test is expected to ICE
384 pub should_ice
: bool
,
388 pub fn new() -> Self {
390 error_patterns
: vec
![],
391 compile_flags
: vec
![],
398 unset_rustc_env
: vec
![],
401 build_aux_docs
: false,
404 check_run_results
: false,
405 dont_check_compiler_stdout
: false,
406 dont_check_compiler_stderr
: false,
407 no_prefer_dynamic
: false,
408 pretty_expanded
: false,
409 pretty_mode
: "normal".to_string(),
410 pretty_compare_only
: false,
411 forbid_output
: vec
![],
412 incremental_dir
: None
,
415 check_test_line_numbers_match
: false,
416 disable_ui_testing_normalization
: false,
417 normalize_stdout
: vec
![],
418 normalize_stderr
: vec
![],
421 rustfix_only_machine_applicable
: false,
422 assembly_output
: None
,
427 pub fn from_aux_file(&self, testfile
: &Path
, cfg
: Option
<&str>, config
: &Config
) -> Self {
428 let mut props
= TestProps
::new();
430 // copy over select properties to the aux build:
431 props
.incremental_dir
= self.incremental_dir
.clone();
432 props
.load_from(testfile
, cfg
, config
);
437 pub fn from_file(testfile
: &Path
, cfg
: Option
<&str>, config
: &Config
) -> Self {
438 let mut props
= TestProps
::new();
439 props
.load_from(testfile
, cfg
, config
);
443 /// Loads properties from `testfile` into `props`. If a property is
444 /// tied to a particular revision `foo` (indicated by writing
445 /// `//[foo]`), then the property is ignored unless `cfg` is
447 fn load_from(&mut self, testfile
: &Path
, cfg
: Option
<&str>, config
: &Config
) {
448 iter_header(testfile
, cfg
, &mut |ln
| {
449 if let Some(ep
) = config
.parse_error_pattern(ln
) {
450 self.error_patterns
.push(ep
);
453 if let Some(flags
) = config
.parse_compile_flags(ln
) {
455 .extend(flags
.split_whitespace().map(|s
| s
.to_owned()));
458 if let Some(edition
) = config
.parse_edition(ln
) {
459 self.compile_flags
.push(format
!("--edition={}", edition
));
462 if let Some(r
) = config
.parse_revisions(ln
) {
463 self.revisions
.extend(r
);
466 if self.run_flags
.is_none() {
467 self.run_flags
= config
.parse_run_flags(ln
);
470 if self.pp_exact
.is_none() {
471 self.pp_exact
= config
.parse_pp_exact(ln
, testfile
);
474 if !self.should_ice
{
475 self.should_ice
= config
.parse_should_ice(ln
);
478 if !self.build_aux_docs
{
479 self.build_aux_docs
= config
.parse_build_aux_docs(ln
);
482 if !self.force_host
{
483 self.force_host
= config
.parse_force_host(ln
);
486 if !self.check_stdout
{
487 self.check_stdout
= config
.parse_check_stdout(ln
);
490 if !self.check_run_results
{
491 self.check_run_results
= config
.parse_check_run_results(ln
);
494 if !self.dont_check_compiler_stdout
{
495 self.dont_check_compiler_stdout
= config
.parse_dont_check_compiler_stdout(ln
);
498 if !self.dont_check_compiler_stderr
{
499 self.dont_check_compiler_stderr
= config
.parse_dont_check_compiler_stderr(ln
);
502 if !self.no_prefer_dynamic
{
503 self.no_prefer_dynamic
= config
.parse_no_prefer_dynamic(ln
);
506 if !self.pretty_expanded
{
507 self.pretty_expanded
= config
.parse_pretty_expanded(ln
);
510 if let Some(m
) = config
.parse_pretty_mode(ln
) {
511 self.pretty_mode
= m
;
514 if !self.pretty_compare_only
{
515 self.pretty_compare_only
= config
.parse_pretty_compare_only(ln
);
518 if let Some(ab
) = config
.parse_aux_build(ln
) {
519 self.aux_builds
.push(ab
);
522 if let Some(ac
) = config
.parse_aux_crate(ln
) {
523 self.aux_crates
.push(ac
);
526 if let Some(ee
) = config
.parse_env(ln
, "exec-env") {
527 self.exec_env
.push(ee
);
530 if let Some(ee
) = config
.parse_env(ln
, "rustc-env") {
531 self.rustc_env
.push(ee
);
534 if let Some(ev
) = config
.parse_name_value_directive(ln
, "unset-rustc-env") {
535 self.unset_rustc_env
.push(ev
);
538 if let Some(cl
) = config
.parse_check_line(ln
) {
539 self.check_lines
.push(cl
);
542 if let Some(of
) = config
.parse_forbid_output(ln
) {
543 self.forbid_output
.push(of
);
546 if !self.check_test_line_numbers_match
{
547 self.check_test_line_numbers_match
= config
.parse_check_test_line_numbers_match(ln
);
550 self.update_pass_mode(ln
, cfg
, config
);
552 if !self.ignore_pass
{
553 self.ignore_pass
= config
.parse_ignore_pass(ln
);
556 if !self.disable_ui_testing_normalization
{
557 self.disable_ui_testing_normalization
=
558 config
.parse_disable_ui_testing_normalization(ln
);
561 if let Some(rule
) = config
.parse_custom_normalization(ln
, "normalize-stdout") {
562 self.normalize_stdout
.push(rule
);
564 if let Some(rule
) = config
.parse_custom_normalization(ln
, "normalize-stderr") {
565 self.normalize_stderr
.push(rule
);
568 if let Some(code
) = config
.parse_failure_status(ln
) {
569 self.failure_status
= code
;
572 if !self.run_rustfix
{
573 self.run_rustfix
= config
.parse_run_rustfix(ln
);
576 if !self.rustfix_only_machine_applicable
{
577 self.rustfix_only_machine_applicable
=
578 config
.parse_rustfix_only_machine_applicable(ln
);
581 if self.assembly_output
.is_none() {
582 self.assembly_output
= config
.parse_assembly_output(ln
);
586 if self.failure_status
== -1 {
587 self.failure_status
= match config
.mode
{
588 Mode
::RunFail
=> 101,
593 self.failure_status
= 101;
596 for key
in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
597 if let Ok(val
) = env
::var(key
) {
598 if self.exec_env
.iter().find(|&&(ref x
, _
)| x
== key
).is_none() {
599 self.exec_env
.push(((*key
).to_owned(), val
))
605 fn update_pass_mode(&mut self, ln
: &str, revision
: Option
<&str>, config
: &Config
) {
606 let check_no_run
= |s
| {
607 if config
.mode
!= Mode
::Ui
&& config
.mode
!= Mode
::Incremental
{
608 panic
!("`{}` header is only supported in UI and incremental tests", s
);
610 if config
.mode
== Mode
::Incremental
&&
611 !revision
.map_or(false, |r
| r
.starts_with("cfail")) &&
612 !self.revisions
.iter().all(|r
| r
.starts_with("cfail")) {
613 panic
!("`{}` header is only supported in `cfail` incremental tests", s
);
616 let pass_mode
= if config
.parse_name_directive(ln
, "check-pass") {
617 check_no_run("check-pass");
618 Some(PassMode
::Check
)
619 } else if config
.parse_name_directive(ln
, "build-pass") {
620 check_no_run("build-pass");
621 Some(PassMode
::Build
)
622 } else if config
.parse_name_directive(ln
, "run-pass") {
623 if config
.mode
!= Mode
::Ui
{
624 panic
!("`run-pass` header is only supported in UI tests")
627 } else if config
.parse_name_directive(ln
, "run-fail") {
628 if config
.mode
!= Mode
::Ui
{
629 panic
!("`run-fail` header is only supported in UI tests")
631 Some(PassMode
::RunFail
)
635 match (self.pass_mode
, pass_mode
) {
636 (None
, Some(_
)) => self.pass_mode
= pass_mode
,
637 (Some(_
), Some(_
)) => panic
!("multiple `*-pass` headers in a single test"),
642 pub fn pass_mode(&self, config
: &Config
) -> Option
<PassMode
> {
643 if !self.ignore_pass
{
644 if let (mode @
Some(_
), Some(_
)) = (config
.force_pass_mode
, self.pass_mode
) {
651 // does not consider CLI override for pass mode
652 pub fn local_pass_mode(&self) -> Option
<PassMode
> {
657 fn iter_header(testfile
: &Path
, cfg
: Option
<&str>, it
: &mut dyn FnMut(&str)) {
658 if testfile
.is_dir() {
662 let comment
= if testfile
.to_string_lossy().ends_with(".rs") {
668 // FIXME: would be nice to allow some whitespace between comment and brace :)
669 // It took me like 2 days to debug why compile-flags weren’t taken into account for my test :)
670 let comment_with_brace
= comment
.to_string() + "[";
672 let rdr
= BufReader
::new(File
::open(testfile
).unwrap());
673 for ln
in rdr
.lines() {
674 // Assume that any directives will be found before the first
675 // module or function. This doesn't seem to be an optimization
676 // with a warm page cache. Maybe with a cold one.
677 let ln
= ln
.unwrap();
679 if ln
.starts_with("fn") || ln
.starts_with("mod") {
681 } else if ln
.starts_with(&comment_with_brace
) {
682 // A comment like `//[foo]` is specific to revision `foo`
683 if let Some(close_brace
) = ln
.find('
]'
) {
684 let open_brace
= ln
.find('
['
).unwrap();
685 let lncfg
= &ln
[open_brace
+ 1 .. close_brace
];
686 let matches
= match cfg
{
687 Some(s
) => s
== &lncfg
[..],
691 it(ln
[(close_brace
+ 1)..].trim_start());
694 panic
!("malformed condition directive: expected `{}foo]`, found `{}`",
695 comment_with_brace
, ln
)
697 } else if ln
.starts_with(comment
) {
698 it(ln
[comment
.len() ..].trim_start());
705 fn parse_should_ice(&self, line
: &str) -> bool
{
706 self.parse_name_directive(line
, "should-ice")
708 fn parse_error_pattern(&self, line
: &str) -> Option
<String
> {
709 self.parse_name_value_directive(line
, "error-pattern")
712 fn parse_forbid_output(&self, line
: &str) -> Option
<String
> {
713 self.parse_name_value_directive(line
, "forbid-output")
716 fn parse_aux_build(&self, line
: &str) -> Option
<String
> {
717 self.parse_name_value_directive(line
, "aux-build")
718 .map(|r
| r
.trim().to_string())
721 fn parse_aux_crate(&self, line
: &str) -> Option
<(String
, String
)> {
722 self.parse_name_value_directive(line
, "aux-crate").map(|r
| {
723 let mut parts
= r
.trim().splitn(2, '
='
);
725 parts
.next().expect("aux-crate name").to_string(),
726 parts
.next().expect("aux-crate value").to_string(),
731 fn parse_compile_flags(&self, line
: &str) -> Option
<String
> {
732 self.parse_name_value_directive(line
, "compile-flags")
735 fn parse_revisions(&self, line
: &str) -> Option
<Vec
<String
>> {
736 self.parse_name_value_directive(line
, "revisions")
737 .map(|r
| r
.split_whitespace().map(|t
| t
.to_string()).collect())
740 fn parse_run_flags(&self, line
: &str) -> Option
<String
> {
741 self.parse_name_value_directive(line
, "run-flags")
744 fn parse_check_line(&self, line
: &str) -> Option
<String
> {
745 self.parse_name_value_directive(line
, "check")
748 fn parse_force_host(&self, line
: &str) -> bool
{
749 self.parse_name_directive(line
, "force-host")
752 fn parse_build_aux_docs(&self, line
: &str) -> bool
{
753 self.parse_name_directive(line
, "build-aux-docs")
756 fn parse_check_stdout(&self, line
: &str) -> bool
{
757 self.parse_name_directive(line
, "check-stdout")
760 fn parse_check_run_results(&self, line
: &str) -> bool
{
761 self.parse_name_directive(line
, "check-run-results")
764 fn parse_dont_check_compiler_stdout(&self, line
: &str) -> bool
{
765 self.parse_name_directive(line
, "dont-check-compiler-stdout")
768 fn parse_dont_check_compiler_stderr(&self, line
: &str) -> bool
{
769 self.parse_name_directive(line
, "dont-check-compiler-stderr")
772 fn parse_no_prefer_dynamic(&self, line
: &str) -> bool
{
773 self.parse_name_directive(line
, "no-prefer-dynamic")
776 fn parse_pretty_expanded(&self, line
: &str) -> bool
{
777 self.parse_name_directive(line
, "pretty-expanded")
780 fn parse_pretty_mode(&self, line
: &str) -> Option
<String
> {
781 self.parse_name_value_directive(line
, "pretty-mode")
784 fn parse_pretty_compare_only(&self, line
: &str) -> bool
{
785 self.parse_name_directive(line
, "pretty-compare-only")
788 fn parse_failure_status(&self, line
: &str) -> Option
<i32> {
789 match self.parse_name_value_directive(line
, "failure-status") {
790 Some(code
) => code
.trim().parse
::<i32>().ok(),
795 fn parse_disable_ui_testing_normalization(&self, line
: &str) -> bool
{
796 self.parse_name_directive(line
, "disable-ui-testing-normalization")
799 fn parse_check_test_line_numbers_match(&self, line
: &str) -> bool
{
800 self.parse_name_directive(line
, "check-test-line-numbers-match")
803 fn parse_ignore_pass(&self, line
: &str) -> bool
{
804 self.parse_name_directive(line
, "ignore-pass")
807 fn parse_assembly_output(&self, line
: &str) -> Option
<String
> {
808 self.parse_name_value_directive(line
, "assembly-output")
809 .map(|r
| r
.trim().to_string())
812 fn parse_env(&self, line
: &str, name
: &str) -> Option
<(String
, String
)> {
813 self.parse_name_value_directive(line
, name
).map(|nv
| {
814 // nv is either FOO or FOO=BAR
815 let mut strs
: Vec
<String
> = nv
.splitn(2, '
='
).map(str::to_owned
).collect();
818 1 => (strs
.pop().unwrap(), String
::new()),
820 let end
= strs
.pop().unwrap();
821 (strs
.pop().unwrap(), end
)
823 n
=> panic
!("Expected 1 or 2 strings, not {}", n
),
828 fn parse_pp_exact(&self, line
: &str, testfile
: &Path
) -> Option
<PathBuf
> {
829 if let Some(s
) = self.parse_name_value_directive(line
, "pp-exact") {
830 Some(PathBuf
::from(&s
))
831 } else if self.parse_name_directive(line
, "pp-exact") {
832 testfile
.file_name().map(PathBuf
::from
)
838 fn parse_custom_normalization(&self, mut line
: &str, prefix
: &str) -> Option
<(String
, String
)> {
839 if self.parse_cfg_name_directive(line
, prefix
) == ParsedNameDirective
::Match
{
840 let from
= parse_normalization_string(&mut line
)?
;
841 let to
= parse_normalization_string(&mut line
)?
;
848 fn parse_needs_matching_clang(&self, line
: &str) -> bool
{
849 self.parse_name_directive(line
, "needs-matching-clang")
852 fn parse_needs_profiler_support(&self, line
: &str) -> bool
{
853 self.parse_name_directive(line
, "needs-profiler-support")
856 fn parse_needs_sanitizer_support(&self, line
: &str) -> bool
{
857 self.parse_name_directive(line
, "needs-sanitizer-support")
860 /// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
861 /// or `normalize-stderr-32bit`.
862 fn parse_cfg_name_directive(&self, line
: &str, prefix
: &str) -> ParsedNameDirective
{
863 if line
.starts_with(prefix
) && line
.as_bytes().get(prefix
.len()) == Some(&b'
-'
) {
864 let name
= line
[prefix
.len() + 1..]
865 .split(&['
:'
, ' '
][..])
870 util
::matches_os(&self.target
, name
) || // target
871 util
::matches_env(&self.target
, name
) || // env
872 name
== util
::get_arch(&self.target
) || // architecture
873 name
== util
::get_pointer_width(&self.target
) || // pointer width
874 name
== self.stage_id
.split('
-'
).next().unwrap() || // stage
875 (self.target
!= self.host
&& name
== "cross-compile") ||
876 match self.compare_mode
{
877 Some(CompareMode
::Nll
) => name
== "compare-mode-nll",
878 Some(CompareMode
::Polonius
) => name
== "compare-mode-polonius",
881 (cfg
!(debug_assertions
) && name
== "debug") {
882 ParsedNameDirective
::Match
885 common
::DebugInfoGdbLldb
=> {
887 ParsedNameDirective
::MatchGdb
888 } else if name
== "lldb" {
889 ParsedNameDirective
::MatchLldb
891 ParsedNameDirective
::NoMatch
894 common
::DebugInfoCdb
=> if name
== "cdb" {
895 ParsedNameDirective
::Match
897 ParsedNameDirective
::NoMatch
899 common
::DebugInfoGdb
=> if name
== "gdb" {
900 ParsedNameDirective
::Match
902 ParsedNameDirective
::NoMatch
904 common
::DebugInfoLldb
=> if name
== "lldb" {
905 ParsedNameDirective
::Match
907 ParsedNameDirective
::NoMatch
909 common
::Pretty
=> if name
== "pretty" {
910 ParsedNameDirective
::Match
912 ParsedNameDirective
::NoMatch
914 _
=> ParsedNameDirective
::NoMatch
,
918 ParsedNameDirective
::NoMatch
922 fn has_cfg_prefix(&self, line
: &str, prefix
: &str) -> bool
{
923 // returns whether this line contains this prefix or not. For prefix
924 // "ignore", returns true if line says "ignore-x86_64", "ignore-arch",
925 // "ignore-android" etc.
926 line
.starts_with(prefix
) && line
.as_bytes().get(prefix
.len()) == Some(&b'
-'
)
929 fn parse_name_directive(&self, line
: &str, directive
: &str) -> bool
{
930 // Ensure the directive is a whole word. Do not match "ignore-x86" when
931 // the line says "ignore-x86_64".
932 line
.starts_with(directive
) && match line
.as_bytes().get(directive
.len()) {
933 None
| Some(&b' '
) | Some(&b'
:'
) => true,
938 pub fn parse_name_value_directive(&self, line
: &str, directive
: &str) -> Option
<String
> {
939 let colon
= directive
.len();
940 if line
.starts_with(directive
) && line
.as_bytes().get(colon
) == Some(&b'
:'
) {
941 let value
= line
[(colon
+ 1)..].to_owned();
942 debug
!("{}: {}", directive
, value
);
943 Some(expand_variables(value
, self))
949 pub fn find_rust_src_root(&self) -> Option
<PathBuf
> {
950 let mut path
= self.src_base
.clone();
951 let path_postfix
= Path
::new("src/etc/lldb_batchmode.py");
954 if path
.join(&path_postfix
).is_file() {
962 fn parse_run_rustfix(&self, line
: &str) -> bool
{
963 self.parse_name_directive(line
, "run-rustfix")
966 fn parse_rustfix_only_machine_applicable(&self, line
: &str) -> bool
{
967 self.parse_name_directive(line
, "rustfix-only-machine-applicable")
970 fn parse_edition(&self, line
: &str) -> Option
<String
> {
971 self.parse_name_value_directive(line
, "edition")
975 pub fn lldb_version_to_int(version_string
: &str) -> isize {
976 let error_string
= format
!(
977 "Encountered LLDB version string with unexpected format: {}",
980 version_string
.parse().expect(&error_string
)
983 fn expand_variables(mut value
: String
, config
: &Config
) -> String
{
984 const CWD
: &'
static str = "{{cwd}}";
985 const SRC_BASE
: &'
static str = "{{src-base}}";
986 const BUILD_BASE
: &'
static str = "{{build-base}}";
988 if value
.contains(CWD
) {
989 let cwd
= env
::current_dir().unwrap();
990 value
= value
.replace(CWD
, &cwd
.to_string_lossy());
993 if value
.contains(SRC_BASE
) {
994 value
= value
.replace(SRC_BASE
, &config
.src_base
.to_string_lossy());
997 if value
.contains(BUILD_BASE
) {
998 value
= value
.replace(BUILD_BASE
, &config
.build_base
.to_string_lossy());
1004 /// Finds the next quoted string `"..."` in `line`, and extract the content from it. Move the `line`
1005 /// variable after the end of the quoted string.
1010 /// let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
1011 /// let first = parse_normalization_string(&mut s);
1012 /// assert_eq!(first, Some("something (32 bits)".to_owned()));
1013 /// assert_eq!(s, " -> \"something ($WORD bits)\".");
1015 fn parse_normalization_string(line
: &mut &str) -> Option
<String
> {
1016 // FIXME support escapes in strings.
1017 let begin
= line
.find('
"')? + 1;
1018 let end = line[begin..].find('"'
)?
+ begin
;
1019 let result
= line
[begin
..end
].to_owned();
1020 *line
= &line
[end
+ 1..];