1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
13 use common::{Codegen, DebugInfoLldb, DebugInfoGdb, Rustdoc, CodegenUnits};
14 use common::{Incremental, RunMake, Ui, MirOpt};
15 use errors::{self, ErrorKind, Error};
16 use filetime::FileTime;
18 use header::TestProps;
25 use std::collections::HashSet;
28 use std::fs::{self, File, create_dir_all};
29 use std::io::prelude::*;
30 use std::io::{self, BufReader};
31 use std::path::{Path, PathBuf};
32 use std::process::{Command, Output, ExitStatus};
34 use std::collections::HashMap;
36 use extract_gdb_version;
38 pub fn run(config: Config, testpaths: &TestPaths) {
39 match &*config.target {
41 "arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
42 if !config.adb_device_status {
43 panic!("android device not available");
48 // android has its own gdb handling
49 if config.mode == DebugInfoGdb && config.gdb.is_none() {
50 panic!("gdb not available but debuginfo gdb debuginfo test requested");
56 // We're going to be dumping a lot of info. Start on a new line.
59 debug!("running {:?}", testpaths.file.display());
60 let base_props = TestProps::from_file(&testpaths.file);
62 let base_cx = TestCx { config: &config,
68 if base_props.revisions.is_empty() {
69 base_cx.run_revision()
71 for revision in &base_props.revisions {
72 let mut revision_props = base_props.clone();
73 revision_props.load_from(&testpaths.file, Some(&revision));
76 props: &revision_props,
78 revision: Some(revision)
80 rev_cx.run_revision();
84 base_cx.complete_all();
86 File::create(::stamp(&config, &testpaths)).unwrap();
89 struct TestCx<'test> {
90 config: &'test Config,
91 props: &'test TestProps,
92 testpaths: &'test TestPaths,
93 revision: Option<&'test str>
96 struct DebuggerCommands {
97 commands: Vec<String>,
98 check_lines: Vec<String>,
99 breakpoint_lines: Vec<usize>,
102 impl<'test> TestCx<'test> {
103 /// invoked once before any revisions have been processed
105 assert!(self.revision.is_none(), "init_all invoked for a revision");
106 match self.config.mode {
107 Incremental => self.init_incremental_test(),
112 /// Code executed for each revision in turn (or, if there are no
113 /// revisions, exactly once, with revision == None).
114 fn run_revision(&self) {
115 match self.config.mode {
116 CompileFail => self.run_cfail_test(),
117 ParseFail => self.run_cfail_test(),
118 RunFail => self.run_rfail_test(),
119 RunPass => self.run_rpass_test(),
120 RunPassValgrind => self.run_valgrind_test(),
121 Pretty => self.run_pretty_test(),
122 DebugInfoGdb => self.run_debuginfo_gdb_test(),
123 DebugInfoLldb => self.run_debuginfo_lldb_test(),
124 Codegen => self.run_codegen_test(),
125 Rustdoc => self.run_rustdoc_test(),
126 CodegenUnits => self.run_codegen_units_test(),
127 Incremental => self.run_incremental_test(),
128 RunMake => self.run_rmake_test(),
129 Ui => self.run_ui_test(),
130 MirOpt => self.run_mir_opt_test(),
134 /// Invoked after all revisions have executed.
135 fn complete_all(&self) {
136 assert!(self.revision.is_none(), "init_all invoked for a revision");
139 fn run_cfail_test(&self) {
140 let proc_res = self.compile_test();
142 if self.props.must_compile_successfully {
143 if !proc_res.status.success() {
145 "test compilation failed although it shouldn't!",
149 if proc_res.status.success() {
151 &format!("{} test compiled successfully!", self.config.mode)[..],
155 self.check_correct_failure_status(&proc_res);
158 let output_to_check = self.get_output(&proc_res);
159 let expected_errors = errors::load_errors(&self.testpaths.file, self.revision);
160 if !expected_errors.is_empty() {
161 if !self.props.error_patterns.is_empty() {
162 self.fatal("both error pattern and expected errors specified");
164 self.check_expected_errors(expected_errors, &proc_res);
166 self.check_error_patterns(&output_to_check, &proc_res);
169 self.check_no_compiler_crash(&proc_res);
170 self.check_forbid_output(&output_to_check, &proc_res);
173 fn run_rfail_test(&self) {
174 let proc_res = self.compile_test();
176 if !proc_res.status.success() {
177 self.fatal_proc_rec("compilation failed!", &proc_res);
180 let proc_res = self.exec_compiled_test();
182 // The value our Makefile configures valgrind to return on failure
183 const VALGRIND_ERR: i32 = 100;
184 if proc_res.status.code() == Some(VALGRIND_ERR) {
185 self.fatal_proc_rec("run-fail test isn't valgrind-clean!", &proc_res);
188 let output_to_check = self.get_output(&proc_res);
189 self.check_correct_failure_status(&proc_res);
190 self.check_error_patterns(&output_to_check, &proc_res);
193 fn get_output(&self, proc_res: &ProcRes) -> String {
194 if self.props.check_stdout {
195 format!("{}{}", proc_res.stdout, proc_res.stderr)
197 proc_res.stderr.clone()
201 fn check_correct_failure_status(&self, proc_res: &ProcRes) {
202 // The value the rust runtime returns on failure
203 const RUST_ERR: i32 = 101;
204 if proc_res.status.code() != Some(RUST_ERR) {
206 &format!("failure produced the wrong error: {}",
212 fn run_rpass_test(&self) {
213 let proc_res = self.compile_test();
215 if !proc_res.status.success() {
216 self.fatal_proc_rec("compilation failed!", &proc_res);
219 let expected_errors = errors::load_errors(&self.testpaths.file, self.revision);
220 if !expected_errors.is_empty() {
221 self.check_expected_errors(expected_errors, &proc_res);
224 let proc_res = self.exec_compiled_test();
226 if !proc_res.status.success() {
227 self.fatal_proc_rec("test run failed!", &proc_res);
231 fn run_valgrind_test(&self) {
232 assert!(self.revision.is_none(), "revisions not relevant here");
234 if self.config.valgrind_path.is_none() {
235 assert!(!self.config.force_valgrind);
236 return self.run_rpass_test();
239 let mut proc_res = self.compile_test();
241 if !proc_res.status.success() {
242 self.fatal_proc_rec("compilation failed!", &proc_res);
245 let mut new_config = self.config.clone();
246 new_config.runtool = new_config.valgrind_path.clone();
247 let new_cx = TestCx { config: &new_config, ..*self };
248 proc_res = new_cx.exec_compiled_test();
250 if !proc_res.status.success() {
251 self.fatal_proc_rec("test run failed!", &proc_res);
255 fn run_pretty_test(&self) {
256 if self.props.pp_exact.is_some() {
257 logv(self.config, "testing for exact pretty-printing".to_owned());
259 logv(self.config, "testing for converging pretty-printing".to_owned());
262 let rounds = match self.props.pp_exact { Some(_) => 1, None => 2 };
264 let mut src = String::new();
265 File::open(&self.testpaths.file).unwrap().read_to_string(&mut src).unwrap();
266 let mut srcs = vec![src];
269 while round < rounds {
270 logv(self.config, format!("pretty-printing round {} revision {:?}",
271 round, self.revision));
272 let proc_res = self.print_source(srcs[round].to_owned(), &self.props.pretty_mode);
274 if !proc_res.status.success() {
275 self.fatal_proc_rec(&format!("pretty-printing failed in round {} revision {:?}",
276 round, self.revision),
280 let ProcRes{ stdout, .. } = proc_res;
285 let mut expected = match self.props.pp_exact {
287 let filepath = self.testpaths.file.parent().unwrap().join(file);
288 let mut s = String::new();
289 File::open(&filepath).unwrap().read_to_string(&mut s).unwrap();
292 None => { srcs[srcs.len() - 2].clone() }
294 let mut actual = srcs[srcs.len() - 1].clone();
296 if self.props.pp_exact.is_some() {
297 // Now we have to care about line endings
298 let cr = "\r".to_owned();
299 actual = actual.replace(&cr, "").to_owned();
300 expected = expected.replace(&cr, "").to_owned();
303 self.compare_source(&expected, &actual);
305 // If we're only making sure that the output matches then just stop here
306 if self.props.pretty_compare_only { return; }
308 // Finally, let's make sure it actually appears to remain valid code
309 let proc_res = self.typecheck_source(actual);
310 if !proc_res.status.success() {
311 self.fatal_proc_rec("pretty-printed source does not typecheck", &proc_res);
314 if !self.props.pretty_expanded { return }
316 // additionally, run `--pretty expanded` and try to build it.
317 let proc_res = self.print_source(srcs[round].clone(), "expanded");
318 if !proc_res.status.success() {
319 self.fatal_proc_rec("pretty-printing (expanded) failed", &proc_res);
322 let ProcRes{ stdout: expanded_src, .. } = proc_res;
323 let proc_res = self.typecheck_source(expanded_src);
324 if !proc_res.status.success() {
326 "pretty-printed source (expanded) does not typecheck",
331 fn print_source(&self,
335 let aux_dir = self.aux_output_dir_name();
336 self.compose_and_run(self.make_pp_args(pretty_type.to_owned()),
337 self.props.exec_env.clone(),
338 self.config.compile_lib_path.to_str().unwrap(),
339 Some(aux_dir.to_str().unwrap()),
343 fn make_pp_args(&self,
346 let aux_dir = self.aux_output_dir_name();
347 // FIXME (#9639): This needs to handle non-utf8 paths
348 let mut args = vec!["-".to_owned(),
349 "-Zunstable-options".to_owned(),
350 "--unpretty".to_owned(),
352 format!("--target={}", self.config.target),
354 aux_dir.to_str().unwrap().to_owned()];
355 args.extend(self.split_maybe_args(&self.config.target_rustcflags));
356 args.extend(self.props.compile_flags.iter().cloned());
358 prog: self.config.rustc_path.to_str().unwrap().to_owned(),
363 fn compare_source(&self,
366 if expected != actual {
367 self.error("pretty-printed source does not match expected source");
370 ------------------------------------------\n\
372 ------------------------------------------\n\
374 ------------------------------------------\n\
376 ------------------------------------------\n\
383 fn typecheck_source(&self, src: String) -> ProcRes {
384 let args = self.make_typecheck_args();
385 self.compose_and_run_compiler(args, Some(src))
388 fn make_typecheck_args(&self) -> ProcArgs {
389 let aux_dir = self.aux_output_dir_name();
390 let target = if self.props.force_host {
396 let out_dir = self.output_base_name().with_extension("pretty-out");
397 let _ = fs::remove_dir_all(&out_dir);
398 create_dir_all(&out_dir).unwrap();
400 // FIXME (#9639): This needs to handle non-utf8 paths
401 let mut args = vec!["-".to_owned(),
402 "-Zno-trans".to_owned(),
403 "--out-dir".to_owned(),
404 out_dir.to_str().unwrap().to_owned(),
405 format!("--target={}", target),
407 self.config.build_base.to_str().unwrap().to_owned(),
409 aux_dir.to_str().unwrap().to_owned()];
410 if let Some(revision) = self.revision {
413 format!("{}", revision),
416 args.extend(self.split_maybe_args(&self.config.target_rustcflags));
417 args.extend(self.props.compile_flags.iter().cloned());
418 // FIXME (#9639): This needs to handle non-utf8 paths
420 prog: self.config.rustc_path.to_str().unwrap().to_owned(),
425 fn run_debuginfo_gdb_test(&self) {
426 assert!(self.revision.is_none(), "revisions not relevant here");
428 let config = Config {
429 target_rustcflags: self.cleanup_debug_info_options(&self.config.target_rustcflags),
430 host_rustcflags: self.cleanup_debug_info_options(&self.config.host_rustcflags),
431 .. self.config.clone()
434 let test_cx = TestCx {
439 test_cx.run_debuginfo_gdb_test_no_opt();
442 fn run_debuginfo_gdb_test_no_opt(&self) {
443 let prefixes = if self.config.gdb_native_rust {
445 static PREFIXES: &'static [&'static str] = &["gdb", "gdbr"];
446 println!("NOTE: compiletest thinks it is using GDB with native rust support");
450 static PREFIXES: &'static [&'static str] = &["gdb", "gdbg"];
451 println!("NOTE: compiletest thinks it is using GDB without native rust support");
455 let DebuggerCommands {
459 } = self.parse_debugger_commands(prefixes);
460 let mut cmds = commands.join("\n");
462 // compile test file (it should have 'compile-flags:-g' in the header)
463 let compiler_run_result = self.compile_test();
464 if !compiler_run_result.status.success() {
465 self.fatal_proc_rec("compilation failed!", &compiler_run_result);
468 let exe_file = self.make_exe_name();
470 let debugger_run_result;
471 match &*self.config.target {
472 "arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
474 cmds = cmds.replace("run", "continue");
476 let tool_path = match self.config.android_cross_path.to_str() {
477 Some(x) => x.to_owned(),
478 None => self.fatal("cannot find android cross path")
481 // write debugger script
482 let mut script_str = String::with_capacity(2048);
483 script_str.push_str(&format!("set charset {}\n", Self::charset()));
484 script_str.push_str(&format!("set sysroot {}\n", tool_path));
485 script_str.push_str(&format!("file {}\n", exe_file.to_str().unwrap()));
486 script_str.push_str("target remote :5039\n");
487 script_str.push_str(&format!("set solib-search-path \
488 ./{}/stage2/lib/rustlib/{}/lib/\n",
489 self.config.host, self.config.target));
490 for line in &breakpoint_lines {
491 script_str.push_str(&format!("break {:?}:{}\n",
492 self.testpaths.file.file_name()
497 script_str.push_str(&cmds);
498 script_str.push_str("\nquit\n");
500 debug!("script_str = {}", script_str);
501 self.dump_output_file(&script_str, "debugger.script");
505 &self.config.adb_path,
509 exe_file.to_str().unwrap().to_owned(),
510 self.config.adb_test_dir.clone()
514 .expect(&format!("failed to exec `{:?}`", self.config.adb_path));
517 &self.config.adb_path,
520 "forward".to_owned(),
521 "tcp:5039".to_owned(),
522 "tcp:5039".to_owned()
526 .expect(&format!("failed to exec `{:?}`", self.config.adb_path));
528 let adb_arg = format!("export LD_LIBRARY_PATH={}; \
529 gdbserver{} :5039 {}/{}",
530 self.config.adb_test_dir.clone(),
531 if self.config.target.contains("aarch64")
533 self.config.adb_test_dir.clone(),
534 exe_file.file_name().unwrap().to_str()
537 let mut process = procsrv::run_background("",
538 &self.config.adb_path
547 .expect(&format!("failed to exec `{:?}`", self.config.adb_path));
549 // Wait for the gdbserver to print out "Listening on port ..."
550 // at which point we know that it's started and then we can
551 // execute the debugger below.
552 let mut stdout = BufReader::new(process.stdout.take().unwrap());
553 let mut line = String::new();
556 stdout.read_line(&mut line).unwrap();
557 if line.starts_with("Listening on port 5039") {
563 let debugger_script = self.make_out_name("debugger.script");
564 // FIXME (#9639): This needs to handle non-utf8 paths
566 vec!["-quiet".to_owned(),
569 format!("-command={}", debugger_script.to_str().unwrap())];
571 let mut gdb_path = tool_path;
572 gdb_path.push_str(&format!("/bin/{}-gdb", self.config.target));
573 let procsrv::Result {
583 .expect(&format!("failed to exec `{:?}`", gdb_path));
585 let cmdline = self.make_cmdline("",
586 &format!("{}-gdb", self.config.target),
588 logv(self.config, format!("executing {}", cmdline));
592 debugger_run_result = ProcRes {
593 status: Status::Normal(status),
598 if process.kill().is_err() {
599 println!("Adb process is already finished.");
604 let rust_src_root = self.find_rust_src_root()
605 .expect("Could not find Rust source root");
606 let rust_pp_module_rel_path = Path::new("./src/etc");
607 let rust_pp_module_abs_path = rust_src_root.join(rust_pp_module_rel_path)
611 // write debugger script
612 let mut script_str = String::with_capacity(2048);
613 script_str.push_str(&format!("set charset {}\n", Self::charset()));
614 script_str.push_str("show version\n");
616 match self.config.gdb_version {
618 println!("NOTE: compiletest thinks it is using GDB version {}",
621 if version > extract_gdb_version("7.4").unwrap() {
622 // Add the directory containing the pretty printers to
623 // GDB's script auto loading safe path
625 &format!("add-auto-load-safe-path {}\n",
626 rust_pp_module_abs_path.replace(r"\", r"\\"))
631 println!("NOTE: compiletest does not know which version of \
636 // The following line actually doesn't have to do anything with
637 // pretty printing, it just tells GDB to print values on one line:
638 script_str.push_str("set print pretty off\n");
640 // Add the pretty printer directory to GDB's source-file search path
641 script_str.push_str(&format!("directory {}\n",
642 rust_pp_module_abs_path));
644 // Load the target executable
645 script_str.push_str(&format!("file {}\n",
646 exe_file.to_str().unwrap()
647 .replace(r"\", r"\\")));
649 // Add line breakpoints
650 for line in &breakpoint_lines {
651 script_str.push_str(&format!("break '{}':{}\n",
652 self.testpaths.file.file_name().unwrap()
657 script_str.push_str(&cmds);
658 script_str.push_str("\nquit\n");
660 debug!("script_str = {}", script_str);
661 self.dump_output_file(&script_str, "debugger.script");
663 let debugger_script = self.make_out_name("debugger.script");
665 // FIXME (#9639): This needs to handle non-utf8 paths
667 vec!["-quiet".to_owned(),
670 format!("-command={}", debugger_script.to_str().unwrap())];
672 let proc_args = ProcArgs {
673 prog: self.config.gdb.as_ref().unwrap().to_owned(),
677 let environment = vec![("PYTHONPATH".to_owned(), rust_pp_module_abs_path)];
679 debugger_run_result =
680 self.compose_and_run(proc_args,
682 self.config.run_lib_path.to_str().unwrap(),
688 if !debugger_run_result.status.success() {
689 self.fatal("gdb failed to execute");
692 self.check_debugger_output(&debugger_run_result, &check_lines);
695 fn find_rust_src_root(&self) -> Option<PathBuf> {
696 let mut path = self.config.src_base.clone();
697 let path_postfix = Path::new("src/etc/lldb_batchmode.py");
700 if path.join(&path_postfix).is_file() {
708 fn run_debuginfo_lldb_test(&self) {
709 assert!(self.revision.is_none(), "revisions not relevant here");
711 if self.config.lldb_python_dir.is_none() {
712 self.fatal("Can't run LLDB test because LLDB's python path is not set.");
715 let config = Config {
716 target_rustcflags: self.cleanup_debug_info_options(&self.config.target_rustcflags),
717 host_rustcflags: self.cleanup_debug_info_options(&self.config.host_rustcflags),
718 .. self.config.clone()
722 let test_cx = TestCx {
727 test_cx.run_debuginfo_lldb_test_no_opt();
730 fn run_debuginfo_lldb_test_no_opt(&self) {
731 // compile test file (it should have 'compile-flags:-g' in the header)
732 let compile_result = self.compile_test();
733 if !compile_result.status.success() {
734 self.fatal_proc_rec("compilation failed!", &compile_result);
737 let exe_file = self.make_exe_name();
739 match self.config.lldb_version {
740 Some(ref version) => {
741 println!("NOTE: compiletest thinks it is using LLDB version {}",
745 println!("NOTE: compiletest does not know which version of \
750 // Parse debugger commands etc from test files
751 let DebuggerCommands {
756 } = self.parse_debugger_commands(&["lldb"]);
758 // Write debugger script:
759 // We don't want to hang when calling `quit` while the process is still running
760 let mut script_str = String::from("settings set auto-confirm true\n");
762 // Make LLDB emit its version, so we have it documented in the test output
763 script_str.push_str("version\n");
765 // Switch LLDB into "Rust mode"
766 let rust_src_root = self.find_rust_src_root().expect("Could not find Rust source root");
767 let rust_pp_module_rel_path = Path::new("./src/etc/lldb_rust_formatters.py");
768 let rust_pp_module_abs_path = rust_src_root.join(rust_pp_module_rel_path)
773 script_str.push_str(&format!("command script import {}\n",
774 &rust_pp_module_abs_path[..])[..]);
775 script_str.push_str("type summary add --no-value ");
776 script_str.push_str("--python-function lldb_rust_formatters.print_val ");
777 script_str.push_str("-x \".*\" --category Rust\n");
778 script_str.push_str("type category enable Rust\n");
780 // Set breakpoints on every line that contains the string "#break"
781 let source_file_name = self.testpaths.file.file_name().unwrap().to_string_lossy();
782 for line in &breakpoint_lines {
783 script_str.push_str(&format!("breakpoint set --file '{}' --line {}\n",
788 // Append the other commands
789 for line in &commands {
790 script_str.push_str(line);
791 script_str.push_str("\n");
794 // Finally, quit the debugger
795 script_str.push_str("\nquit\n");
797 // Write the script into a file
798 debug!("script_str = {}", script_str);
799 self.dump_output_file(&script_str, "debugger.script");
800 let debugger_script = self.make_out_name("debugger.script");
802 // Let LLDB execute the script via lldb_batchmode.py
803 let debugger_run_result = self.run_lldb(&exe_file,
807 if !debugger_run_result.status.success() {
808 self.fatal_proc_rec("Error while running LLDB", &debugger_run_result);
811 self.check_debugger_output(&debugger_run_result, &check_lines);
815 test_executable: &Path,
816 debugger_script: &Path,
817 rust_src_root: &Path)
819 // Prepare the lldb_batchmode which executes the debugger script
820 let lldb_script_path = rust_src_root.join("src/etc/lldb_batchmode.py");
821 self.cmd2procres(Command::new(&self.config.lldb_python)
822 .arg(&lldb_script_path)
823 .arg(test_executable)
824 .arg(debugger_script)
826 self.config.lldb_python_dir.as_ref().unwrap()))
829 fn cmd2procres(&self, cmd: &mut Command) -> ProcRes {
830 let (status, out, err) = match cmd.output() {
831 Ok(Output { status, stdout, stderr }) => {
833 String::from_utf8(stdout).unwrap(),
834 String::from_utf8(stderr).unwrap())
837 self.fatal(&format!("Failed to setup Python process for \
838 LLDB script: {}", e))
842 self.dump_output(&out, &err);
844 status: Status::Normal(status),
847 cmdline: format!("{:?}", cmd)
851 fn parse_debugger_commands(&self, debugger_prefixes: &[&str]) -> DebuggerCommands {
852 let directives = debugger_prefixes.iter().map(|prefix| (
853 format!("{}-command", prefix),
854 format!("{}-check", prefix),
855 )).collect::<Vec<_>>();
857 let mut breakpoint_lines = vec![];
858 let mut commands = vec![];
859 let mut check_lines = vec![];
861 let reader = BufReader::new(File::open(&self.testpaths.file).unwrap());
862 for line in reader.lines() {
865 if line.contains("#break") {
866 breakpoint_lines.push(counter);
869 for &(ref command_directive, ref check_directive) in &directives {
870 header::parse_name_value_directive(
872 &command_directive).map(|cmd| {
876 header::parse_name_value_directive(
878 &check_directive).map(|cmd| {
879 check_lines.push(cmd)
884 self.fatal(&format!("Error while parsing debugger commands: {}", e))
892 check_lines: check_lines,
893 breakpoint_lines: breakpoint_lines,
897 fn cleanup_debug_info_options(&self, options: &Option<String>) -> Option<String> {
898 if options.is_none() {
902 // Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
903 let options_to_remove = [
906 "--debuginfo".to_owned()
909 self.split_maybe_args(options).into_iter()
910 .filter(|x| !options_to_remove.contains(x))
911 .collect::<Vec<String>>();
913 Some(new_options.join(" "))
916 fn check_debugger_output(&self, debugger_run_result: &ProcRes, check_lines: &[String]) {
917 let num_check_lines = check_lines.len();
919 let mut check_line_index = 0;
920 for line in debugger_run_result.stdout.lines() {
921 if check_line_index >= num_check_lines {
925 if check_single_line(line, &(check_lines[check_line_index])[..]) {
926 check_line_index += 1;
929 if check_line_index != num_check_lines && num_check_lines > 0 {
930 self.fatal_proc_rec(&format!("line not found in debugger output: {}",
931 check_lines[check_line_index]),
932 debugger_run_result);
935 fn check_single_line(line: &str, check_line: &str) -> bool {
936 // Allow check lines to leave parts unspecified (e.g., uninitialized
937 // bits in the wrong case of an enum) with the notation "[...]".
938 let line = line.trim();
939 let check_line = check_line.trim();
940 let can_start_anywhere = check_line.starts_with("[...]");
941 let can_end_anywhere = check_line.ends_with("[...]");
943 let check_fragments: Vec<&str> = check_line.split("[...]")
944 .filter(|frag| !frag.is_empty())
946 if check_fragments.is_empty() {
950 let (mut rest, first_fragment) = if can_start_anywhere {
951 match line.find(check_fragments[0]) {
952 Some(pos) => (&line[pos + check_fragments[0].len() ..], 1),
959 for fragment_index in first_fragment .. check_fragments.len() {
960 let current_fragment = check_fragments[fragment_index];
961 match rest.find(current_fragment) {
963 rest = &rest[pos + current_fragment.len() .. ];
969 if !can_end_anywhere && !rest.is_empty() {
977 fn check_error_patterns(&self,
978 output_to_check: &str,
979 proc_res: &ProcRes) {
980 if self.props.error_patterns.is_empty() {
981 if self.props.must_compile_successfully {
984 self.fatal(&format!("no error pattern specified in {:?}",
985 self.testpaths.file.display()));
988 let mut next_err_idx = 0;
989 let mut next_err_pat = self.props.error_patterns[next_err_idx].trim();
990 let mut done = false;
991 for line in output_to_check.lines() {
992 if line.contains(next_err_pat) {
993 debug!("found error pattern {}", next_err_pat);
995 if next_err_idx == self.props.error_patterns.len() {
996 debug!("found all error patterns");
1000 next_err_pat = self.props.error_patterns[next_err_idx].trim();
1005 let missing_patterns = &self.props.error_patterns[next_err_idx..];
1006 if missing_patterns.len() == 1 {
1007 self.fatal_proc_rec(
1008 &format!("error pattern '{}' not found!", missing_patterns[0]),
1011 for pattern in missing_patterns {
1012 self.error(&format!("error pattern '{}' not found!", *pattern));
1014 self.fatal_proc_rec("multiple error patterns not found", proc_res);
1018 fn check_no_compiler_crash(&self, proc_res: &ProcRes) {
1019 for line in proc_res.stderr.lines() {
1020 if line.contains("error: internal compiler error") {
1021 self.fatal_proc_rec("compiler encountered internal error", proc_res);
1026 fn check_forbid_output(&self,
1027 output_to_check: &str,
1028 proc_res: &ProcRes) {
1029 for pat in &self.props.forbid_output {
1030 if output_to_check.contains(pat) {
1031 self.fatal_proc_rec("forbidden pattern found in compiler output", proc_res);
1036 fn check_expected_errors(&self,
1037 expected_errors: Vec<errors::Error>,
1038 proc_res: &ProcRes) {
1039 if proc_res.status.success() &&
1040 expected_errors.iter().any(|x| x.kind == Some(ErrorKind::Error)) {
1041 self.fatal_proc_rec("process did not return an error status", proc_res);
1045 format!("{}", self.testpaths.file.display())
1046 .replace(r"\", "/"); // on windows, translate all '\' path separators to '/'
1048 // If the testcase being checked contains at least one expected "help"
1049 // message, then we'll ensure that all "help" messages are expected.
1050 // Otherwise, all "help" messages reported by the compiler will be ignored.
1051 // This logic also applies to "note" messages.
1052 let expect_help = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Help));
1053 let expect_note = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Note));
1055 // Parse the JSON output from the compiler and extract out the messages.
1056 let actual_errors = json::parse_output(&file_name, &proc_res.stderr, &proc_res);
1057 let mut unexpected = Vec::new();
1058 let mut found = vec![false; expected_errors.len()];
1059 for actual_error in &actual_errors {
1064 .position(|(index, expected_error)| {
1066 actual_error.line_num == expected_error.line_num &&
1067 (expected_error.kind.is_none() ||
1068 actual_error.kind == expected_error.kind) &&
1069 actual_error.msg.contains(&expected_error.msg)
1074 // found a match, everybody is happy
1075 assert!(!found[index]);
1076 found[index] = true;
1080 if self.is_unexpected_compiler_message(actual_error, expect_help, expect_note) {
1082 &format!("{}:{}: unexpected {:?}: '{}'",
1084 actual_error.line_num,
1085 actual_error.kind.as_ref()
1086 .map_or(String::from("message"),
1089 unexpected.push(actual_error.clone());
1095 let mut not_found = Vec::new();
1096 // anything not yet found is a problem
1097 for (index, expected_error) in expected_errors.iter().enumerate() {
1100 &format!("{}:{}: expected {} not found: {}",
1102 expected_error.line_num,
1103 expected_error.kind.as_ref()
1104 .map_or("message".into(),
1106 expected_error.msg));
1107 not_found.push(expected_error.clone());
1111 if unexpected.len() > 0 || not_found.len() > 0 {
1113 &format!("{} unexpected errors found, {} expected errors not found",
1114 unexpected.len(), not_found.len()));
1115 print!("status: {}\ncommand: {}\n",
1116 proc_res.status, proc_res.cmdline);
1117 if unexpected.len() > 0 {
1118 println!("unexpected errors (from JSON output): {:#?}\n", unexpected);
1120 if not_found.len() > 0 {
1121 println!("not found errors (from test file): {:#?}\n", not_found);
1127 /// Returns true if we should report an error about `actual_error`,
1128 /// which did not match any of the expected error. We always require
1129 /// errors/warnings to be explicitly listed, but only require
1130 /// helps/notes if there are explicit helps/notes given.
1131 fn is_unexpected_compiler_message(&self,
1132 actual_error: &Error,
1136 match actual_error.kind {
1137 Some(ErrorKind::Help) => expect_help,
1138 Some(ErrorKind::Note) => expect_note,
1139 Some(ErrorKind::Error) => true,
1140 Some(ErrorKind::Warning) => true,
1141 Some(ErrorKind::Suggestion) => false,
1146 fn compile_test(&self) -> ProcRes {
1147 let aux_dir = self.aux_output_dir_name();
1148 // FIXME (#9639): This needs to handle non-utf8 paths
1149 let link_args = vec!["-L".to_owned(),
1150 aux_dir.to_str().unwrap().to_owned()];
1151 let args = self.make_compile_args(link_args,
1152 &self.testpaths.file,
1153 TargetLocation::ThisFile(self.make_exe_name()));
1154 self.compose_and_run_compiler(args, None)
1157 fn document(&self, out_dir: &Path) -> ProcRes {
1158 if self.props.build_aux_docs {
1159 for rel_ab in &self.props.aux_builds {
1160 let aux_testpaths = self.compute_aux_test_paths(rel_ab);
1161 let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision);
1162 let aux_cx = TestCx {
1163 config: self.config,
1165 testpaths: &aux_testpaths,
1166 revision: self.revision
1168 let auxres = aux_cx.document(out_dir);
1169 if !auxres.status.success() {
1175 let aux_dir = self.aux_output_dir_name();
1176 let mut args = vec!["-L".to_owned(),
1177 aux_dir.to_str().unwrap().to_owned(),
1179 out_dir.to_str().unwrap().to_owned(),
1180 self.testpaths.file.to_str().unwrap().to_owned()];
1181 args.extend(self.props.compile_flags.iter().cloned());
1182 let args = ProcArgs {
1183 prog: self.config.rustdoc_path.to_str().unwrap().to_owned(),
1186 self.compose_and_run_compiler(args, None)
1189 fn exec_compiled_test(&self) -> ProcRes {
1190 let env = self.props.exec_env.clone();
1192 match &*self.config.target {
1194 "arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
1195 self._arm_exec_compiled_test(env)
1198 // This is pretty similar to below, we're transforming:
1200 // program arg1 arg2
1204 // qemu-test-client run program:support-lib.so arg1 arg2
1206 // The test-client program will upload `program` to the emulator
1207 // along with all other support libraries listed (in this case
1208 // `support-lib.so`. It will then execute the program on the
1209 // emulator with the arguments specified (in the environment we give
1210 // the process) and then report back the same result.
1211 _ if self.config.qemu_test_client.is_some() => {
1212 let aux_dir = self.aux_output_dir_name();
1213 let mut args = self.make_run_args();
1214 let mut program = args.prog.clone();
1215 if let Ok(entries) = aux_dir.read_dir() {
1216 for entry in entries {
1217 let entry = entry.unwrap();
1218 if !entry.path().is_file() {
1221 program.push_str(":");
1222 program.push_str(entry.path().to_str().unwrap());
1225 args.args.insert(0, program);
1226 args.args.insert(0, "run".to_string());
1227 args.prog = self.config.qemu_test_client.clone().unwrap()
1228 .into_os_string().into_string().unwrap();
1229 self.compose_and_run(args,
1231 self.config.run_lib_path.to_str().unwrap(),
1232 Some(aux_dir.to_str().unwrap()),
1236 let aux_dir = self.aux_output_dir_name();
1237 self.compose_and_run(self.make_run_args(),
1239 self.config.run_lib_path.to_str().unwrap(),
1240 Some(aux_dir.to_str().unwrap()),
1246 /// For each `aux-build: foo/bar` annotation, we check to find the
1247 /// file in a `aux` directory relative to the test itself.
1248 fn compute_aux_test_paths(&self, rel_ab: &str) -> TestPaths {
1249 let test_ab = self.testpaths.file
1251 .expect("test file path has no parent")
1254 if !test_ab.exists() {
1255 self.fatal(&format!("aux-build `{}` source not found", test_ab.display()))
1260 base: self.testpaths.base.clone(),
1261 relative_dir: self.testpaths.relative_dir
1265 .expect("aux-build path has no parent")
1270 fn compose_and_run_compiler(&self, args: ProcArgs, input: Option<String>) -> ProcRes {
1271 if !self.props.aux_builds.is_empty() {
1272 create_dir_all(&self.aux_output_dir_name()).unwrap();
1275 let aux_dir = self.aux_output_dir_name();
1276 // FIXME (#9639): This needs to handle non-utf8 paths
1277 let extra_link_args = vec!["-L".to_owned(),
1278 aux_dir.to_str().unwrap().to_owned()];
1280 for rel_ab in &self.props.aux_builds {
1281 let aux_testpaths = self.compute_aux_test_paths(rel_ab);
1282 let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision);
1283 let mut crate_type = if aux_props.no_prefer_dynamic {
1286 // We primarily compile all auxiliary libraries as dynamic libraries
1287 // to avoid code size bloat and large binaries as much as possible
1288 // for the test suite (otherwise including libstd statically in all
1289 // executables takes up quite a bit of space).
1291 // For targets like MUSL or Emscripten, however, there is no support for
1292 // dynamic libraries so we just go back to building a normal library. Note,
1293 // however, that for MUSL if the library is built with `force_host` then
1294 // it's ok to be a dylib as the host should always support dylibs.
1295 if (self.config.target.contains("musl") && !aux_props.force_host) ||
1296 self.config.target.contains("emscripten")
1298 vec!["--crate-type=lib".to_owned()]
1300 vec!["--crate-type=dylib".to_owned()]
1303 crate_type.extend(extra_link_args.clone());
1305 let f = self.make_lib_name(&self.testpaths.file);
1306 let parent = f.parent().unwrap();
1307 TargetLocation::ThisDirectory(parent.to_path_buf())
1309 let aux_cx = TestCx {
1310 config: self.config,
1312 testpaths: &aux_testpaths,
1313 revision: self.revision
1315 let aux_args = aux_cx.make_compile_args(crate_type, &aux_testpaths.file, aux_output);
1316 let auxres = aux_cx.compose_and_run(aux_args,
1318 aux_cx.config.compile_lib_path.to_str().unwrap(),
1319 Some(aux_dir.to_str().unwrap()),
1321 if !auxres.status.success() {
1322 self.fatal_proc_rec(
1323 &format!("auxiliary build of {:?} failed to compile: ",
1324 aux_testpaths.file.display()),
1328 match &*self.config.target {
1329 "arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
1330 self._arm_push_aux_shared_library();
1336 self.compose_and_run(args,
1337 self.props.rustc_env.clone(),
1338 self.config.compile_lib_path.to_str().unwrap(),
1339 Some(aux_dir.to_str().unwrap()),
1344 fn compose_and_run(&self,
1345 ProcArgs{ args, prog }: ProcArgs,
1346 procenv: Vec<(String, String)> ,
1348 aux_path: Option<&str>,
1349 input: Option<String>) -> ProcRes {
1350 return self.program_output(lib_path, prog, aux_path, args, procenv, input);
1353 fn make_compile_args(&self,
1354 extras: Vec<String> ,
1356 output_file: TargetLocation)
1359 let target = if self.props.force_host {
1362 &*self.config.target
1365 // FIXME (#9639): This needs to handle non-utf8 paths
1366 let mut args = vec![input_file.to_str().unwrap().to_owned(),
1368 self.config.build_base.to_str().unwrap().to_owned()];
1370 // Optionally prevent default --target if specified in test compile-flags.
1371 let custom_target = self.props.compile_flags
1373 .fold(false, |acc, ref x| acc || x.starts_with("--target"));
1377 format!("--target={}", target),
1381 if let Some(revision) = self.revision {
1384 format!("{}", revision),
1388 if let Some(ref incremental_dir) = self.props.incremental_dir {
1391 format!("incremental={}", incremental_dir.display()),
1396 match self.config.mode {
1401 // If we are extracting and matching errors in the new
1402 // fashion, then you want JSON mode. Old-skool error
1403 // patterns still match the raw compiler output.
1404 if self.props.error_patterns.is_empty() {
1405 args.extend(["--error-format",
1408 .map(|s| s.to_string()));
1418 .map(|s| s.to_string()));
1421 let mir_dump_dir = self.get_mir_dump_dir();
1422 create_dir_all(mir_dump_dir.as_path()).unwrap();
1423 let mut dir_opt = "dump-mir-dir=".to_string();
1424 dir_opt.push_str(mir_dump_dir.to_str().unwrap());
1425 debug!("dir_opt: {:?}", dir_opt);
1439 // do not use JSON output
1443 args.extend_from_slice(&extras);
1444 if !self.props.no_prefer_dynamic {
1445 args.push("-C".to_owned());
1446 args.push("prefer-dynamic".to_owned());
1448 let path = match output_file {
1449 TargetLocation::ThisFile(path) => {
1450 args.push("-o".to_owned());
1453 TargetLocation::ThisDirectory(path) => {
1454 args.push("--out-dir".to_owned());
1458 args.push(path.to_str().unwrap().to_owned());
1459 if self.props.force_host {
1460 args.extend(self.split_maybe_args(&self.config.host_rustcflags));
1462 args.extend(self.split_maybe_args(&self.config.target_rustcflags));
1464 args.extend(self.props.compile_flags.iter().cloned());
1466 prog: self.config.rustc_path.to_str().unwrap().to_owned(),
1471 fn make_lib_name(&self, auxfile: &Path) -> PathBuf {
1472 // what we return here is not particularly important, as it
1473 // happens; rustc ignores everything except for the directory.
1474 let auxname = self.output_testname(auxfile);
1475 self.aux_output_dir_name().join(&auxname)
1478 fn make_exe_name(&self) -> PathBuf {
1479 let mut f = self.output_base_name();
1480 // FIXME: This is using the host architecture exe suffix, not target!
1481 if self.config.target.contains("emscripten") {
1482 let mut fname = f.file_name().unwrap().to_os_string();
1484 f.set_file_name(&fname);
1485 } else if !env::consts::EXE_SUFFIX.is_empty() {
1486 let mut fname = f.file_name().unwrap().to_os_string();
1487 fname.push(env::consts::EXE_SUFFIX);
1488 f.set_file_name(&fname);
1493 fn make_run_args(&self) -> ProcArgs {
1494 // If we've got another tool to run under (valgrind),
1495 // then split apart its command
1496 let mut args = self.split_maybe_args(&self.config.runtool);
1498 // If this is emscripten, then run tests under nodejs
1499 if self.config.target.contains("emscripten") {
1500 if let Some(ref p) = self.config.nodejs {
1501 args.push(p.clone());
1503 self.fatal("no NodeJS binary found (--nodejs)");
1507 let exe_file = self.make_exe_name();
1509 // FIXME (#9639): This needs to handle non-utf8 paths
1510 args.push(exe_file.to_str().unwrap().to_owned());
1512 // Add the arguments in the run_flags directive
1513 args.extend(self.split_maybe_args(&self.props.run_flags));
1515 let prog = args.remove(0);
1522 fn split_maybe_args(&self, argstr: &Option<String>) -> Vec<String> {
1528 if s.chars().all(|c| c.is_whitespace()) {
1539 fn program_output(&self,
1542 aux_path: Option<&str>,
1544 env: Vec<(String, String)>,
1545 input: Option<String>)
1549 let cmdline = self.make_cmdline(lib_path,
1552 logv(self.config, format!("executing {}", cmdline));
1555 let procsrv::Result {
1559 } = procsrv::run(lib_path,
1564 input).expect(&format!("failed to exec `{}`", prog));
1565 self.dump_output(&out, &err);
1567 status: Status::Normal(status),
1574 fn make_cmdline(&self, libpath: &str, prog: &str, args: &[String]) -> String {
1577 // Linux and mac don't require adjusting the library search path
1579 format!("{} {}", prog, args.join(" "))
1581 // Build the LD_LIBRARY_PATH variable as it would be seen on the command line
1582 // for diagnostic purposes
1583 fn lib_path_cmd_prefix(path: &str) -> String {
1584 format!("{}=\"{}\"", util::lib_path_env_var(), util::make_new_path(path))
1587 format!("{} {} {}", lib_path_cmd_prefix(libpath), prog, args.join(" "))
1591 fn dump_output(&self, out: &str, err: &str) {
1592 self.dump_output_file(out, "out");
1593 self.dump_output_file(err, "err");
1594 self.maybe_dump_to_stdout(out, err);
1597 fn dump_output_file(&self,
1600 let outfile = self.make_out_name(extension);
1601 File::create(&outfile).unwrap().write_all(out.as_bytes()).unwrap();
1604 fn make_out_name(&self, extension: &str) -> PathBuf {
1605 self.output_base_name().with_extension(extension)
1608 fn aux_output_dir_name(&self) -> PathBuf {
1609 let f = self.output_base_name();
1610 let mut fname = f.file_name().unwrap().to_os_string();
1611 fname.push(&format!(".{}.libaux", self.config.mode));
1612 f.with_file_name(&fname)
1615 fn output_testname(&self, filepath: &Path) -> PathBuf {
1616 PathBuf::from(filepath.file_stem().unwrap())
1619 /// Given a test path like `compile-fail/foo/bar.rs` Returns a name like
1621 /// <output>/foo/bar-stage1
1622 fn output_base_name(&self) -> PathBuf {
1623 let dir = self.config.build_base.join(&self.testpaths.relative_dir);
1625 // Note: The directory `dir` is created during `collect_tests_from_dir`
1627 .join(&self.output_testname(&self.testpaths.file))
1628 .with_extension(&self.config.stage_id)
1631 fn maybe_dump_to_stdout(&self, out: &str, err: &str) {
1632 if self.config.verbose {
1633 println!("------{}------------------------------", "stdout");
1634 println!("{}", out);
1635 println!("------{}------------------------------", "stderr");
1636 println!("{}", err);
1637 println!("------------------------------------------");
1641 fn error(&self, err: &str) {
1642 match self.revision {
1643 Some(rev) => println!("\nerror in revision `{}`: {}", rev, err),
1644 None => println!("\nerror: {}", err)
1648 fn fatal(&self, err: &str) -> ! {
1649 self.error(err); panic!();
1652 fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
1653 self.try_print_open_handles();
1655 proc_res.fatal(None);
1658 // This function is a poor man's attempt to debug rust-lang/rust#38620, if
1659 // that's closed then this should be deleted
1661 // This is a very "opportunistic" debugging attempt, so we ignore all
1663 fn try_print_open_handles(&self) {
1667 if self.config.mode != Incremental {
1671 let filename = match self.testpaths.file.file_stem() {
1676 let mut cmd = Command::new("handle.exe");
1677 cmd.arg("-a").arg("-u");
1679 cmd.arg("-nobanner");
1680 let output = match cmd.output() {
1681 Ok(output) => output,
1684 println!("---------------------------------------------------");
1685 println!("ran extra command to debug rust-lang/rust#38620: ");
1686 println!("{:?}", cmd);
1687 println!("result: {}", output.status);
1688 println!("--- stdout ----------------------------------------");
1689 println!("{}", String::from_utf8_lossy(&output.stdout));
1690 println!("--- stderr ----------------------------------------");
1691 println!("{}", String::from_utf8_lossy(&output.stderr));
1692 println!("---------------------------------------------------");
1695 fn _arm_exec_compiled_test(&self, env: Vec<(String, String)>) -> ProcRes {
1696 let args = self.make_run_args();
1697 let cmdline = self.make_cmdline("", &args.prog, &args.args);
1699 // get bare program string
1700 let mut tvec: Vec<String> = args.prog
1704 let prog_short = tvec.pop().unwrap();
1707 let copy_result = procsrv::run("",
1708 &self.config.adb_path,
1713 self.config.adb_test_dir.clone()
1715 vec![("".to_owned(), "".to_owned())],
1716 Some("".to_owned()))
1717 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1719 if self.config.verbose {
1720 println!("push ({}) {} {} {}",
1727 logv(self.config, format!("executing ({}) {}", self.config.target, cmdline));
1729 let mut runargs = Vec::new();
1731 // run test via adb_run_wrapper
1732 runargs.push("shell".to_owned());
1733 for (key, val) in env {
1734 runargs.push(format!("{}={}", key, val));
1736 runargs.push(format!("{}/../adb_run_wrapper.sh", self.config.adb_test_dir));
1737 runargs.push(format!("{}", self.config.adb_test_dir));
1738 runargs.push(format!("{}", prog_short));
1740 for tv in &args.args {
1741 runargs.push(tv.to_owned());
1744 &self.config.adb_path,
1747 vec![("".to_owned(), "".to_owned())], Some("".to_owned()))
1748 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1750 // get exitcode of result
1751 runargs = Vec::new();
1752 runargs.push("shell".to_owned());
1753 runargs.push("cat".to_owned());
1754 runargs.push(format!("{}/{}.exitcode", self.config.adb_test_dir, prog_short));
1756 let procsrv::Result{ out: exitcode_out, err: _, status: _ } =
1758 &self.config.adb_path,
1761 vec![("".to_owned(), "".to_owned())],
1762 Some("".to_owned()))
1763 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1765 let mut exitcode: i32 = 0;
1766 for c in exitcode_out.chars() {
1767 if !c.is_numeric() { break; }
1768 exitcode = exitcode * 10 + match c {
1769 '0' ... '9' => c as i32 - ('0' as i32),
1774 // get stdout of result
1775 runargs = Vec::new();
1776 runargs.push("shell".to_owned());
1777 runargs.push("cat".to_owned());
1778 runargs.push(format!("{}/{}.stdout", self.config.adb_test_dir, prog_short));
1780 let procsrv::Result{ out: stdout_out, err: _, status: _ } =
1782 &self.config.adb_path,
1785 vec![("".to_owned(), "".to_owned())],
1786 Some("".to_owned()))
1787 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1789 // get stderr of result
1790 runargs = Vec::new();
1791 runargs.push("shell".to_owned());
1792 runargs.push("cat".to_owned());
1793 runargs.push(format!("{}/{}.stderr", self.config.adb_test_dir, prog_short));
1795 let procsrv::Result{ out: stderr_out, err: _, status: _ } =
1797 &self.config.adb_path,
1800 vec![("".to_owned(), "".to_owned())],
1801 Some("".to_owned()))
1802 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1804 self.dump_output(&stdout_out, &stderr_out);
1807 status: Status::Parsed(exitcode),
1814 fn _arm_push_aux_shared_library(&self) {
1815 let tdir = self.aux_output_dir_name();
1817 let dirs = fs::read_dir(&tdir).unwrap();
1819 let file = file.unwrap().path();
1820 if file.extension().and_then(|s| s.to_str()) == Some("so") {
1821 // FIXME (#9639): This needs to handle non-utf8 paths
1822 let copy_result = procsrv::run("",
1823 &self.config.adb_path,
1830 self.config.adb_test_dir.to_owned(),
1832 vec![("".to_owned(),
1834 Some("".to_owned()))
1835 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1837 if self.config.verbose {
1838 println!("push ({}) {:?} {} {}",
1839 self.config.target, file.display(),
1840 copy_result.out, copy_result.err);
1846 // codegen tests (using FileCheck)
1848 fn compile_test_and_save_ir(&self) -> ProcRes {
1849 let aux_dir = self.aux_output_dir_name();
1850 // FIXME (#9639): This needs to handle non-utf8 paths
1851 let mut link_args = vec!["-L".to_owned(),
1852 aux_dir.to_str().unwrap().to_owned()];
1853 let llvm_args = vec!["--emit=llvm-ir".to_owned(),];
1854 link_args.extend(llvm_args);
1855 let args = self.make_compile_args(link_args,
1856 &self.testpaths.file,
1857 TargetLocation::ThisDirectory(
1858 self.output_base_name().parent()
1861 self.compose_and_run_compiler(args, None)
1864 fn check_ir_with_filecheck(&self) -> ProcRes {
1865 let irfile = self.output_base_name().with_extension("ll");
1866 let prog = self.config.llvm_filecheck.as_ref().unwrap();
1867 let proc_args = ProcArgs {
1868 // FIXME (#9639): This needs to handle non-utf8 paths
1869 prog: prog.to_str().unwrap().to_owned(),
1870 args: vec![format!("-input-file={}", irfile.to_str().unwrap()),
1871 self.testpaths.file.to_str().unwrap().to_owned()]
1873 self.compose_and_run(proc_args, Vec::new(), "", None, None)
1876 fn run_codegen_test(&self) {
1877 assert!(self.revision.is_none(), "revisions not relevant here");
1879 if self.config.llvm_filecheck.is_none() {
1880 self.fatal("missing --llvm-filecheck");
1883 let mut proc_res = self.compile_test_and_save_ir();
1884 if !proc_res.status.success() {
1885 self.fatal_proc_rec("compilation failed!", &proc_res);
1888 proc_res = self.check_ir_with_filecheck();
1889 if !proc_res.status.success() {
1890 self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
1894 fn charset() -> &'static str {
1895 // FreeBSD 10.1 defaults to GDB 6.1.1 which doesn't support "auto" charset
1896 if cfg!(target_os = "bitrig") {
1898 } else if cfg!(target_os = "freebsd") {
1905 fn run_rustdoc_test(&self) {
1906 assert!(self.revision.is_none(), "revisions not relevant here");
1908 let out_dir = self.output_base_name();
1909 let _ = fs::remove_dir_all(&out_dir);
1910 create_dir_all(&out_dir).unwrap();
1912 let proc_res = self.document(&out_dir);
1913 if !proc_res.status.success() {
1914 self.fatal_proc_rec("rustdoc failed!", &proc_res);
1917 if self.props.check_test_line_numbers_match == true {
1918 self.check_rustdoc_test_option(proc_res);
1920 let root = self.find_rust_src_root().unwrap();
1921 let res = self.cmd2procres(Command::new(&self.config.docck_python)
1922 .arg(root.join("src/etc/htmldocck.py"))
1924 .arg(&self.testpaths.file));
1925 if !res.status.success() {
1926 self.fatal_proc_rec("htmldocck failed!", &res);
1931 fn get_lines<P: AsRef<Path>>(&self, path: &P,
1932 mut other_files: Option<&mut Vec<String>>) -> Vec<usize> {
1933 let mut file = fs::File::open(path)
1934 .expect("markdown_test_output_check_entry File::open failed");
1935 let mut content = String::new();
1936 file.read_to_string(&mut content)
1937 .expect("markdown_test_output_check_entry read_to_string failed");
1938 let mut ignore = false;
1941 .filter_map(|(line_nb, line)| {
1942 if (line.trim_left().starts_with("pub mod ") ||
1943 line.trim_left().starts_with("mod ")) &&
1944 line.ends_with(";") {
1945 if let Some(ref mut other_files) = other_files {
1946 other_files.push(line.rsplit("mod ")
1953 let sline = line.split("///").last().unwrap_or("");
1954 let line = sline.trim_left();
1955 if line.starts_with("```") {
1971 fn check_rustdoc_test_option(&self, res: ProcRes) {
1972 let mut other_files = Vec::new();
1973 let mut files: HashMap<String, Vec<usize>> = HashMap::new();
1974 let cwd = env::current_dir().unwrap();
1975 files.insert(self.testpaths.file.strip_prefix(&cwd)
1976 .unwrap_or(&self.testpaths.file)
1979 .replace('\\', "/"),
1980 self.get_lines(&self.testpaths.file, Some(&mut other_files)));
1981 for other_file in other_files {
1982 let mut path = self.testpaths.file.clone();
1983 path.set_file_name(&format!("{}.rs", other_file));
1984 files.insert(path.strip_prefix(&cwd)
1988 .replace('\\', "/"),
1989 self.get_lines(&path, None));
1993 for _ in res.stdout.split("\n")
1994 .filter(|s| s.starts_with("test "))
1996 let tmp: Vec<&str> = s.split(" - ").collect();
1998 let path = tmp[0].rsplit("test ").next().unwrap();
1999 if let Some(ref mut v) = files.get_mut(
2000 &path.replace('\\', "/")) {
2002 let mut iter = tmp[1].split("(line ");
2004 let line = iter.next()
2011 if let Ok(pos) = v.binary_search(&line) {
2014 self.fatal_proc_rec(
2015 &format!("Not found doc test: \"{}\" in \"{}\":{:?}",
2023 self.fatal_proc_rec(&format!("No test has been found... {:?}", files), &res);
2025 for (entry, v) in &files {
2027 self.fatal_proc_rec(&format!("Not found test at line{} \"{}\":{:?}",
2028 if v.len() > 1 { "s" } else { "" }, entry, v),
2035 fn run_codegen_units_test(&self) {
2036 assert!(self.revision.is_none(), "revisions not relevant here");
2038 let proc_res = self.compile_test();
2040 if !proc_res.status.success() {
2041 self.fatal_proc_rec("compilation failed!", &proc_res);
2044 self.check_no_compiler_crash(&proc_res);
2046 const PREFIX: &'static str = "TRANS_ITEM ";
2047 const CGU_MARKER: &'static str = "@@";
2049 let actual: Vec<TransItem> = proc_res
2052 .filter(|line| line.starts_with(PREFIX))
2053 .map(str_to_trans_item)
2056 let expected: Vec<TransItem> = errors::load_errors(&self.testpaths.file, None)
2058 .map(|e| str_to_trans_item(&e.msg[..]))
2061 let mut missing = Vec::new();
2062 let mut wrong_cgus = Vec::new();
2064 for expected_item in &expected {
2065 let actual_item_with_same_name = actual.iter()
2066 .find(|ti| ti.name == expected_item.name);
2068 if let Some(actual_item) = actual_item_with_same_name {
2069 if !expected_item.codegen_units.is_empty() {
2070 // Also check for codegen units
2071 if expected_item.codegen_units != actual_item.codegen_units {
2072 wrong_cgus.push((expected_item.clone(), actual_item.clone()));
2076 missing.push(expected_item.string.clone());
2080 let unexpected: Vec<_> =
2082 .filter(|acgu| !expected.iter().any(|ecgu| acgu.name == ecgu.name))
2083 .map(|acgu| acgu.string.clone())
2086 if !missing.is_empty() {
2089 println!("\nThese items should have been contained but were not:\n");
2091 for item in &missing {
2092 println!("{}", item);
2098 if !unexpected.is_empty() {
2100 let mut sorted = unexpected.clone();
2105 println!("\nThese items were contained but should not have been:\n");
2107 for item in sorted {
2108 println!("{}", item);
2114 if !wrong_cgus.is_empty() {
2115 wrong_cgus.sort_by_key(|pair| pair.0.name.clone());
2116 println!("\nThe following items were assigned to wrong codegen units:\n");
2118 for &(ref expected_item, ref actual_item) in &wrong_cgus {
2119 println!("{}", expected_item.name);
2120 println!(" expected: {}", codegen_units_to_str(&expected_item.codegen_units));
2121 println!(" actual: {}", codegen_units_to_str(&actual_item.codegen_units));
2126 if !(missing.is_empty() && unexpected.is_empty() && wrong_cgus.is_empty())
2131 #[derive(Clone, Eq, PartialEq)]
2134 codegen_units: HashSet<String>,
2138 // [TRANS_ITEM] name [@@ (cgu)+]
2139 fn str_to_trans_item(s: &str) -> TransItem {
2140 let s = if s.starts_with(PREFIX) {
2141 (&s[PREFIX.len()..]).trim()
2146 let full_string = format!("{}{}", PREFIX, s.trim().to_owned());
2148 let parts: Vec<&str> = s.split(CGU_MARKER)
2150 .filter(|s| !s.is_empty())
2153 let name = parts[0].trim();
2155 let cgus = if parts.len() > 1 {
2156 let cgus_str = parts[1];
2160 .filter(|s| !s.is_empty())
2169 name: name.to_owned(),
2170 codegen_units: cgus,
2171 string: full_string,
2175 fn codegen_units_to_str(cgus: &HashSet<String>) -> String
2177 let mut cgus: Vec<_> = cgus.iter().collect();
2180 let mut string = String::new();
2182 string.push_str(&cgu[..]);
2183 string.push_str(" ");
2190 fn init_incremental_test(&self) {
2191 // (See `run_incremental_test` for an overview of how incremental tests work.)
2193 // Before any of the revisions have executed, create the
2194 // incremental workproduct directory. Delete any old
2195 // incremental work products that may be there from prior
2197 let incremental_dir = self.incremental_dir();
2198 if incremental_dir.exists() {
2199 // Canonicalizing the path will convert it to the //?/ format
2200 // on Windows, which enables paths longer than 260 character
2201 let canonicalized = incremental_dir.canonicalize().unwrap();
2202 fs::remove_dir_all(canonicalized).unwrap();
2204 fs::create_dir_all(&incremental_dir).unwrap();
2206 if self.config.verbose {
2207 print!("init_incremental_test: incremental_dir={}", incremental_dir.display());
2211 fn run_incremental_test(&self) {
2212 // Basic plan for a test incremental/foo/bar.rs:
2213 // - load list of revisions rpass1, cfail2, rpass3
2214 // - each should begin with `rpass`, `cfail`, or `cfail`
2215 // - if `rpass`, expect compile and execution to succeed
2216 // - if `cfail`, expect compilation to fail
2217 // - if `rfail`, expect execution to fail
2218 // - create a directory build/foo/bar.incremental
2219 // - compile foo/bar.rs with -Z incremental=.../foo/bar.incremental and -C rpass1
2220 // - because name of revision starts with "rpass", expect success
2221 // - compile foo/bar.rs with -Z incremental=.../foo/bar.incremental and -C cfail2
2222 // - because name of revision starts with "cfail", expect an error
2223 // - load expected errors as usual, but filter for those that end in `[rfail2]`
2224 // - compile foo/bar.rs with -Z incremental=.../foo/bar.incremental and -C rpass3
2225 // - because name of revision starts with "rpass", expect success
2226 // - execute build/foo/bar.exe and save output
2228 // FIXME -- use non-incremental mode as an oracle? That doesn't apply
2229 // to #[rustc_dirty] and clean tests I guess
2231 let revision = self.revision.expect("incremental tests require a list of revisions");
2233 // Incremental workproduct directory should have already been created.
2234 let incremental_dir = self.incremental_dir();
2235 assert!(incremental_dir.exists(), "init_incremental_test failed to create incremental dir");
2237 // Add an extra flag pointing at the incremental directory.
2238 let mut revision_props = self.props.clone();
2239 revision_props.incremental_dir = Some(incremental_dir);
2240 revision_props.compile_flags.push(String::from("-Zincremental-info"));
2242 let revision_cx = TestCx {
2243 config: self.config,
2244 props: &revision_props,
2245 testpaths: self.testpaths,
2246 revision: self.revision,
2249 if self.config.verbose {
2250 print!("revision={:?} revision_props={:#?}", revision, revision_props);
2253 if revision.starts_with("rpass") {
2254 revision_cx.run_rpass_test();
2255 } else if revision.starts_with("rfail") {
2256 revision_cx.run_rfail_test();
2257 } else if revision.starts_with("cfail") {
2258 revision_cx.run_cfail_test();
2261 "revision name must begin with rpass, rfail, or cfail");
2265 /// Directory where incremental work products are stored.
2266 fn incremental_dir(&self) -> PathBuf {
2267 self.output_base_name().with_extension("inc")
2270 fn run_rmake_test(&self) {
2271 // FIXME(#11094): we should fix these tests
2272 if self.config.host != self.config.target {
2276 let cwd = env::current_dir().unwrap();
2277 let src_root = self.config.src_base.parent().unwrap()
2280 let src_root = cwd.join(&src_root);
2282 let tmpdir = cwd.join(self.output_base_name());
2283 if tmpdir.exists() {
2284 self.aggressive_rm_rf(&tmpdir).unwrap();
2286 create_dir_all(&tmpdir).unwrap();
2288 let host = &self.config.host;
2289 let make = if host.contains("bitrig") || host.contains("dragonfly") ||
2290 host.contains("freebsd") || host.contains("netbsd") ||
2291 host.contains("openbsd") {
2297 let mut cmd = Command::new(make);
2298 cmd.current_dir(&self.testpaths.file)
2299 .env("TARGET", &self.config.target)
2300 .env("PYTHON", &self.config.docck_python)
2302 .env("RUST_BUILD_STAGE", &self.config.stage_id)
2303 .env("RUSTC", cwd.join(&self.config.rustc_path))
2304 .env("RUSTDOC", cwd.join(&self.config.rustdoc_path))
2305 .env("TMPDIR", &tmpdir)
2306 .env("LD_LIB_PATH_ENVVAR", procsrv::dylib_env_var())
2307 .env("HOST_RPATH_DIR", cwd.join(&self.config.compile_lib_path))
2308 .env("TARGET_RPATH_DIR", cwd.join(&self.config.run_lib_path))
2309 .env("LLVM_COMPONENTS", &self.config.llvm_components)
2310 .env("LLVM_CXXFLAGS", &self.config.llvm_cxxflags);
2312 // We don't want RUSTFLAGS set from the outside to interfere with
2313 // compiler flags set in the test cases:
2314 cmd.env_remove("RUSTFLAGS");
2316 if self.config.target.contains("msvc") {
2317 // We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
2318 // and that `lib.exe` lives next to it.
2319 let lib = Path::new(&self.config.cc).parent().unwrap().join("lib.exe");
2321 // MSYS doesn't like passing flags of the form `/foo` as it thinks it's
2322 // a path and instead passes `C:\msys64\foo`, so convert all
2323 // `/`-arguments to MSVC here to `-` arguments.
2324 let cflags = self.config.cflags.split(' ').map(|s| s.replace("/", "-"))
2325 .collect::<Vec<_>>().join(" ");
2327 cmd.env("IS_MSVC", "1")
2328 .env("IS_WINDOWS", "1")
2329 .env("MSVC_LIB", format!("'{}' -nologo", lib.display()))
2330 .env("CC", format!("'{}' {}", self.config.cc, cflags))
2331 .env("CXX", &self.config.cxx);
2333 cmd.env("CC", format!("{} {}", self.config.cc, self.config.cflags))
2334 .env("CXX", format!("{} {}", self.config.cxx, self.config.cflags));
2336 if self.config.target.contains("windows") {
2337 cmd.env("IS_WINDOWS", "1");
2341 let output = cmd.output().expect("failed to spawn `make`");
2342 if !output.status.success() {
2344 status: Status::Normal(output.status),
2345 stdout: String::from_utf8_lossy(&output.stdout).into_owned(),
2346 stderr: String::from_utf8_lossy(&output.stderr).into_owned(),
2347 cmdline: format!("{:?}", cmd),
2349 self.fatal_proc_rec("make failed", &res);
2353 fn aggressive_rm_rf(&self, path: &Path) -> io::Result<()> {
2354 for e in path.read_dir()? {
2356 let path = entry.path();
2357 if entry.file_type()?.is_dir() {
2358 self.aggressive_rm_rf(&path)?;
2360 // Remove readonly files as well on windows (by default we can't)
2361 fs::remove_file(&path).or_else(|e| {
2362 if cfg!(windows) && e.kind() == io::ErrorKind::PermissionDenied {
2363 let mut meta = entry.metadata()?.permissions();
2364 meta.set_readonly(false);
2365 fs::set_permissions(&path, meta)?;
2366 fs::remove_file(&path)
2373 fs::remove_dir(path)
2376 fn run_ui_test(&self) {
2377 println!("ui: {}", self.testpaths.file.display());
2379 let proc_res = self.compile_test();
2381 let expected_stderr_path = self.expected_output_path("stderr");
2382 let expected_stderr = self.load_expected_output(&expected_stderr_path);
2384 let expected_stdout_path = self.expected_output_path("stdout");
2385 let expected_stdout = self.load_expected_output(&expected_stdout_path);
2387 let normalized_stdout = self.normalize_output(&proc_res.stdout);
2388 let normalized_stderr = self.normalize_output(&proc_res.stderr);
2391 errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout);
2392 errors += self.compare_output("stderr", &normalized_stderr, &expected_stderr);
2395 println!("To update references, run this command from build directory:");
2396 let relative_path_to_file =
2397 self.testpaths.relative_dir
2398 .join(self.testpaths.file.file_name().unwrap());
2399 println!("{}/update-references.sh '{}' '{}'",
2400 self.config.src_base.display(),
2401 self.config.build_base.display(),
2402 relative_path_to_file.display());
2403 self.fatal_proc_rec(&format!("{} errors occurred comparing output.", errors),
2408 fn run_mir_opt_test(&self) {
2409 let proc_res = self.compile_test();
2411 if !proc_res.status.success() {
2412 self.fatal_proc_rec("compilation failed!", &proc_res);
2415 let proc_res = self.exec_compiled_test();
2417 if !proc_res.status.success() {
2418 self.fatal_proc_rec("test run failed!", &proc_res);
2420 self.check_mir_dump();
2423 fn check_mir_dump(&self) {
2424 let mut test_file_contents = String::new();
2425 fs::File::open(self.testpaths.file.clone()).unwrap()
2426 .read_to_string(&mut test_file_contents)
2428 if let Some(idx) = test_file_contents.find("// END RUST SOURCE") {
2429 let (_, tests_text) = test_file_contents.split_at(idx + "// END_RUST SOURCE".len());
2430 let tests_text_str = String::from(tests_text);
2431 let mut curr_test : Option<&str> = None;
2432 let mut curr_test_contents = Vec::new();
2433 for l in tests_text_str.lines() {
2434 debug!("line: {:?}", l);
2435 if l.starts_with("// START ") {
2436 let (_, t) = l.split_at("// START ".len());
2437 curr_test = Some(t);
2438 } else if l.starts_with("// END") {
2439 let (_, t) = l.split_at("// END ".len());
2440 if Some(t) != curr_test {
2441 panic!("mismatched START END test name");
2443 self.compare_mir_test_output(curr_test.unwrap(), &curr_test_contents);
2445 curr_test_contents.clear();
2446 } else if l.is_empty() {
2448 } else if l.starts_with("// ") {
2449 let (_, test_content) = l.split_at("// ".len());
2450 curr_test_contents.push(test_content);
2456 fn check_mir_test_timestamp(&self, test_name: &str, output_file: &Path) {
2457 let t = |file| FileTime::from_last_modification_time(&fs::metadata(file).unwrap());
2458 let source_file = &self.testpaths.file;
2459 let output_time = t(output_file);
2460 let source_time = t(source_file);
2461 if source_time > output_time {
2462 debug!("source file time: {:?} output file time: {:?}", source_time, output_time);
2463 panic!("test source file `{}` is newer than potentially stale output file `{}`.",
2464 source_file.display(), test_name);
2468 fn compare_mir_test_output(&self, test_name: &str, expected_content: &Vec<&str>) {
2469 let mut output_file = PathBuf::new();
2470 output_file.push(self.get_mir_dump_dir());
2471 output_file.push(test_name);
2472 debug!("comparing the contests of: {:?}", output_file);
2473 debug!("with: {:?}", expected_content);
2474 self.check_mir_test_timestamp(test_name, &output_file);
2476 let mut dumped_file = fs::File::open(output_file.clone()).unwrap();
2477 let mut dumped_string = String::new();
2478 dumped_file.read_to_string(&mut dumped_string).unwrap();
2479 let mut dumped_lines = dumped_string.lines().filter(|l| !l.is_empty());
2480 let mut expected_lines = expected_content.iter().filter(|l| !l.is_empty());
2482 // We expect each non-empty line from expected_content to appear
2483 // in the dump in order, but there may be extra lines interleaved
2484 while let Some(expected_line) = expected_lines.next() {
2485 let e_norm = normalize_mir_line(expected_line);
2486 if e_norm.is_empty() {
2489 let mut found = false;
2490 while let Some(dumped_line) = dumped_lines.next() {
2491 let d_norm = normalize_mir_line(dumped_line);
2492 debug!("found: {:?}", d_norm);
2493 debug!("expected: {:?}", e_norm);
2494 if e_norm == d_norm {
2500 let normalize_all = dumped_string.lines()
2501 .map(nocomment_mir_line)
2502 .filter(|l| !l.is_empty())
2503 .collect::<Vec<_>>()
2505 panic!("ran out of mir dump output to match against.\n\
2506 Did not find expected line: {:?}\n\
2510 expected_content.join("\n"),
2516 fn get_mir_dump_dir(&self) -> PathBuf {
2517 let mut mir_dump_dir = PathBuf::from(self.config.build_base
2521 debug!("input_file: {:?}", self.testpaths.file);
2522 mir_dump_dir.push(self.testpaths.file.file_stem().unwrap().to_str().unwrap());
2526 fn normalize_output(&self, output: &str) -> String {
2527 let parent_dir = self.testpaths.file.parent().unwrap();
2528 let parent_dir_str = parent_dir.display().to_string();
2529 output.replace(&parent_dir_str, "$DIR")
2530 .replace("\\", "/") // normalize for paths on windows
2531 .replace("\r\n", "\n") // normalize for linebreaks on windows
2532 .replace("\t", "\\t") // makes tabs visible
2535 fn expected_output_path(&self, kind: &str) -> PathBuf {
2536 let extension = match self.revision {
2537 Some(r) => format!("{}.{}", r, kind),
2538 None => kind.to_string(),
2540 self.testpaths.file.with_extension(extension)
2543 fn load_expected_output(&self, path: &Path) -> String {
2545 return String::new();
2548 let mut result = String::new();
2549 match File::open(path).and_then(|mut f| f.read_to_string(&mut result)) {
2552 self.fatal(&format!("failed to load expected output from `{}`: {}",
2558 fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize {
2559 if actual == expected {
2563 println!("normalized {}:\n{}\n", kind, actual);
2564 println!("expected {}:\n{}\n", kind, expected);
2565 println!("diff of {}:\n", kind);
2566 for line in uidiff::diff_lines(actual, expected) {
2567 println!("{}", line);
2570 let output_file = self.output_base_name().with_extension(kind);
2571 match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) {
2574 self.fatal(&format!("failed to write {} to `{}`: {}",
2575 kind, output_file.display(), e))
2579 println!("\nThe actual {0} differed from the expected {0}.", kind);
2580 println!("Actual {} saved to {}", kind, output_file.display());
2590 pub struct ProcRes {
2603 pub fn fatal(&self, err: Option<&str>) -> ! {
2604 if let Some(e) = err {
2605 println!("\nerror: {}", e);
2611 ------------------------------------------\n\
2613 ------------------------------------------\n\
2615 ------------------------------------------\n\
2617 ------------------------------------------\n\
2619 self.status, self.cmdline, self.stdout,
2626 fn code(&self) -> Option<i32> {
2628 Status::Parsed(i) => Some(i),
2629 Status::Normal(ref e) => e.code(),
2633 fn success(&self) -> bool {
2635 Status::Parsed(i) => i == 0,
2636 Status::Normal(ref e) => e.success(),
2641 impl fmt::Display for Status {
2642 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2644 Status::Parsed(i) => write!(f, "exit code: {}", i),
2645 Status::Normal(ref e) => e.fmt(f),
2650 enum TargetLocation {
2652 ThisDirectory(PathBuf),
2655 fn normalize_mir_line(line: &str) -> String {
2656 nocomment_mir_line(line).replace(char::is_whitespace, "")
2659 fn nocomment_mir_line(line: &str) -> &str {
2660 if let Some(idx) = line.find("//") {
2661 let (l, _) = line.split_at(idx);