3 use std::io::prelude::*;
4 use std::io::BufReader;
5 use std::path::{Path, PathBuf};
7 use crate::common::{self, CompareMode, Config, Mode};
10 use crate::extract_gdb_version;
12 /// Whether to ignore the test.
13 #[derive(Clone, Copy, PartialEq, Debug)]
17 /// Ignore it totally.
19 /// Ignore only the gdb test, but run the lldb test.
21 /// Ignore only the lldb test, but run the gdb test.
26 pub fn can_run_gdb(&self) -> bool {
27 *self == Ignore::Run || *self == Ignore::IgnoreLldb
30 pub fn can_run_lldb(&self) -> bool {
31 *self == Ignore::Run || *self == Ignore::IgnoreGdb
34 pub fn no_gdb(&self) -> Ignore {
36 Ignore::Run => Ignore::IgnoreGdb,
37 Ignore::IgnoreGdb => Ignore::IgnoreGdb,
42 pub fn no_lldb(&self) -> Ignore {
44 Ignore::Run => Ignore::IgnoreLldb,
45 Ignore::IgnoreLldb => Ignore::IgnoreLldb,
51 /// The result of parse_cfg_name_directive.
52 #[derive(Clone, Copy, PartialEq, Debug)]
53 enum ParsedNameDirective {
58 /// Mode was DebugInfoBoth and this matched gdb.
60 /// Mode was DebugInfoBoth and this matched lldb.
64 /// Properties which must be known very early, before actually running
66 pub struct EarlyProps {
68 pub should_fail: bool,
70 pub revisions: Vec<String>,
74 pub fn from_file(config: &Config, testfile: &Path) -> Self {
75 let mut props = EarlyProps {
82 if config.mode == common::DebugInfoBoth {
83 if config.lldb_python_dir.is_none() {
84 props.ignore = props.ignore.no_lldb();
86 if config.gdb_version.is_none() {
87 props.ignore = props.ignore.no_gdb();
91 iter_header(testfile, None, &mut |ln| {
92 // we should check if any only-<platform> exists and if it exists
93 // and does not matches the current platform, skip the test
94 if props.ignore != Ignore::Ignore {
95 props.ignore = match config.parse_cfg_name_directive(ln, "ignore") {
96 ParsedNameDirective::Match => Ignore::Ignore,
97 ParsedNameDirective::NoMatch => props.ignore,
98 ParsedNameDirective::MatchGdb => props.ignore.no_gdb(),
99 ParsedNameDirective::MatchLldb => props.ignore.no_lldb(),
102 if config.has_cfg_prefix(ln, "only") {
103 props.ignore = match config.parse_cfg_name_directive(ln, "only") {
104 ParsedNameDirective::Match => props.ignore,
105 ParsedNameDirective::NoMatch => Ignore::Ignore,
106 ParsedNameDirective::MatchLldb => props.ignore.no_gdb(),
107 ParsedNameDirective::MatchGdb => props.ignore.no_lldb(),
111 if ignore_llvm(config, ln) {
112 props.ignore = Ignore::Ignore;
115 if config.run_clang_based_tests_with.is_none() &&
116 config.parse_needs_matching_clang(ln) {
117 props.ignore = Ignore::Ignore;
121 if (config.mode == common::DebugInfoGdb || config.mode == common::DebugInfoBoth) &&
122 props.ignore.can_run_gdb() && ignore_gdb(config, ln) {
123 props.ignore = props.ignore.no_gdb();
126 if (config.mode == common::DebugInfoLldb || config.mode == common::DebugInfoBoth) &&
127 props.ignore.can_run_lldb() && ignore_lldb(config, ln) {
128 props.ignore = props.ignore.no_lldb();
131 if let Some(s) = config.parse_aux_build(ln) {
135 if let Some(r) = config.parse_revisions(ln) {
136 props.revisions.extend(r);
139 props.should_fail = props.should_fail || config.parse_name_directive(ln, "should-fail");
144 fn ignore_gdb(config: &Config, line: &str) -> bool {
145 if let Some(actual_version) = config.gdb_version {
146 if line.starts_with("min-gdb-version") {
147 let (start_ver, end_ver) = extract_gdb_version_range(line);
149 if start_ver != end_ver {
150 panic!("Expected single GDB version")
152 // Ignore if actual version is smaller the minimum required
154 actual_version < start_ver
155 } else if line.starts_with("ignore-gdb-version") {
156 let (min_version, max_version) = extract_gdb_version_range(line);
158 if max_version < min_version {
159 panic!("Malformed GDB version range: max < min")
162 actual_version >= min_version && actual_version <= max_version
171 // Takes a directive of the form "ignore-gdb-version <version1> [- <version2>]",
172 // returns the numeric representation of <version1> and <version2> as
173 // tuple: (<version1> as u32, <version2> as u32)
174 // If the <version2> part is omitted, the second component of the tuple
175 // is the same as <version1>.
176 fn extract_gdb_version_range(line: &str) -> (u32, u32) {
177 const ERROR_MESSAGE: &'static str = "Malformed GDB version directive";
179 let range_components = line.split(&[' ', '-'][..])
180 .filter(|word| !word.is_empty())
181 .map(extract_gdb_version)
182 .skip_while(Option::is_none)
183 .take(3) // 3 or more = invalid, so take at most 3.
184 .collect::<Vec<Option<u32>>>();
186 match range_components.len() {
188 let v = range_components[0].unwrap();
192 let v_min = range_components[0].unwrap();
193 let v_max = range_components[1].expect(ERROR_MESSAGE);
196 _ => panic!(ERROR_MESSAGE),
200 fn ignore_lldb(config: &Config, line: &str) -> bool {
201 if let Some(ref actual_version) = config.lldb_version {
202 if line.starts_with("min-lldb-version") {
203 let min_version = line.trim_end()
206 .expect("Malformed lldb version directive");
207 // Ignore if actual version is smaller the minimum required
209 lldb_version_to_int(actual_version) < lldb_version_to_int(min_version)
210 } else if line.starts_with("rust-lldb") && !config.lldb_native_rust {
220 fn ignore_llvm(config: &Config, line: &str) -> bool {
221 if config.system_llvm && line.starts_with("no-system-llvm") {
224 if let Some(ref actual_version) = config.llvm_version {
225 if line.starts_with("min-llvm-version") {
226 let min_version = line.trim_end()
229 .expect("Malformed llvm version directive");
230 // Ignore if actual version is smaller the minimum required
232 &actual_version[..] < min_version
233 } else if line.starts_with("min-system-llvm-version") {
234 let min_version = line.trim_end()
237 .expect("Malformed llvm version directive");
238 // Ignore if using system LLVM and actual version
239 // is smaller the minimum required version
240 config.system_llvm && &actual_version[..] < min_version
241 } else if line.starts_with("ignore-llvm-version") {
242 // Syntax is: "ignore-llvm-version <version1> [- <version2>]"
243 let range_components = line.split(' ')
244 .skip(1) // Skip the directive.
246 .filter(|word| !word.is_empty() && word != &"-")
247 .take(3) // 3 or more = invalid, so take at most 3.
248 .collect::<Vec<&str>>();
249 match range_components.len() {
251 &actual_version[..] == range_components[0]
254 let v_min = range_components[0];
255 let v_max = range_components[1];
257 panic!("Malformed LLVM version range: max < min")
259 // Ignore if version lies inside of range.
260 &actual_version[..] >= v_min && &actual_version[..] <= v_max
262 _ => panic!("Malformed LLVM version directive"),
274 #[derive(Clone, Debug)]
275 pub struct TestProps {
276 // Lines that should be expected, in order, on standard out
277 pub error_patterns: Vec<String>,
278 // Extra flags to pass to the compiler
279 pub compile_flags: Vec<String>,
280 // Extra flags to pass when the compiled code is run (such as --bench)
281 pub run_flags: Option<String>,
282 // If present, the name of a file that this test should match when
284 pub pp_exact: Option<PathBuf>,
285 // Other crates that should be compiled (typically from the same
286 // directory as the test, but for backwards compatibility reasons
287 // we also check the auxiliary directory)
288 pub aux_builds: Vec<String>,
289 // Environment settings to use for compiling
290 pub rustc_env: Vec<(String, String)>,
291 // Environment settings to use during execution
292 pub exec_env: Vec<(String, String)>,
293 // Lines to check if they appear in the expected debugger output
294 pub check_lines: Vec<String>,
295 // Build documentation for all specified aux-builds as well
296 pub build_aux_docs: bool,
297 // Flag to force a crate to be built with the host architecture
298 pub force_host: bool,
299 // Check stdout for error-pattern output as well as stderr
300 pub check_stdout: bool,
301 // For UI tests, allows compiler to generate arbitrary output to stdout
302 pub dont_check_compiler_stdout: bool,
303 // For UI tests, allows compiler to generate arbitrary output to stderr
304 pub dont_check_compiler_stderr: bool,
305 // Don't force a --crate-type=dylib flag on the command line
306 pub no_prefer_dynamic: bool,
307 // Run --pretty expanded when running pretty printing tests
308 pub pretty_expanded: bool,
309 // Which pretty mode are we testing with, default to 'normal'
310 pub pretty_mode: String,
311 // Only compare pretty output and don't try compiling
312 pub pretty_compare_only: bool,
313 // Patterns which must not appear in the output of a cfail test.
314 pub forbid_output: Vec<String>,
315 // Revisions to test for incremental compilation.
316 pub revisions: Vec<String>,
317 // Directory (if any) to use for incremental compilation. This is
318 // not set by end-users; rather it is set by the incremental
319 // testing harness and used when generating compilation
320 // arguments. (In particular, it propagates to the aux-builds.)
321 pub incremental_dir: Option<PathBuf>,
322 // Specifies that a test must actually compile without errors.
323 pub compile_pass: bool,
324 // rustdoc will test the output of the `--test` option
325 pub check_test_line_numbers_match: bool,
326 // The test must be compiled and run successfully. Only used in UI tests for now.
328 // Skip any codegen step and running the executable. Only for run-pass.
329 pub skip_codegen: bool,
330 // Do not pass `-Z ui-testing` to UI tests
331 pub disable_ui_testing_normalization: bool,
332 // customized normalization rules
333 pub normalize_stdout: Vec<(String, String)>,
334 pub normalize_stderr: Vec<(String, String)>,
335 pub failure_status: i32,
336 pub run_rustfix: bool,
337 pub rustfix_only_machine_applicable: bool,
341 pub fn new() -> Self {
343 error_patterns: vec![],
344 compile_flags: vec![],
352 build_aux_docs: false,
355 dont_check_compiler_stdout: false,
356 dont_check_compiler_stderr: false,
357 no_prefer_dynamic: false,
358 pretty_expanded: false,
359 pretty_mode: "normal".to_string(),
360 pretty_compare_only: false,
361 forbid_output: vec![],
362 incremental_dir: None,
364 check_test_line_numbers_match: false,
367 disable_ui_testing_normalization: false,
368 normalize_stdout: vec![],
369 normalize_stderr: vec![],
372 rustfix_only_machine_applicable: false,
376 pub fn from_aux_file(&self, testfile: &Path, cfg: Option<&str>, config: &Config) -> Self {
377 let mut props = TestProps::new();
379 // copy over select properties to the aux build:
380 props.incremental_dir = self.incremental_dir.clone();
381 props.load_from(testfile, cfg, config);
386 pub fn from_file(testfile: &Path, cfg: Option<&str>, config: &Config) -> Self {
387 let mut props = TestProps::new();
388 props.load_from(testfile, cfg, config);
392 /// Loads properties from `testfile` into `props`. If a property is
393 /// tied to a particular revision `foo` (indicated by writing
394 /// `//[foo]`), then the property is ignored unless `cfg` is
396 fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
397 iter_header(testfile, cfg, &mut |ln| {
398 if let Some(ep) = config.parse_error_pattern(ln) {
399 self.error_patterns.push(ep);
402 if let Some(flags) = config.parse_compile_flags(ln) {
404 .extend(flags.split_whitespace().map(|s| s.to_owned()));
407 if let Some(edition) = config.parse_edition(ln) {
408 self.compile_flags.push(format!("--edition={}", edition));
411 if let Some(r) = config.parse_revisions(ln) {
412 self.revisions.extend(r);
415 if self.run_flags.is_none() {
416 self.run_flags = config.parse_run_flags(ln);
419 if self.pp_exact.is_none() {
420 self.pp_exact = config.parse_pp_exact(ln, testfile);
423 if !self.build_aux_docs {
424 self.build_aux_docs = config.parse_build_aux_docs(ln);
427 if !self.force_host {
428 self.force_host = config.parse_force_host(ln);
431 if !self.check_stdout {
432 self.check_stdout = config.parse_check_stdout(ln);
435 if !self.dont_check_compiler_stdout {
436 self.dont_check_compiler_stdout = config.parse_dont_check_compiler_stdout(ln);
439 if !self.dont_check_compiler_stderr {
440 self.dont_check_compiler_stderr = config.parse_dont_check_compiler_stderr(ln);
443 if !self.no_prefer_dynamic {
444 self.no_prefer_dynamic = config.parse_no_prefer_dynamic(ln);
447 if !self.pretty_expanded {
448 self.pretty_expanded = config.parse_pretty_expanded(ln);
451 if let Some(m) = config.parse_pretty_mode(ln) {
452 self.pretty_mode = m;
455 if !self.pretty_compare_only {
456 self.pretty_compare_only = config.parse_pretty_compare_only(ln);
459 if let Some(ab) = config.parse_aux_build(ln) {
460 self.aux_builds.push(ab);
463 if let Some(ee) = config.parse_env(ln, "exec-env") {
464 self.exec_env.push(ee);
467 if let Some(ee) = config.parse_env(ln, "rustc-env") {
468 self.rustc_env.push(ee);
471 if let Some(cl) = config.parse_check_line(ln) {
472 self.check_lines.push(cl);
475 if let Some(of) = config.parse_forbid_output(ln) {
476 self.forbid_output.push(of);
479 if !self.check_test_line_numbers_match {
480 self.check_test_line_numbers_match = config.parse_check_test_line_numbers_match(ln);
484 self.run_pass = config.parse_run_pass(ln);
487 if !self.compile_pass {
488 // run-pass implies must_compile_successfully
489 self.compile_pass = config.parse_compile_pass(ln) || self.run_pass;
492 if !self.skip_codegen {
493 self.skip_codegen = config.parse_skip_codegen(ln);
496 if !self.disable_ui_testing_normalization {
497 self.disable_ui_testing_normalization =
498 config.parse_disable_ui_testing_normalization(ln);
501 if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stdout") {
502 self.normalize_stdout.push(rule);
504 if let Some(rule) = config.parse_custom_normalization(ln, "normalize-stderr") {
505 self.normalize_stderr.push(rule);
508 if let Some(code) = config.parse_failure_status(ln) {
509 self.failure_status = code;
512 if !self.run_rustfix {
513 self.run_rustfix = config.parse_run_rustfix(ln);
516 if !self.rustfix_only_machine_applicable {
517 self.rustfix_only_machine_applicable =
518 config.parse_rustfix_only_machine_applicable(ln);
522 if self.failure_status == -1 {
523 self.failure_status = match config.mode {
524 Mode::RunFail => 101,
529 for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
530 if let Ok(val) = env::var(key) {
531 if self.exec_env.iter().find(|&&(ref x, _)| x == key).is_none() {
532 self.exec_env.push(((*key).to_owned(), val))
539 fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
540 if testfile.is_dir() {
544 let comment = if testfile.to_string_lossy().ends_with(".rs") {
550 // FIXME: would be nice to allow some whitespace between comment and brace :)
551 // It took me like 2 days to debug why compile-flags weren’t taken into account for my test :)
552 let comment_with_brace = comment.to_string() + "[";
554 let rdr = BufReader::new(File::open(testfile).unwrap());
555 for ln in rdr.lines() {
556 // Assume that any directives will be found before the first
557 // module or function. This doesn't seem to be an optimization
558 // with a warm page cache. Maybe with a cold one.
559 let ln = ln.unwrap();
561 if ln.starts_with("fn") || ln.starts_with("mod") {
563 } else if ln.starts_with(&comment_with_brace) {
564 // A comment like `//[foo]` is specific to revision `foo`
565 if let Some(close_brace) = ln.find(']') {
566 let open_brace = ln.find('[').unwrap();
567 let lncfg = &ln[open_brace + 1 .. close_brace];
568 let matches = match cfg {
569 Some(s) => s == &lncfg[..],
573 it(ln[(close_brace + 1)..].trim_start());
576 panic!("malformed condition directive: expected `{}foo]`, found `{}`",
577 comment_with_brace, ln)
579 } else if ln.starts_with(comment) {
580 it(ln[comment.len() ..].trim_start());
587 fn parse_error_pattern(&self, line: &str) -> Option<String> {
588 self.parse_name_value_directive(line, "error-pattern")
591 fn parse_forbid_output(&self, line: &str) -> Option<String> {
592 self.parse_name_value_directive(line, "forbid-output")
595 fn parse_aux_build(&self, line: &str) -> Option<String> {
596 self.parse_name_value_directive(line, "aux-build")
599 fn parse_compile_flags(&self, line: &str) -> Option<String> {
600 self.parse_name_value_directive(line, "compile-flags")
603 fn parse_revisions(&self, line: &str) -> Option<Vec<String>> {
604 self.parse_name_value_directive(line, "revisions")
605 .map(|r| r.split_whitespace().map(|t| t.to_string()).collect())
608 fn parse_run_flags(&self, line: &str) -> Option<String> {
609 self.parse_name_value_directive(line, "run-flags")
612 fn parse_check_line(&self, line: &str) -> Option<String> {
613 self.parse_name_value_directive(line, "check")
616 fn parse_force_host(&self, line: &str) -> bool {
617 self.parse_name_directive(line, "force-host")
620 fn parse_build_aux_docs(&self, line: &str) -> bool {
621 self.parse_name_directive(line, "build-aux-docs")
624 fn parse_check_stdout(&self, line: &str) -> bool {
625 self.parse_name_directive(line, "check-stdout")
628 fn parse_dont_check_compiler_stdout(&self, line: &str) -> bool {
629 self.parse_name_directive(line, "dont-check-compiler-stdout")
632 fn parse_dont_check_compiler_stderr(&self, line: &str) -> bool {
633 self.parse_name_directive(line, "dont-check-compiler-stderr")
636 fn parse_no_prefer_dynamic(&self, line: &str) -> bool {
637 self.parse_name_directive(line, "no-prefer-dynamic")
640 fn parse_pretty_expanded(&self, line: &str) -> bool {
641 self.parse_name_directive(line, "pretty-expanded")
644 fn parse_pretty_mode(&self, line: &str) -> Option<String> {
645 self.parse_name_value_directive(line, "pretty-mode")
648 fn parse_pretty_compare_only(&self, line: &str) -> bool {
649 self.parse_name_directive(line, "pretty-compare-only")
652 fn parse_failure_status(&self, line: &str) -> Option<i32> {
653 match self.parse_name_value_directive(line, "failure-status") {
654 Some(code) => code.trim().parse::<i32>().ok(),
659 fn parse_compile_pass(&self, line: &str) -> bool {
660 self.parse_name_directive(line, "compile-pass")
663 fn parse_disable_ui_testing_normalization(&self, line: &str) -> bool {
664 self.parse_name_directive(line, "disable-ui-testing-normalization")
667 fn parse_check_test_line_numbers_match(&self, line: &str) -> bool {
668 self.parse_name_directive(line, "check-test-line-numbers-match")
671 fn parse_run_pass(&self, line: &str) -> bool {
672 self.parse_name_directive(line, "run-pass")
675 fn parse_skip_codegen(&self, line: &str) -> bool {
676 self.parse_name_directive(line, "skip-codegen")
679 fn parse_env(&self, line: &str, name: &str) -> Option<(String, String)> {
680 self.parse_name_value_directive(line, name).map(|nv| {
681 // nv is either FOO or FOO=BAR
682 let mut strs: Vec<String> = nv.splitn(2, '=').map(str::to_owned).collect();
685 1 => (strs.pop().unwrap(), String::new()),
687 let end = strs.pop().unwrap();
688 (strs.pop().unwrap(), end)
690 n => panic!("Expected 1 or 2 strings, not {}", n),
695 fn parse_pp_exact(&self, line: &str, testfile: &Path) -> Option<PathBuf> {
696 if let Some(s) = self.parse_name_value_directive(line, "pp-exact") {
697 Some(PathBuf::from(&s))
698 } else if self.parse_name_directive(line, "pp-exact") {
699 testfile.file_name().map(PathBuf::from)
705 fn parse_custom_normalization(&self, mut line: &str, prefix: &str) -> Option<(String, String)> {
706 if self.parse_cfg_name_directive(line, prefix) == ParsedNameDirective::Match {
707 let from = parse_normalization_string(&mut line)?;
708 let to = parse_normalization_string(&mut line)?;
715 fn parse_needs_matching_clang(&self, line: &str) -> bool {
716 self.parse_name_directive(line, "needs-matching-clang")
719 /// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
720 /// or `normalize-stderr-32bit`.
721 fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> ParsedNameDirective {
722 if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') {
723 let name = line[prefix.len() + 1..]
724 .split(&[':', ' '][..])
729 util::matches_os(&self.target, name) || // target
730 name == util::get_arch(&self.target) || // architecture
731 name == util::get_pointer_width(&self.target) || // pointer width
732 name == self.stage_id.split('-').next().unwrap() || // stage
733 Some(name) == util::get_env(&self.target) || // env
734 (self.target != self.host && name == "cross-compile") ||
735 match self.compare_mode {
736 Some(CompareMode::Nll) => name == "compare-mode-nll",
737 Some(CompareMode::Polonius) => name == "compare-mode-polonius",
740 (cfg!(debug_assertions) && name == "debug") {
741 ParsedNameDirective::Match
744 common::DebugInfoBoth => {
746 ParsedNameDirective::MatchGdb
747 } else if name == "lldb" {
748 ParsedNameDirective::MatchLldb
750 ParsedNameDirective::NoMatch
753 common::DebugInfoGdb => if name == "gdb" {
754 ParsedNameDirective::Match
756 ParsedNameDirective::NoMatch
758 common::DebugInfoLldb => if name == "lldb" {
759 ParsedNameDirective::Match
761 ParsedNameDirective::NoMatch
763 common::Pretty => if name == "pretty" {
764 ParsedNameDirective::Match
766 ParsedNameDirective::NoMatch
768 _ => ParsedNameDirective::NoMatch,
772 ParsedNameDirective::NoMatch
776 fn has_cfg_prefix(&self, line: &str, prefix: &str) -> bool {
777 // returns whether this line contains this prefix or not. For prefix
778 // "ignore", returns true if line says "ignore-x86_64", "ignore-arch",
779 // "ignore-android" etc.
780 line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-')
783 fn parse_name_directive(&self, line: &str, directive: &str) -> bool {
784 // Ensure the directive is a whole word. Do not match "ignore-x86" when
785 // the line says "ignore-x86_64".
786 line.starts_with(directive) && match line.as_bytes().get(directive.len()) {
787 None | Some(&b' ') | Some(&b':') => true,
792 pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> {
793 let colon = directive.len();
794 if line.starts_with(directive) && line.as_bytes().get(colon) == Some(&b':') {
795 let value = line[(colon + 1)..].to_owned();
796 debug!("{}: {}", directive, value);
797 Some(expand_variables(value, self))
803 pub fn find_rust_src_root(&self) -> Option<PathBuf> {
804 let mut path = self.src_base.clone();
805 let path_postfix = Path::new("src/etc/lldb_batchmode.py");
808 if path.join(&path_postfix).is_file() {
816 fn parse_run_rustfix(&self, line: &str) -> bool {
817 self.parse_name_directive(line, "run-rustfix")
820 fn parse_rustfix_only_machine_applicable(&self, line: &str) -> bool {
821 self.parse_name_directive(line, "rustfix-only-machine-applicable")
824 fn parse_edition(&self, line: &str) -> Option<String> {
825 self.parse_name_value_directive(line, "edition")
829 pub fn lldb_version_to_int(version_string: &str) -> isize {
830 let error_string = format!(
831 "Encountered LLDB version string with unexpected format: {}",
834 version_string.parse().expect(&error_string)
837 fn expand_variables(mut value: String, config: &Config) -> String {
838 const CWD: &'static str = "{{cwd}}";
839 const SRC_BASE: &'static str = "{{src-base}}";
840 const BUILD_BASE: &'static str = "{{build-base}}";
842 if value.contains(CWD) {
843 let cwd = env::current_dir().unwrap();
844 value = value.replace(CWD, &cwd.to_string_lossy());
847 if value.contains(SRC_BASE) {
848 value = value.replace(SRC_BASE, &config.src_base.to_string_lossy());
851 if value.contains(BUILD_BASE) {
852 value = value.replace(BUILD_BASE, &config.build_base.to_string_lossy());
858 /// Finds the next quoted string `"..."` in `line`, and extract the content from it. Move the `line`
859 /// variable after the end of the quoted string.
864 /// let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
865 /// let first = parse_normalization_string(&mut s);
866 /// assert_eq!(first, Some("something (32 bits)".to_owned()));
867 /// assert_eq!(s, " -> \"something ($WORD bits)\".");
869 fn parse_normalization_string(line: &mut &str) -> Option<String> {
870 // FIXME support escapes in strings.
871 let begin = line.find('"')? + 1;
872 let end = line[begin..].find('"')? + begin;
873 let result = line[begin..end].to_owned();
874 *line = &line[end + 1..];
879 fn test_parse_normalization_string() {
880 let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits)\".";
881 let first = parse_normalization_string(&mut s);
882 assert_eq!(first, Some("something (32 bits)".to_owned()));
883 assert_eq!(s, " -> \"something ($WORD bits)\".");
885 // Nothing to normalize (No quotes)
886 let mut s = "normalize-stderr-32bit: something (32 bits) -> something ($WORD bits).";
887 let first = parse_normalization_string(&mut s);
888 assert_eq!(first, None);
889 assert_eq!(s, r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)."#);
891 // Nothing to normalize (Only a single quote)
892 let mut s = "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).";
893 let first = parse_normalization_string(&mut s);
894 assert_eq!(first, None);
895 assert_eq!(s, "normalize-stderr-32bit: \"something (32 bits) -> something ($WORD bits).");
897 // Nothing to normalize (Three quotes)
898 let mut s = "normalize-stderr-32bit: \"something (32 bits)\" -> \"something ($WORD bits).";
899 let first = parse_normalization_string(&mut s);
900 assert_eq!(first, Some("something (32 bits)".to_owned()));
901 assert_eq!(s, " -> \"something ($WORD bits).");