diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2016-03-01 12:26:24 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2016-03-01 12:26:24 -0500 |
| commit | c76125742a3d7ab9f6ad9fbaba8174f959adc18b (patch) | |
| tree | 7737d288da69bdcfc2650e14cd56f2dc0ea4615c | |
| parent | 24f0851e670530b48ba0c098044a7fb235847501 (diff) | |
| download | rust-c76125742a3d7ab9f6ad9fbaba8174f959adc18b.tar.gz rust-c76125742a3d7ab9f6ad9fbaba8174f959adc18b.zip | |
refactor header parsing so it can work "in-place"
| -rw-r--r-- | src/compiletest/header.rs | 126 |
1 files changed, 64 insertions, 62 deletions
diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index d8d0c383d8e..d5745ab8b34 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -54,80 +54,101 @@ pub struct TestProps { // Load any test directives embedded in the file pub fn load_props(testfile: &Path) -> TestProps { - let mut error_patterns = Vec::new(); - let mut aux_builds = Vec::new(); - let mut exec_env = Vec::new(); - let mut compile_flags = None; - let mut run_flags = None; - let mut pp_exact = None; - let mut check_lines = Vec::new(); - let mut build_aux_docs = false; - let mut force_host = false; - let mut check_stdout = false; - let mut no_prefer_dynamic = false; - let mut pretty_expanded = false; - let mut pretty_mode = None; - let mut pretty_compare_only = false; - let mut forbid_output = Vec::new(); + let error_patterns = Vec::new(); + let aux_builds = Vec::new(); + let exec_env = Vec::new(); + let compile_flags = None; + let run_flags = None; + let pp_exact = None; + let check_lines = Vec::new(); + let build_aux_docs = false; + let force_host = false; + let check_stdout = false; + let no_prefer_dynamic = false; + let pretty_expanded = false; + let pretty_compare_only = false; + let forbid_output = Vec::new(); + let mut props = TestProps { + error_patterns: error_patterns, + compile_flags: compile_flags, + run_flags: run_flags, + pp_exact: pp_exact, + aux_builds: aux_builds, + exec_env: exec_env, + check_lines: check_lines, + build_aux_docs: build_aux_docs, + force_host: force_host, + check_stdout: check_stdout, + no_prefer_dynamic: no_prefer_dynamic, + pretty_expanded: pretty_expanded, + pretty_mode: format!("normal"), + pretty_compare_only: pretty_compare_only, + forbid_output: forbid_output, + }; + load_props_into(&mut props, testfile); + props +} + +pub fn load_props_into(props: &mut TestProps, testfile: &Path) { iter_header(testfile, &mut |ln| { if let Some(ep) = parse_error_pattern(ln) { - error_patterns.push(ep); + props.error_patterns.push(ep); } - if compile_flags.is_none() { - compile_flags = parse_compile_flags(ln); + if props.compile_flags.is_none() { + props.compile_flags = parse_compile_flags(ln); } - if run_flags.is_none() { - run_flags = parse_run_flags(ln); + if props.run_flags.is_none() { + props.run_flags = parse_run_flags(ln); } - if pp_exact.is_none() { - pp_exact = parse_pp_exact(ln, testfile); + if props.pp_exact.is_none() { + props.pp_exact = parse_pp_exact(ln, testfile); } - if !build_aux_docs { - build_aux_docs = parse_build_aux_docs(ln); + if !props.build_aux_docs { + props.build_aux_docs = parse_build_aux_docs(ln); } - if !force_host { - force_host = parse_force_host(ln); + if !props.force_host { + props.force_host = parse_force_host(ln); } - if !check_stdout { - check_stdout = parse_check_stdout(ln); + if !props.check_stdout { + props.check_stdout = parse_check_stdout(ln); } - if !no_prefer_dynamic { - no_prefer_dynamic = parse_no_prefer_dynamic(ln); + if !props.no_prefer_dynamic { + props.no_prefer_dynamic = parse_no_prefer_dynamic(ln); } - if !pretty_expanded { - pretty_expanded = parse_pretty_expanded(ln); + if !props.pretty_expanded { + props.pretty_expanded = parse_pretty_expanded(ln); } - if pretty_mode.is_none() { - pretty_mode = parse_pretty_mode(ln); + if let Some(m) = parse_pretty_mode(ln) { + props.pretty_mode = m; } - if !pretty_compare_only { - pretty_compare_only = parse_pretty_compare_only(ln); + if !props.pretty_compare_only { + props.pretty_compare_only = parse_pretty_compare_only(ln); } if let Some(ab) = parse_aux_build(ln) { - aux_builds.push(ab); + props.aux_builds.push(ab); } if let Some(ee) = parse_exec_env(ln) { - exec_env.push(ee); + props.exec_env.push(ee); } if let Some(cl) = parse_check_line(ln) { - check_lines.push(cl); + props.check_lines.push(cl); } if let Some(of) = parse_forbid_output(ln) { - forbid_output.push(of); + props.forbid_output.push(of); } true @@ -136,30 +157,12 @@ pub fn load_props(testfile: &Path) -> TestProps { for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] { match env::var(key) { Ok(val) => - if exec_env.iter().find(|&&(ref x, _)| *x == key).is_none() { - exec_env.push((key.to_owned(), val)) + if props.exec_env.iter().find(|&&(ref x, _)| *x == key).is_none() { + props.exec_env.push((key.to_owned(), val)) }, Err(..) => {} } } - - TestProps { - error_patterns: error_patterns, - compile_flags: compile_flags, - run_flags: run_flags, - pp_exact: pp_exact, - aux_builds: aux_builds, - exec_env: exec_env, - check_lines: check_lines, - build_aux_docs: build_aux_docs, - force_host: force_host, - check_stdout: check_stdout, - no_prefer_dynamic: no_prefer_dynamic, - pretty_expanded: pretty_expanded, - pretty_mode: pretty_mode.unwrap_or("normal".to_owned()), - pretty_compare_only: pretty_compare_only, - forbid_output: forbid_output, - } } pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool { @@ -253,8 +256,7 @@ fn iter_header(testfile: &Path, it: &mut FnMut(&str) -> bool) -> bool { // with a warm page cache. Maybe with a cold one. let ln = ln.unwrap(); let ln = ln.trim(); - if ln.starts_with("fn") || - ln.starts_with("mod") { + if ln.starts_with("fn") || ln.starts_with("mod") { return true; } else if ln.starts_with("//") { if !it(&ln[2..]) { |
