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};
17 use header::TestProps;
24 use std::collections::HashSet;
27 use std::fs::{self, File};
28 use std::io::prelude::*;
29 use std::io::{self, BufReader};
30 use std::path::{Path, PathBuf};
31 use std::process::{Command, Output, ExitStatus};
33 use std::collections::HashMap;
35 use extract_gdb_version;
37 pub fn run(config: Config, testpaths: &TestPaths) {
38 match &*config.target {
40 "arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
41 if !config.adb_device_status {
42 panic!("android device not available");
47 // android has its own gdb handling
48 if config.mode == DebugInfoGdb && config.gdb.is_none() {
49 panic!("gdb not available but debuginfo gdb debuginfo test requested");
55 // We're going to be dumping a lot of info. Start on a new line.
58 debug!("running {:?}", testpaths.file.display());
59 let base_props = TestProps::from_file(&testpaths.file);
61 let base_cx = TestCx { config: &config,
67 if base_props.revisions.is_empty() {
68 base_cx.run_revision()
70 for revision in &base_props.revisions {
71 let mut revision_props = base_props.clone();
72 revision_props.load_from(&testpaths.file, Some(&revision));
75 props: &revision_props,
77 revision: Some(revision)
79 rev_cx.run_revision();
83 base_cx.complete_all();
85 File::create(::stamp(&config, &testpaths)).unwrap();
88 struct TestCx<'test> {
89 config: &'test Config,
90 props: &'test TestProps,
91 testpaths: &'test TestPaths,
92 revision: Option<&'test str>
95 struct DebuggerCommands {
96 commands: Vec<String>,
97 check_lines: Vec<String>,
98 breakpoint_lines: Vec<usize>,
101 impl<'test> TestCx<'test> {
102 /// invoked once before any revisions have been processed
104 assert!(self.revision.is_none(), "init_all invoked for a revision");
105 match self.config.mode {
106 Incremental => self.init_incremental_test(),
111 /// Code executed for each revision in turn (or, if there are no
112 /// revisions, exactly once, with revision == None).
113 fn run_revision(&self) {
114 match self.config.mode {
115 CompileFail => self.run_cfail_test(),
116 ParseFail => self.run_cfail_test(),
117 RunFail => self.run_rfail_test(),
118 RunPass => self.run_rpass_test(),
119 RunPassValgrind => self.run_valgrind_test(),
120 Pretty => self.run_pretty_test(),
121 DebugInfoGdb => self.run_debuginfo_gdb_test(),
122 DebugInfoLldb => self.run_debuginfo_lldb_test(),
123 Codegen => self.run_codegen_test(),
124 Rustdoc => self.run_rustdoc_test(),
125 CodegenUnits => self.run_codegen_units_test(),
126 Incremental => self.run_incremental_test(),
127 RunMake => self.run_rmake_test(),
128 Ui => self.run_ui_test(),
129 MirOpt => self.run_mir_opt_test(),
133 /// Invoked after all revisions have executed.
134 fn complete_all(&self) {
135 assert!(self.revision.is_none(), "init_all invoked for a revision");
138 fn run_cfail_test(&self) {
139 let proc_res = self.compile_test();
141 if self.props.must_compile_successfully {
142 if !proc_res.status.success() {
144 "test compilation failed although it shouldn't!",
148 if proc_res.status.success() {
150 &format!("{} test compiled successfully!", self.config.mode)[..],
154 self.check_correct_failure_status(&proc_res);
157 let output_to_check = self.get_output(&proc_res);
158 let expected_errors = errors::load_errors(&self.testpaths.file, self.revision);
159 if !expected_errors.is_empty() {
160 if !self.props.error_patterns.is_empty() {
161 self.fatal("both error pattern and expected errors specified");
163 self.check_expected_errors(expected_errors, &proc_res);
165 self.check_error_patterns(&output_to_check, &proc_res);
168 self.check_no_compiler_crash(&proc_res);
169 self.check_forbid_output(&output_to_check, &proc_res);
172 fn run_rfail_test(&self) {
173 let proc_res = self.compile_test();
175 if !proc_res.status.success() {
176 self.fatal_proc_rec("compilation failed!", &proc_res);
179 let proc_res = self.exec_compiled_test();
181 // The value our Makefile configures valgrind to return on failure
182 const VALGRIND_ERR: i32 = 100;
183 if proc_res.status.code() == Some(VALGRIND_ERR) {
184 self.fatal_proc_rec("run-fail test isn't valgrind-clean!", &proc_res);
187 let output_to_check = self.get_output(&proc_res);
188 self.check_correct_failure_status(&proc_res);
189 self.check_error_patterns(&output_to_check, &proc_res);
192 fn get_output(&self, proc_res: &ProcRes) -> String {
193 if self.props.check_stdout {
194 format!("{}{}", proc_res.stdout, proc_res.stderr)
196 proc_res.stderr.clone()
200 fn check_correct_failure_status(&self, proc_res: &ProcRes) {
201 // The value the rust runtime returns on failure
202 const RUST_ERR: i32 = 101;
203 if proc_res.status.code() != Some(RUST_ERR) {
205 &format!("failure produced the wrong error: {}",
211 fn run_rpass_test(&self) {
212 let proc_res = self.compile_test();
214 if !proc_res.status.success() {
215 self.fatal_proc_rec("compilation failed!", &proc_res);
218 let expected_errors = errors::load_errors(&self.testpaths.file, self.revision);
219 if !expected_errors.is_empty() {
220 self.check_expected_errors(expected_errors, &proc_res);
223 let proc_res = self.exec_compiled_test();
225 if !proc_res.status.success() {
226 self.fatal_proc_rec("test run failed!", &proc_res);
230 fn run_valgrind_test(&self) {
231 assert!(self.revision.is_none(), "revisions not relevant here");
233 if self.config.valgrind_path.is_none() {
234 assert!(!self.config.force_valgrind);
235 return self.run_rpass_test();
238 let mut proc_res = self.compile_test();
240 if !proc_res.status.success() {
241 self.fatal_proc_rec("compilation failed!", &proc_res);
244 let mut new_config = self.config.clone();
245 new_config.runtool = new_config.valgrind_path.clone();
246 let new_cx = TestCx { config: &new_config, ..*self };
247 proc_res = new_cx.exec_compiled_test();
249 if !proc_res.status.success() {
250 self.fatal_proc_rec("test run failed!", &proc_res);
254 fn run_pretty_test(&self) {
255 if self.props.pp_exact.is_some() {
256 logv(self.config, "testing for exact pretty-printing".to_owned());
258 logv(self.config, "testing for converging pretty-printing".to_owned());
261 let rounds = match self.props.pp_exact { Some(_) => 1, None => 2 };
263 let mut src = String::new();
264 File::open(&self.testpaths.file).unwrap().read_to_string(&mut src).unwrap();
265 let mut srcs = vec![src];
268 while round < rounds {
269 logv(self.config, format!("pretty-printing round {} revision {:?}",
270 round, self.revision));
271 let proc_res = self.print_source(srcs[round].to_owned(), &self.props.pretty_mode);
273 if !proc_res.status.success() {
274 self.fatal_proc_rec(&format!("pretty-printing failed in round {} revision {:?}",
275 round, self.revision),
279 let ProcRes{ stdout, .. } = proc_res;
284 let mut expected = match self.props.pp_exact {
286 let filepath = self.testpaths.file.parent().unwrap().join(file);
287 let mut s = String::new();
288 File::open(&filepath).unwrap().read_to_string(&mut s).unwrap();
291 None => { srcs[srcs.len() - 2].clone() }
293 let mut actual = srcs[srcs.len() - 1].clone();
295 if self.props.pp_exact.is_some() {
296 // Now we have to care about line endings
297 let cr = "\r".to_owned();
298 actual = actual.replace(&cr, "").to_owned();
299 expected = expected.replace(&cr, "").to_owned();
302 self.compare_source(&expected, &actual);
304 // If we're only making sure that the output matches then just stop here
305 if self.props.pretty_compare_only { return; }
307 // Finally, let's make sure it actually appears to remain valid code
308 let proc_res = self.typecheck_source(actual);
309 if !proc_res.status.success() {
310 self.fatal_proc_rec("pretty-printed source does not typecheck", &proc_res);
313 if !self.props.pretty_expanded { return }
315 // additionally, run `--pretty expanded` and try to build it.
316 let proc_res = self.print_source(srcs[round].clone(), "expanded");
317 if !proc_res.status.success() {
318 self.fatal_proc_rec("pretty-printing (expanded) failed", &proc_res);
321 let ProcRes{ stdout: expanded_src, .. } = proc_res;
322 let proc_res = self.typecheck_source(expanded_src);
323 if !proc_res.status.success() {
325 "pretty-printed source (expanded) does not typecheck",
330 fn print_source(&self,
334 let aux_dir = self.aux_output_dir_name();
335 self.compose_and_run(self.make_pp_args(pretty_type.to_owned()),
336 self.props.exec_env.clone(),
337 self.config.compile_lib_path.to_str().unwrap(),
338 Some(aux_dir.to_str().unwrap()),
342 fn make_pp_args(&self,
345 let aux_dir = self.aux_output_dir_name();
346 // FIXME (#9639): This needs to handle non-utf8 paths
347 let mut args = vec!["-".to_owned(),
348 "-Zunstable-options".to_owned(),
349 "--unpretty".to_owned(),
351 format!("--target={}", self.config.target),
353 aux_dir.to_str().unwrap().to_owned()];
354 args.extend(self.split_maybe_args(&self.config.target_rustcflags));
355 args.extend(self.props.compile_flags.iter().cloned());
357 prog: self.config.rustc_path.to_str().unwrap().to_owned(),
362 fn compare_source(&self,
365 if expected != actual {
366 self.error("pretty-printed source does not match expected source");
369 ------------------------------------------\n\
371 ------------------------------------------\n\
373 ------------------------------------------\n\
375 ------------------------------------------\n\
382 fn typecheck_source(&self, src: String) -> ProcRes {
383 let args = self.make_typecheck_args();
384 self.compose_and_run_compiler(args, Some(src))
387 fn make_typecheck_args(&self) -> ProcArgs {
388 let aux_dir = self.aux_output_dir_name();
389 let target = if self.props.force_host {
395 let out_dir = self.output_base_name().with_extension("pretty-out");
396 let _ = fs::remove_dir_all(&out_dir);
397 self.create_dir_racy(&out_dir);
399 // FIXME (#9639): This needs to handle non-utf8 paths
400 let mut args = vec!["-".to_owned(),
401 "-Zno-trans".to_owned(),
402 "--out-dir".to_owned(),
403 out_dir.to_str().unwrap().to_owned(),
404 format!("--target={}", target),
406 self.config.build_base.to_str().unwrap().to_owned(),
408 aux_dir.to_str().unwrap().to_owned()];
409 if let Some(revision) = self.revision {
412 format!("{}", revision),
415 args.extend(self.split_maybe_args(&self.config.target_rustcflags));
416 args.extend(self.props.compile_flags.iter().cloned());
417 // FIXME (#9639): This needs to handle non-utf8 paths
419 prog: self.config.rustc_path.to_str().unwrap().to_owned(),
424 fn run_debuginfo_gdb_test(&self) {
425 assert!(self.revision.is_none(), "revisions not relevant here");
427 let config = Config {
428 target_rustcflags: self.cleanup_debug_info_options(&self.config.target_rustcflags),
429 host_rustcflags: self.cleanup_debug_info_options(&self.config.host_rustcflags),
430 .. self.config.clone()
433 let test_cx = TestCx {
438 test_cx.run_debuginfo_gdb_test_no_opt();
441 fn run_debuginfo_gdb_test_no_opt(&self) {
442 let prefixes = if self.config.gdb_native_rust {
444 static PREFIXES: &'static [&'static str] = &["gdb", "gdbr"];
445 println!("NOTE: compiletest thinks it is using GDB with native rust support");
449 static PREFIXES: &'static [&'static str] = &["gdb", "gdbg"];
450 println!("NOTE: compiletest thinks it is using GDB without native rust support");
454 let DebuggerCommands {
458 } = self.parse_debugger_commands(prefixes);
459 let mut cmds = commands.join("\n");
461 // compile test file (it should have 'compile-flags:-g' in the header)
462 let compiler_run_result = self.compile_test();
463 if !compiler_run_result.status.success() {
464 self.fatal_proc_rec("compilation failed!", &compiler_run_result);
467 let exe_file = self.make_exe_name();
469 let debugger_run_result;
470 match &*self.config.target {
471 "arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
473 cmds = cmds.replace("run", "continue");
475 let tool_path = match self.config.android_cross_path.to_str() {
476 Some(x) => x.to_owned(),
477 None => self.fatal("cannot find android cross path")
480 // write debugger script
481 let mut script_str = String::with_capacity(2048);
482 script_str.push_str(&format!("set charset {}\n", Self::charset()));
483 script_str.push_str(&format!("set sysroot {}\n", tool_path));
484 script_str.push_str(&format!("file {}\n", exe_file.to_str().unwrap()));
485 script_str.push_str("target remote :5039\n");
486 script_str.push_str(&format!("set solib-search-path \
487 ./{}/stage2/lib/rustlib/{}/lib/\n",
488 self.config.host, self.config.target));
489 for line in &breakpoint_lines {
490 script_str.push_str(&format!("break {:?}:{}\n",
491 self.testpaths.file.file_name()
496 script_str.push_str(&cmds);
497 script_str.push_str("\nquit\n");
499 debug!("script_str = {}", script_str);
500 self.dump_output_file(&script_str, "debugger.script");
504 &self.config.adb_path,
508 exe_file.to_str().unwrap().to_owned(),
509 self.config.adb_test_dir.clone()
513 .expect(&format!("failed to exec `{:?}`", self.config.adb_path));
516 &self.config.adb_path,
519 "forward".to_owned(),
520 "tcp:5039".to_owned(),
521 "tcp:5039".to_owned()
525 .expect(&format!("failed to exec `{:?}`", self.config.adb_path));
527 let adb_arg = format!("export LD_LIBRARY_PATH={}; \
528 gdbserver{} :5039 {}/{}",
529 self.config.adb_test_dir.clone(),
530 if self.config.target.contains("aarch64")
532 self.config.adb_test_dir.clone(),
533 exe_file.file_name().unwrap().to_str()
536 let mut process = procsrv::run_background("",
537 &self.config.adb_path
546 .expect(&format!("failed to exec `{:?}`", self.config.adb_path));
548 // Wait for the gdbserver to print out "Listening on port ..."
549 // at which point we know that it's started and then we can
550 // execute the debugger below.
551 let mut stdout = BufReader::new(process.stdout.take().unwrap());
552 let mut line = String::new();
555 stdout.read_line(&mut line).unwrap();
556 if line.starts_with("Listening on port 5039") {
562 let debugger_script = self.make_out_name("debugger.script");
563 // FIXME (#9639): This needs to handle non-utf8 paths
565 vec!["-quiet".to_owned(),
568 format!("-command={}", debugger_script.to_str().unwrap())];
570 let mut gdb_path = tool_path;
571 gdb_path.push_str(&format!("/bin/{}-gdb", self.config.target));
572 let procsrv::Result {
582 .expect(&format!("failed to exec `{:?}`", gdb_path));
584 let cmdline = self.make_cmdline("",
585 &format!("{}-gdb", self.config.target),
587 logv(self.config, format!("executing {}", cmdline));
591 debugger_run_result = ProcRes {
592 status: Status::Normal(status),
597 if process.kill().is_err() {
598 println!("Adb process is already finished.");
603 let rust_src_root = self.find_rust_src_root()
604 .expect("Could not find Rust source root");
605 let rust_pp_module_rel_path = Path::new("./src/etc");
606 let rust_pp_module_abs_path = rust_src_root.join(rust_pp_module_rel_path)
610 // write debugger script
611 let mut script_str = String::with_capacity(2048);
612 script_str.push_str(&format!("set charset {}\n", Self::charset()));
613 script_str.push_str("show version\n");
615 match self.config.gdb_version {
617 println!("NOTE: compiletest thinks it is using GDB version {}",
620 if version > extract_gdb_version("7.4").unwrap() {
621 // Add the directory containing the pretty printers to
622 // GDB's script auto loading safe path
624 &format!("add-auto-load-safe-path {}\n",
625 rust_pp_module_abs_path.replace(r"\", r"\\"))
630 println!("NOTE: compiletest does not know which version of \
635 // The following line actually doesn't have to do anything with
636 // pretty printing, it just tells GDB to print values on one line:
637 script_str.push_str("set print pretty off\n");
639 // Add the pretty printer directory to GDB's source-file search path
640 script_str.push_str(&format!("directory {}\n",
641 rust_pp_module_abs_path));
643 // Load the target executable
644 script_str.push_str(&format!("file {}\n",
645 exe_file.to_str().unwrap()
646 .replace(r"\", r"\\")));
648 // Add line breakpoints
649 for line in &breakpoint_lines {
650 script_str.push_str(&format!("break '{}':{}\n",
651 self.testpaths.file.file_name().unwrap()
656 script_str.push_str(&cmds);
657 script_str.push_str("\nquit\n");
659 debug!("script_str = {}", script_str);
660 self.dump_output_file(&script_str, "debugger.script");
662 let debugger_script = self.make_out_name("debugger.script");
664 // FIXME (#9639): This needs to handle non-utf8 paths
666 vec!["-quiet".to_owned(),
669 format!("-command={}", debugger_script.to_str().unwrap())];
671 let proc_args = ProcArgs {
672 prog: self.config.gdb.as_ref().unwrap().to_owned(),
676 let environment = vec![("PYTHONPATH".to_owned(), rust_pp_module_abs_path)];
678 debugger_run_result =
679 self.compose_and_run(proc_args,
681 self.config.run_lib_path.to_str().unwrap(),
687 if !debugger_run_result.status.success() {
688 self.fatal("gdb failed to execute");
691 self.check_debugger_output(&debugger_run_result, &check_lines);
694 fn find_rust_src_root(&self) -> Option<PathBuf> {
695 let mut path = self.config.src_base.clone();
696 let path_postfix = Path::new("src/etc/lldb_batchmode.py");
699 if path.join(&path_postfix).is_file() {
707 fn run_debuginfo_lldb_test(&self) {
708 assert!(self.revision.is_none(), "revisions not relevant here");
710 if self.config.lldb_python_dir.is_none() {
711 self.fatal("Can't run LLDB test because LLDB's python path is not set.");
714 let config = Config {
715 target_rustcflags: self.cleanup_debug_info_options(&self.config.target_rustcflags),
716 host_rustcflags: self.cleanup_debug_info_options(&self.config.host_rustcflags),
717 .. self.config.clone()
721 let test_cx = TestCx {
726 test_cx.run_debuginfo_lldb_test_no_opt();
729 fn run_debuginfo_lldb_test_no_opt(&self) {
730 // compile test file (it should have 'compile-flags:-g' in the header)
731 let compile_result = self.compile_test();
732 if !compile_result.status.success() {
733 self.fatal_proc_rec("compilation failed!", &compile_result);
736 let exe_file = self.make_exe_name();
738 match self.config.lldb_version {
739 Some(ref version) => {
740 println!("NOTE: compiletest thinks it is using LLDB version {}",
744 println!("NOTE: compiletest does not know which version of \
749 // Parse debugger commands etc from test files
750 let DebuggerCommands {
755 } = self.parse_debugger_commands(&["lldb"]);
757 // Write debugger script:
758 // We don't want to hang when calling `quit` while the process is still running
759 let mut script_str = String::from("settings set auto-confirm true\n");
761 // Make LLDB emit its version, so we have it documented in the test output
762 script_str.push_str("version\n");
764 // Switch LLDB into "Rust mode"
765 let rust_src_root = self.find_rust_src_root().expect("Could not find Rust source root");
766 let rust_pp_module_rel_path = Path::new("./src/etc/lldb_rust_formatters.py");
767 let rust_pp_module_abs_path = rust_src_root.join(rust_pp_module_rel_path)
772 script_str.push_str(&format!("command script import {}\n",
773 &rust_pp_module_abs_path[..])[..]);
774 script_str.push_str("type summary add --no-value ");
775 script_str.push_str("--python-function lldb_rust_formatters.print_val ");
776 script_str.push_str("-x \".*\" --category Rust\n");
777 script_str.push_str("type category enable Rust\n");
779 // Set breakpoints on every line that contains the string "#break"
780 let source_file_name = self.testpaths.file.file_name().unwrap().to_string_lossy();
781 for line in &breakpoint_lines {
782 script_str.push_str(&format!("breakpoint set --file '{}' --line {}\n",
787 // Append the other commands
788 for line in &commands {
789 script_str.push_str(line);
790 script_str.push_str("\n");
793 // Finally, quit the debugger
794 script_str.push_str("\nquit\n");
796 // Write the script into a file
797 debug!("script_str = {}", script_str);
798 self.dump_output_file(&script_str, "debugger.script");
799 let debugger_script = self.make_out_name("debugger.script");
801 // Let LLDB execute the script via lldb_batchmode.py
802 let debugger_run_result = self.run_lldb(&exe_file,
806 if !debugger_run_result.status.success() {
807 self.fatal_proc_rec("Error while running LLDB", &debugger_run_result);
810 self.check_debugger_output(&debugger_run_result, &check_lines);
814 test_executable: &Path,
815 debugger_script: &Path,
816 rust_src_root: &Path)
818 // Prepare the lldb_batchmode which executes the debugger script
819 let lldb_script_path = rust_src_root.join("src/etc/lldb_batchmode.py");
820 self.cmd2procres(Command::new(&self.config.lldb_python)
821 .arg(&lldb_script_path)
822 .arg(test_executable)
823 .arg(debugger_script)
825 self.config.lldb_python_dir.as_ref().unwrap()))
828 fn cmd2procres(&self, cmd: &mut Command) -> ProcRes {
829 let (status, out, err) = match cmd.output() {
830 Ok(Output { status, stdout, stderr }) => {
832 String::from_utf8(stdout).unwrap(),
833 String::from_utf8(stderr).unwrap())
836 self.fatal(&format!("Failed to setup Python process for \
837 LLDB script: {}", e))
841 self.dump_output(&out, &err);
843 status: Status::Normal(status),
846 cmdline: format!("{:?}", cmd)
850 fn parse_debugger_commands(&self, debugger_prefixes: &[&str]) -> DebuggerCommands {
851 let directives = debugger_prefixes.iter().map(|prefix| (
852 format!("{}-command", prefix),
853 format!("{}-check", prefix),
854 )).collect::<Vec<_>>();
856 let mut breakpoint_lines = vec![];
857 let mut commands = vec![];
858 let mut check_lines = vec![];
860 let reader = BufReader::new(File::open(&self.testpaths.file).unwrap());
861 for line in reader.lines() {
864 if line.contains("#break") {
865 breakpoint_lines.push(counter);
868 for &(ref command_directive, ref check_directive) in &directives {
869 header::parse_name_value_directive(
871 &command_directive).map(|cmd| {
875 header::parse_name_value_directive(
877 &check_directive).map(|cmd| {
878 check_lines.push(cmd)
883 self.fatal(&format!("Error while parsing debugger commands: {}", e))
891 check_lines: check_lines,
892 breakpoint_lines: breakpoint_lines,
896 fn cleanup_debug_info_options(&self, options: &Option<String>) -> Option<String> {
897 if options.is_none() {
901 // Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
902 let options_to_remove = [
905 "--debuginfo".to_owned()
908 self.split_maybe_args(options).into_iter()
909 .filter(|x| !options_to_remove.contains(x))
910 .collect::<Vec<String>>();
912 Some(new_options.join(" "))
915 fn check_debugger_output(&self, debugger_run_result: &ProcRes, check_lines: &[String]) {
916 let num_check_lines = check_lines.len();
918 let mut check_line_index = 0;
919 for line in debugger_run_result.stdout.lines() {
920 if check_line_index >= num_check_lines {
924 if check_single_line(line, &(check_lines[check_line_index])[..]) {
925 check_line_index += 1;
928 if check_line_index != num_check_lines && num_check_lines > 0 {
929 self.fatal_proc_rec(&format!("line not found in debugger output: {}",
930 check_lines[check_line_index]),
931 debugger_run_result);
934 fn check_single_line(line: &str, check_line: &str) -> bool {
935 // Allow check lines to leave parts unspecified (e.g., uninitialized
936 // bits in the wrong case of an enum) with the notation "[...]".
937 let line = line.trim();
938 let check_line = check_line.trim();
939 let can_start_anywhere = check_line.starts_with("[...]");
940 let can_end_anywhere = check_line.ends_with("[...]");
942 let check_fragments: Vec<&str> = check_line.split("[...]")
943 .filter(|frag| !frag.is_empty())
945 if check_fragments.is_empty() {
949 let (mut rest, first_fragment) = if can_start_anywhere {
950 match line.find(check_fragments[0]) {
951 Some(pos) => (&line[pos + check_fragments[0].len() ..], 1),
958 for fragment_index in first_fragment .. check_fragments.len() {
959 let current_fragment = check_fragments[fragment_index];
960 match rest.find(current_fragment) {
962 rest = &rest[pos + current_fragment.len() .. ];
968 if !can_end_anywhere && !rest.is_empty() {
976 fn check_error_patterns(&self,
977 output_to_check: &str,
978 proc_res: &ProcRes) {
979 if self.props.error_patterns.is_empty() {
980 if self.props.must_compile_successfully {
983 self.fatal(&format!("no error pattern specified in {:?}",
984 self.testpaths.file.display()));
987 let mut next_err_idx = 0;
988 let mut next_err_pat = self.props.error_patterns[next_err_idx].trim();
989 let mut done = false;
990 for line in output_to_check.lines() {
991 if line.contains(next_err_pat) {
992 debug!("found error pattern {}", next_err_pat);
994 if next_err_idx == self.props.error_patterns.len() {
995 debug!("found all error patterns");
999 next_err_pat = self.props.error_patterns[next_err_idx].trim();
1004 let missing_patterns = &self.props.error_patterns[next_err_idx..];
1005 if missing_patterns.len() == 1 {
1006 self.fatal_proc_rec(
1007 &format!("error pattern '{}' not found!", missing_patterns[0]),
1010 for pattern in missing_patterns {
1011 self.error(&format!("error pattern '{}' not found!", *pattern));
1013 self.fatal_proc_rec("multiple error patterns not found", proc_res);
1017 fn check_no_compiler_crash(&self, proc_res: &ProcRes) {
1018 for line in proc_res.stderr.lines() {
1019 if line.contains("error: internal compiler error") {
1020 self.fatal_proc_rec("compiler encountered internal error", proc_res);
1025 fn check_forbid_output(&self,
1026 output_to_check: &str,
1027 proc_res: &ProcRes) {
1028 for pat in &self.props.forbid_output {
1029 if output_to_check.contains(pat) {
1030 self.fatal_proc_rec("forbidden pattern found in compiler output", proc_res);
1035 fn check_expected_errors(&self,
1036 expected_errors: Vec<errors::Error>,
1037 proc_res: &ProcRes) {
1038 if proc_res.status.success() &&
1039 expected_errors.iter().any(|x| x.kind == Some(ErrorKind::Error)) {
1040 self.fatal_proc_rec("process did not return an error status", proc_res);
1044 format!("{}", self.testpaths.file.display())
1045 .replace(r"\", "/"); // on windows, translate all '\' path separators to '/'
1047 // If the testcase being checked contains at least one expected "help"
1048 // message, then we'll ensure that all "help" messages are expected.
1049 // Otherwise, all "help" messages reported by the compiler will be ignored.
1050 // This logic also applies to "note" messages.
1051 let expect_help = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Help));
1052 let expect_note = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Note));
1054 // Parse the JSON output from the compiler and extract out the messages.
1055 let actual_errors = json::parse_output(&file_name, &proc_res.stderr, &proc_res);
1056 let mut unexpected = Vec::new();
1057 let mut found = vec![false; expected_errors.len()];
1058 for actual_error in &actual_errors {
1063 .position(|(index, expected_error)| {
1065 actual_error.line_num == expected_error.line_num &&
1066 (expected_error.kind.is_none() ||
1067 actual_error.kind == expected_error.kind) &&
1068 actual_error.msg.contains(&expected_error.msg)
1073 // found a match, everybody is happy
1074 assert!(!found[index]);
1075 found[index] = true;
1079 if self.is_unexpected_compiler_message(actual_error, expect_help, expect_note) {
1081 &format!("{}:{}: unexpected {:?}: '{}'",
1083 actual_error.line_num,
1084 actual_error.kind.as_ref()
1085 .map_or(String::from("message"),
1088 unexpected.push(actual_error.clone());
1094 let mut not_found = Vec::new();
1095 // anything not yet found is a problem
1096 for (index, expected_error) in expected_errors.iter().enumerate() {
1099 &format!("{}:{}: expected {} not found: {}",
1101 expected_error.line_num,
1102 expected_error.kind.as_ref()
1103 .map_or("message".into(),
1105 expected_error.msg));
1106 not_found.push(expected_error.clone());
1110 if unexpected.len() > 0 || not_found.len() > 0 {
1112 &format!("{} unexpected errors found, {} expected errors not found",
1113 unexpected.len(), not_found.len()));
1114 print!("status: {}\ncommand: {}\n",
1115 proc_res.status, proc_res.cmdline);
1116 if unexpected.len() > 0 {
1117 println!("unexpected errors (from JSON output): {:#?}\n", unexpected);
1119 if not_found.len() > 0 {
1120 println!("not found errors (from test file): {:#?}\n", not_found);
1126 /// Returns true if we should report an error about `actual_error`,
1127 /// which did not match any of the expected error. We always require
1128 /// errors/warnings to be explicitly listed, but only require
1129 /// helps/notes if there are explicit helps/notes given.
1130 fn is_unexpected_compiler_message(&self,
1131 actual_error: &Error,
1135 match actual_error.kind {
1136 Some(ErrorKind::Help) => expect_help,
1137 Some(ErrorKind::Note) => expect_note,
1138 Some(ErrorKind::Error) => true,
1139 Some(ErrorKind::Warning) => true,
1140 Some(ErrorKind::Suggestion) => false,
1145 fn compile_test(&self) -> ProcRes {
1146 let aux_dir = self.aux_output_dir_name();
1147 // FIXME (#9639): This needs to handle non-utf8 paths
1148 let link_args = vec!["-L".to_owned(),
1149 aux_dir.to_str().unwrap().to_owned()];
1150 let args = self.make_compile_args(link_args,
1151 &self.testpaths.file,
1152 TargetLocation::ThisFile(self.make_exe_name()));
1153 self.compose_and_run_compiler(args, None)
1156 fn document(&self, out_dir: &Path) -> ProcRes {
1157 if self.props.build_aux_docs {
1158 for rel_ab in &self.props.aux_builds {
1159 let aux_testpaths = self.compute_aux_test_paths(rel_ab);
1160 let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision);
1161 let aux_cx = TestCx {
1162 config: self.config,
1164 testpaths: &aux_testpaths,
1165 revision: self.revision
1167 let auxres = aux_cx.document(out_dir);
1168 if !auxres.status.success() {
1174 let aux_dir = self.aux_output_dir_name();
1175 let mut args = vec!["-L".to_owned(),
1176 aux_dir.to_str().unwrap().to_owned(),
1178 out_dir.to_str().unwrap().to_owned(),
1179 self.testpaths.file.to_str().unwrap().to_owned()];
1180 args.extend(self.props.compile_flags.iter().cloned());
1181 let args = ProcArgs {
1182 prog: self.config.rustdoc_path.to_str().unwrap().to_owned(),
1185 self.compose_and_run_compiler(args, None)
1188 fn exec_compiled_test(&self) -> ProcRes {
1189 let env = self.props.exec_env.clone();
1191 match &*self.config.target {
1193 "arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
1194 self._arm_exec_compiled_test(env)
1197 // This is pretty similar to below, we're transforming:
1199 // program arg1 arg2
1203 // qemu-test-client run program:support-lib.so arg1 arg2
1205 // The test-client program will upload `program` to the emulator
1206 // along with all other support libraries listed (in this case
1207 // `support-lib.so`. It will then execute the program on the
1208 // emulator with the arguments specified (in the environment we give
1209 // the process) and then report back the same result.
1210 _ if self.config.qemu_test_client.is_some() => {
1211 let aux_dir = self.aux_output_dir_name();
1212 let mut args = self.make_run_args();
1213 let mut program = args.prog.clone();
1214 if let Ok(entries) = aux_dir.read_dir() {
1215 for entry in entries {
1216 let entry = entry.unwrap();
1217 if !entry.path().is_file() {
1220 program.push_str(":");
1221 program.push_str(entry.path().to_str().unwrap());
1224 args.args.insert(0, program);
1225 args.args.insert(0, "run".to_string());
1226 args.prog = self.config.qemu_test_client.clone().unwrap()
1227 .into_os_string().into_string().unwrap();
1228 self.compose_and_run(args,
1230 self.config.run_lib_path.to_str().unwrap(),
1231 Some(aux_dir.to_str().unwrap()),
1235 let aux_dir = self.aux_output_dir_name();
1236 self.compose_and_run(self.make_run_args(),
1238 self.config.run_lib_path.to_str().unwrap(),
1239 Some(aux_dir.to_str().unwrap()),
1245 /// For each `aux-build: foo/bar` annotation, we check to find the
1246 /// file in a `aux` directory relative to the test itself.
1247 fn compute_aux_test_paths(&self, rel_ab: &str) -> TestPaths {
1248 let test_ab = self.testpaths.file
1250 .expect("test file path has no parent")
1253 if !test_ab.exists() {
1254 self.fatal(&format!("aux-build `{}` source not found", test_ab.display()))
1259 base: self.testpaths.base.clone(),
1260 relative_dir: self.testpaths.relative_dir
1264 .expect("aux-build path has no parent")
1269 fn compose_and_run_compiler(&self, args: ProcArgs, input: Option<String>) -> ProcRes {
1270 if !self.props.aux_builds.is_empty() {
1271 self.create_dir_racy(&self.aux_output_dir_name());
1274 let aux_dir = self.aux_output_dir_name();
1275 // FIXME (#9639): This needs to handle non-utf8 paths
1276 let extra_link_args = vec!["-L".to_owned(),
1277 aux_dir.to_str().unwrap().to_owned()];
1279 for rel_ab in &self.props.aux_builds {
1280 let aux_testpaths = self.compute_aux_test_paths(rel_ab);
1281 let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision);
1282 let mut crate_type = if aux_props.no_prefer_dynamic {
1285 // We primarily compile all auxiliary libraries as dynamic libraries
1286 // to avoid code size bloat and large binaries as much as possible
1287 // for the test suite (otherwise including libstd statically in all
1288 // executables takes up quite a bit of space).
1290 // For targets like MUSL or Emscripten, however, there is no support for
1291 // dynamic libraries so we just go back to building a normal library. Note,
1292 // however, that for MUSL if the library is built with `force_host` then
1293 // it's ok to be a dylib as the host should always support dylibs.
1294 if (self.config.target.contains("musl") && !aux_props.force_host) ||
1295 self.config.target.contains("emscripten")
1297 vec!["--crate-type=lib".to_owned()]
1299 vec!["--crate-type=dylib".to_owned()]
1302 crate_type.extend(extra_link_args.clone());
1304 let f = self.make_lib_name(&self.testpaths.file);
1305 let parent = f.parent().unwrap();
1306 TargetLocation::ThisDirectory(parent.to_path_buf())
1308 let aux_cx = TestCx {
1309 config: self.config,
1311 testpaths: &aux_testpaths,
1312 revision: self.revision
1314 let aux_args = aux_cx.make_compile_args(crate_type, &aux_testpaths.file, aux_output);
1315 let auxres = aux_cx.compose_and_run(aux_args,
1317 aux_cx.config.compile_lib_path.to_str().unwrap(),
1318 Some(aux_dir.to_str().unwrap()),
1320 if !auxres.status.success() {
1321 self.fatal_proc_rec(
1322 &format!("auxiliary build of {:?} failed to compile: ",
1323 aux_testpaths.file.display()),
1327 match &*self.config.target {
1328 "arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
1329 self._arm_push_aux_shared_library();
1335 self.compose_and_run(args,
1336 self.props.rustc_env.clone(),
1337 self.config.compile_lib_path.to_str().unwrap(),
1338 Some(aux_dir.to_str().unwrap()),
1342 // Like std::fs::create_dir_all, except handles concurrent calls among multiple
1343 // threads or processes.
1344 fn create_dir_racy(&self, path: &Path) {
1345 match fs::create_dir(path) {
1347 Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => return,
1348 Err(ref e) if e.kind() == io::ErrorKind::NotFound => {}
1349 Err(e) => panic!("failed to create dir {:?}: {}", path, e),
1351 self.create_dir_racy(path.parent().unwrap());
1352 match fs::create_dir(path) {
1354 Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => {}
1355 Err(e) => panic!("failed to create dir {:?}: {}", path, e),
1359 fn compose_and_run(&self,
1360 ProcArgs{ args, prog }: ProcArgs,
1361 procenv: Vec<(String, String)> ,
1363 aux_path: Option<&str>,
1364 input: Option<String>) -> ProcRes {
1365 return self.program_output(lib_path, prog, aux_path, args, procenv, input);
1368 fn make_compile_args(&self,
1369 extras: Vec<String> ,
1371 output_file: TargetLocation)
1374 let target = if self.props.force_host {
1377 &*self.config.target
1380 // FIXME (#9639): This needs to handle non-utf8 paths
1381 let mut args = vec![input_file.to_str().unwrap().to_owned(),
1383 self.config.build_base.to_str().unwrap().to_owned()];
1385 // Optionally prevent default --target if specified in test compile-flags.
1386 let custom_target = self.props.compile_flags
1388 .fold(false, |acc, ref x| acc || x.starts_with("--target"));
1392 format!("--target={}", target),
1396 if let Some(revision) = self.revision {
1399 format!("{}", revision),
1403 if let Some(ref incremental_dir) = self.props.incremental_dir {
1406 format!("incremental={}", incremental_dir.display()),
1411 match self.config.mode {
1416 // If we are extracting and matching errors in the new
1417 // fashion, then you want JSON mode. Old-skool error
1418 // patterns still match the raw compiler output.
1419 if self.props.error_patterns.is_empty() {
1420 args.extend(["--error-format",
1423 .map(|s| s.to_string()));
1433 .map(|s| s.to_string()));
1436 let mir_dump_dir = self.get_mir_dump_dir();
1437 self.create_dir_racy(mir_dump_dir.as_path());
1438 let mut dir_opt = "dump-mir-dir=".to_string();
1439 dir_opt.push_str(mir_dump_dir.to_str().unwrap());
1440 debug!("dir_opt: {:?}", dir_opt);
1454 // do not use JSON output
1458 args.extend_from_slice(&extras);
1459 if !self.props.no_prefer_dynamic {
1460 args.push("-C".to_owned());
1461 args.push("prefer-dynamic".to_owned());
1463 let path = match output_file {
1464 TargetLocation::ThisFile(path) => {
1465 args.push("-o".to_owned());
1468 TargetLocation::ThisDirectory(path) => {
1469 args.push("--out-dir".to_owned());
1473 args.push(path.to_str().unwrap().to_owned());
1474 if self.props.force_host {
1475 args.extend(self.split_maybe_args(&self.config.host_rustcflags));
1477 args.extend(self.split_maybe_args(&self.config.target_rustcflags));
1479 args.extend(self.props.compile_flags.iter().cloned());
1481 prog: self.config.rustc_path.to_str().unwrap().to_owned(),
1486 fn make_lib_name(&self, auxfile: &Path) -> PathBuf {
1487 // what we return here is not particularly important, as it
1488 // happens; rustc ignores everything except for the directory.
1489 let auxname = self.output_testname(auxfile);
1490 self.aux_output_dir_name().join(&auxname)
1493 fn make_exe_name(&self) -> PathBuf {
1494 let mut f = self.output_base_name();
1495 // FIXME: This is using the host architecture exe suffix, not target!
1496 if self.config.target.contains("emscripten") {
1497 let mut fname = f.file_name().unwrap().to_os_string();
1499 f.set_file_name(&fname);
1500 } else if !env::consts::EXE_SUFFIX.is_empty() {
1501 let mut fname = f.file_name().unwrap().to_os_string();
1502 fname.push(env::consts::EXE_SUFFIX);
1503 f.set_file_name(&fname);
1508 fn make_run_args(&self) -> ProcArgs {
1509 // If we've got another tool to run under (valgrind),
1510 // then split apart its command
1511 let mut args = self.split_maybe_args(&self.config.runtool);
1513 // If this is emscripten, then run tests under nodejs
1514 if self.config.target.contains("emscripten") {
1515 if let Some(ref p) = self.config.nodejs {
1516 args.push(p.clone());
1518 self.fatal("no NodeJS binary found (--nodejs)");
1522 let exe_file = self.make_exe_name();
1524 // FIXME (#9639): This needs to handle non-utf8 paths
1525 args.push(exe_file.to_str().unwrap().to_owned());
1527 // Add the arguments in the run_flags directive
1528 args.extend(self.split_maybe_args(&self.props.run_flags));
1530 let prog = args.remove(0);
1537 fn split_maybe_args(&self, argstr: &Option<String>) -> Vec<String> {
1543 if s.chars().all(|c| c.is_whitespace()) {
1554 fn program_output(&self,
1557 aux_path: Option<&str>,
1559 env: Vec<(String, String)>,
1560 input: Option<String>)
1564 let cmdline = self.make_cmdline(lib_path,
1567 logv(self.config, format!("executing {}", cmdline));
1570 let procsrv::Result {
1574 } = procsrv::run(lib_path,
1579 input).expect(&format!("failed to exec `{}`", prog));
1580 self.dump_output(&out, &err);
1582 status: Status::Normal(status),
1589 fn make_cmdline(&self, libpath: &str, prog: &str, args: &[String]) -> String {
1592 // Linux and mac don't require adjusting the library search path
1594 format!("{} {}", prog, args.join(" "))
1596 // Build the LD_LIBRARY_PATH variable as it would be seen on the command line
1597 // for diagnostic purposes
1598 fn lib_path_cmd_prefix(path: &str) -> String {
1599 format!("{}=\"{}\"", util::lib_path_env_var(), util::make_new_path(path))
1602 format!("{} {} {}", lib_path_cmd_prefix(libpath), prog, args.join(" "))
1606 fn dump_output(&self, out: &str, err: &str) {
1607 self.dump_output_file(out, "out");
1608 self.dump_output_file(err, "err");
1609 self.maybe_dump_to_stdout(out, err);
1612 fn dump_output_file(&self,
1615 let outfile = self.make_out_name(extension);
1616 File::create(&outfile).unwrap().write_all(out.as_bytes()).unwrap();
1619 fn make_out_name(&self, extension: &str) -> PathBuf {
1620 self.output_base_name().with_extension(extension)
1623 fn aux_output_dir_name(&self) -> PathBuf {
1624 let f = self.output_base_name();
1625 let mut fname = f.file_name().unwrap().to_os_string();
1626 fname.push(&format!(".{}.libaux", self.config.mode));
1627 f.with_file_name(&fname)
1630 fn output_testname(&self, filepath: &Path) -> PathBuf {
1631 PathBuf::from(filepath.file_stem().unwrap())
1634 /// Given a test path like `compile-fail/foo/bar.rs` Returns a name like
1636 /// <output>/foo/bar-stage1
1637 fn output_base_name(&self) -> PathBuf {
1638 let dir = self.config.build_base.join(&self.testpaths.relative_dir);
1640 // Note: The directory `dir` is created during `collect_tests_from_dir`
1642 .join(&self.output_testname(&self.testpaths.file))
1643 .with_extension(&self.config.stage_id)
1646 fn maybe_dump_to_stdout(&self, out: &str, err: &str) {
1647 if self.config.verbose {
1648 println!("------{}------------------------------", "stdout");
1649 println!("{}", out);
1650 println!("------{}------------------------------", "stderr");
1651 println!("{}", err);
1652 println!("------------------------------------------");
1656 fn error(&self, err: &str) {
1657 match self.revision {
1658 Some(rev) => println!("\nerror in revision `{}`: {}", rev, err),
1659 None => println!("\nerror: {}", err)
1663 fn fatal(&self, err: &str) -> ! {
1664 self.error(err); panic!();
1667 fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
1668 self.try_print_open_handles();
1670 proc_res.fatal(None);
1673 // This function is a poor man's attempt to debug rust-lang/rust#38620, if
1674 // that's closed then this should be deleted
1676 // This is a very "opportunistic" debugging attempt, so we ignore all
1678 fn try_print_open_handles(&self) {
1682 if self.config.mode != Incremental {
1686 let filename = match self.testpaths.file.file_stem() {
1691 let mut cmd = Command::new("handle.exe");
1692 cmd.arg("-a").arg("-u");
1694 cmd.arg("-nobanner");
1695 let output = match cmd.output() {
1696 Ok(output) => output,
1699 println!("---------------------------------------------------");
1700 println!("ran extra command to debug rust-lang/rust#38620: ");
1701 println!("{:?}", cmd);
1702 println!("result: {}", output.status);
1703 println!("--- stdout ----------------------------------------");
1704 println!("{}", String::from_utf8_lossy(&output.stdout));
1705 println!("--- stderr ----------------------------------------");
1706 println!("{}", String::from_utf8_lossy(&output.stderr));
1707 println!("---------------------------------------------------");
1710 fn _arm_exec_compiled_test(&self, env: Vec<(String, String)>) -> ProcRes {
1711 let args = self.make_run_args();
1712 let cmdline = self.make_cmdline("", &args.prog, &args.args);
1714 // get bare program string
1715 let mut tvec: Vec<String> = args.prog
1719 let prog_short = tvec.pop().unwrap();
1722 let copy_result = procsrv::run("",
1723 &self.config.adb_path,
1728 self.config.adb_test_dir.clone()
1730 vec![("".to_owned(), "".to_owned())],
1731 Some("".to_owned()))
1732 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1734 if self.config.verbose {
1735 println!("push ({}) {} {} {}",
1742 logv(self.config, format!("executing ({}) {}", self.config.target, cmdline));
1744 let mut runargs = Vec::new();
1746 // run test via adb_run_wrapper
1747 runargs.push("shell".to_owned());
1748 for (key, val) in env {
1749 runargs.push(format!("{}={}", key, val));
1751 runargs.push(format!("{}/../adb_run_wrapper.sh", self.config.adb_test_dir));
1752 runargs.push(format!("{}", self.config.adb_test_dir));
1753 runargs.push(format!("{}", prog_short));
1755 for tv in &args.args {
1756 runargs.push(tv.to_owned());
1759 &self.config.adb_path,
1762 vec![("".to_owned(), "".to_owned())], Some("".to_owned()))
1763 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1765 // get exitcode of result
1766 runargs = Vec::new();
1767 runargs.push("shell".to_owned());
1768 runargs.push("cat".to_owned());
1769 runargs.push(format!("{}/{}.exitcode", self.config.adb_test_dir, prog_short));
1771 let procsrv::Result{ out: exitcode_out, err: _, status: _ } =
1773 &self.config.adb_path,
1776 vec![("".to_owned(), "".to_owned())],
1777 Some("".to_owned()))
1778 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1780 let mut exitcode: i32 = 0;
1781 for c in exitcode_out.chars() {
1782 if !c.is_numeric() { break; }
1783 exitcode = exitcode * 10 + match c {
1784 '0' ... '9' => c as i32 - ('0' as i32),
1789 // get stdout of result
1790 runargs = Vec::new();
1791 runargs.push("shell".to_owned());
1792 runargs.push("cat".to_owned());
1793 runargs.push(format!("{}/{}.stdout", self.config.adb_test_dir, prog_short));
1795 let procsrv::Result{ out: stdout_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 // get stderr of result
1805 runargs = Vec::new();
1806 runargs.push("shell".to_owned());
1807 runargs.push("cat".to_owned());
1808 runargs.push(format!("{}/{}.stderr", self.config.adb_test_dir, prog_short));
1810 let procsrv::Result{ out: stderr_out, err: _, status: _ } =
1812 &self.config.adb_path,
1815 vec![("".to_owned(), "".to_owned())],
1816 Some("".to_owned()))
1817 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1819 self.dump_output(&stdout_out, &stderr_out);
1822 status: Status::Parsed(exitcode),
1829 fn _arm_push_aux_shared_library(&self) {
1830 let tdir = self.aux_output_dir_name();
1832 let dirs = fs::read_dir(&tdir).unwrap();
1834 let file = file.unwrap().path();
1835 if file.extension().and_then(|s| s.to_str()) == Some("so") {
1836 // FIXME (#9639): This needs to handle non-utf8 paths
1837 let copy_result = procsrv::run("",
1838 &self.config.adb_path,
1845 self.config.adb_test_dir.to_owned(),
1847 vec![("".to_owned(),
1849 Some("".to_owned()))
1850 .expect(&format!("failed to exec `{}`", self.config.adb_path));
1852 if self.config.verbose {
1853 println!("push ({}) {:?} {} {}",
1854 self.config.target, file.display(),
1855 copy_result.out, copy_result.err);
1861 // codegen tests (using FileCheck)
1863 fn compile_test_and_save_ir(&self) -> ProcRes {
1864 let aux_dir = self.aux_output_dir_name();
1865 // FIXME (#9639): This needs to handle non-utf8 paths
1866 let mut link_args = vec!["-L".to_owned(),
1867 aux_dir.to_str().unwrap().to_owned()];
1868 let llvm_args = vec!["--emit=llvm-ir".to_owned(),];
1869 link_args.extend(llvm_args);
1870 let args = self.make_compile_args(link_args,
1871 &self.testpaths.file,
1872 TargetLocation::ThisDirectory(
1873 self.output_base_name().parent()
1876 self.compose_and_run_compiler(args, None)
1879 fn check_ir_with_filecheck(&self) -> ProcRes {
1880 let irfile = self.output_base_name().with_extension("ll");
1881 let prog = self.config.llvm_filecheck.as_ref().unwrap();
1882 let proc_args = ProcArgs {
1883 // FIXME (#9639): This needs to handle non-utf8 paths
1884 prog: prog.to_str().unwrap().to_owned(),
1885 args: vec![format!("-input-file={}", irfile.to_str().unwrap()),
1886 self.testpaths.file.to_str().unwrap().to_owned()]
1888 self.compose_and_run(proc_args, Vec::new(), "", None, None)
1891 fn run_codegen_test(&self) {
1892 assert!(self.revision.is_none(), "revisions not relevant here");
1894 if self.config.llvm_filecheck.is_none() {
1895 self.fatal("missing --llvm-filecheck");
1898 let mut proc_res = self.compile_test_and_save_ir();
1899 if !proc_res.status.success() {
1900 self.fatal_proc_rec("compilation failed!", &proc_res);
1903 proc_res = self.check_ir_with_filecheck();
1904 if !proc_res.status.success() {
1905 self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
1909 fn charset() -> &'static str {
1910 // FreeBSD 10.1 defaults to GDB 6.1.1 which doesn't support "auto" charset
1911 if cfg!(target_os = "bitrig") {
1913 } else if cfg!(target_os = "freebsd") {
1920 fn run_rustdoc_test(&self) {
1921 assert!(self.revision.is_none(), "revisions not relevant here");
1923 let out_dir = self.output_base_name();
1924 let _ = fs::remove_dir_all(&out_dir);
1925 self.create_dir_racy(&out_dir);
1927 let proc_res = self.document(&out_dir);
1928 if !proc_res.status.success() {
1929 self.fatal_proc_rec("rustdoc failed!", &proc_res);
1932 if self.props.check_test_line_numbers_match == true {
1933 self.check_rustdoc_test_option(proc_res);
1935 let root = self.find_rust_src_root().unwrap();
1936 let res = self.cmd2procres(Command::new(&self.config.docck_python)
1937 .arg(root.join("src/etc/htmldocck.py"))
1939 .arg(&self.testpaths.file));
1940 if !res.status.success() {
1941 self.fatal_proc_rec("htmldocck failed!", &res);
1946 fn get_lines<P: AsRef<Path>>(&self, path: &P,
1947 mut other_files: Option<&mut Vec<String>>) -> Vec<usize> {
1948 let mut file = fs::File::open(path)
1949 .expect("markdown_test_output_check_entry File::open failed");
1950 let mut content = String::new();
1951 file.read_to_string(&mut content)
1952 .expect("markdown_test_output_check_entry read_to_string failed");
1953 let mut ignore = false;
1956 .filter_map(|(line_nb, line)| {
1957 if (line.trim_left().starts_with("pub mod ") ||
1958 line.trim_left().starts_with("mod ")) &&
1959 line.ends_with(";") {
1960 if let Some(ref mut other_files) = other_files {
1961 other_files.push(line.rsplit("mod ")
1968 let sline = line.split("///").last().unwrap_or("");
1969 let line = sline.trim_left();
1970 if line.starts_with("```") {
1986 fn check_rustdoc_test_option(&self, res: ProcRes) {
1987 let mut other_files = Vec::new();
1988 let mut files: HashMap<String, Vec<usize>> = HashMap::new();
1989 files.insert(self.testpaths.file.to_str().unwrap().to_owned(),
1990 self.get_lines(&self.testpaths.file, Some(&mut other_files)));
1991 for other_file in other_files {
1992 let mut path = self.testpaths.file.clone();
1993 path.set_file_name(&format!("{}.rs", other_file));
1994 files.insert(path.to_str().unwrap().to_owned(), self.get_lines(&path, None));
1998 for _ in res.stdout.split("\n")
1999 .filter(|s| s.starts_with("test "))
2001 let tmp: Vec<&str> = s.split(" - ").collect();
2003 let path = tmp[0].rsplit("test ").next().unwrap();
2004 if let Some(ref mut v) = files.get_mut(path) {
2006 let mut iter = tmp[1].split("(line ");
2008 let line = iter.next()
2015 if let Ok(pos) = v.binary_search(&line) {
2018 self.fatal_proc_rec(
2019 &format!("Not found doc test: \"{}\" in \"{}\":{:?}",
2027 self.fatal_proc_rec(&format!("No test has been found... {:?}", files), &res);
2029 for (entry, v) in &files {
2031 self.fatal_proc_rec(&format!("Not found test at line{} \"{}\":{:?}",
2032 if v.len() > 1 { "s" } else { "" }, entry, v),
2039 fn run_codegen_units_test(&self) {
2040 assert!(self.revision.is_none(), "revisions not relevant here");
2042 let proc_res = self.compile_test();
2044 if !proc_res.status.success() {
2045 self.fatal_proc_rec("compilation failed!", &proc_res);
2048 self.check_no_compiler_crash(&proc_res);
2050 const PREFIX: &'static str = "TRANS_ITEM ";
2051 const CGU_MARKER: &'static str = "@@";
2053 let actual: Vec<TransItem> = proc_res
2056 .filter(|line| line.starts_with(PREFIX))
2057 .map(str_to_trans_item)
2060 let expected: Vec<TransItem> = errors::load_errors(&self.testpaths.file, None)
2062 .map(|e| str_to_trans_item(&e.msg[..]))
2065 let mut missing = Vec::new();
2066 let mut wrong_cgus = Vec::new();
2068 for expected_item in &expected {
2069 let actual_item_with_same_name = actual.iter()
2070 .find(|ti| ti.name == expected_item.name);
2072 if let Some(actual_item) = actual_item_with_same_name {
2073 if !expected_item.codegen_units.is_empty() {
2074 // Also check for codegen units
2075 if expected_item.codegen_units != actual_item.codegen_units {
2076 wrong_cgus.push((expected_item.clone(), actual_item.clone()));
2080 missing.push(expected_item.string.clone());
2084 let unexpected: Vec<_> =
2086 .filter(|acgu| !expected.iter().any(|ecgu| acgu.name == ecgu.name))
2087 .map(|acgu| acgu.string.clone())
2090 if !missing.is_empty() {
2093 println!("\nThese items should have been contained but were not:\n");
2095 for item in &missing {
2096 println!("{}", item);
2102 if !unexpected.is_empty() {
2104 let mut sorted = unexpected.clone();
2109 println!("\nThese items were contained but should not have been:\n");
2111 for item in sorted {
2112 println!("{}", item);
2118 if !wrong_cgus.is_empty() {
2119 wrong_cgus.sort_by_key(|pair| pair.0.name.clone());
2120 println!("\nThe following items were assigned to wrong codegen units:\n");
2122 for &(ref expected_item, ref actual_item) in &wrong_cgus {
2123 println!("{}", expected_item.name);
2124 println!(" expected: {}", codegen_units_to_str(&expected_item.codegen_units));
2125 println!(" actual: {}", codegen_units_to_str(&actual_item.codegen_units));
2130 if !(missing.is_empty() && unexpected.is_empty() && wrong_cgus.is_empty())
2135 #[derive(Clone, Eq, PartialEq)]
2138 codegen_units: HashSet<String>,
2142 // [TRANS_ITEM] name [@@ (cgu)+]
2143 fn str_to_trans_item(s: &str) -> TransItem {
2144 let s = if s.starts_with(PREFIX) {
2145 (&s[PREFIX.len()..]).trim()
2150 let full_string = format!("{}{}", PREFIX, s.trim().to_owned());
2152 let parts: Vec<&str> = s.split(CGU_MARKER)
2154 .filter(|s| !s.is_empty())
2157 let name = parts[0].trim();
2159 let cgus = if parts.len() > 1 {
2160 let cgus_str = parts[1];
2164 .filter(|s| !s.is_empty())
2173 name: name.to_owned(),
2174 codegen_units: cgus,
2175 string: full_string,
2179 fn codegen_units_to_str(cgus: &HashSet<String>) -> String
2181 let mut cgus: Vec<_> = cgus.iter().collect();
2184 let mut string = String::new();
2186 string.push_str(&cgu[..]);
2187 string.push_str(" ");
2194 fn init_incremental_test(&self) {
2195 // (See `run_incremental_test` for an overview of how incremental tests work.)
2197 // Before any of the revisions have executed, create the
2198 // incremental workproduct directory. Delete any old
2199 // incremental work products that may be there from prior
2201 let incremental_dir = self.incremental_dir();
2202 if incremental_dir.exists() {
2203 // Canonicalizing the path will convert it to the //?/ format
2204 // on Windows, which enables paths longer than 260 character
2205 let canonicalized = incremental_dir.canonicalize().unwrap();
2206 fs::remove_dir_all(canonicalized).unwrap();
2208 fs::create_dir_all(&incremental_dir).unwrap();
2210 if self.config.verbose {
2211 print!("init_incremental_test: incremental_dir={}", incremental_dir.display());
2215 fn run_incremental_test(&self) {
2216 // Basic plan for a test incremental/foo/bar.rs:
2217 // - load list of revisions rpass1, cfail2, rpass3
2218 // - each should begin with `rpass`, `cfail`, or `cfail`
2219 // - if `rpass`, expect compile and execution to succeed
2220 // - if `cfail`, expect compilation to fail
2221 // - if `rfail`, expect execution to fail
2222 // - create a directory build/foo/bar.incremental
2223 // - compile foo/bar.rs with -Z incremental=.../foo/bar.incremental and -C rpass1
2224 // - because name of revision starts with "rpass", expect success
2225 // - compile foo/bar.rs with -Z incremental=.../foo/bar.incremental and -C cfail2
2226 // - because name of revision starts with "cfail", expect an error
2227 // - load expected errors as usual, but filter for those that end in `[rfail2]`
2228 // - compile foo/bar.rs with -Z incremental=.../foo/bar.incremental and -C rpass3
2229 // - because name of revision starts with "rpass", expect success
2230 // - execute build/foo/bar.exe and save output
2232 // FIXME -- use non-incremental mode as an oracle? That doesn't apply
2233 // to #[rustc_dirty] and clean tests I guess
2235 let revision = self.revision.expect("incremental tests require a list of revisions");
2237 // Incremental workproduct directory should have already been created.
2238 let incremental_dir = self.incremental_dir();
2239 assert!(incremental_dir.exists(), "init_incremental_test failed to create incremental dir");
2241 // Add an extra flag pointing at the incremental directory.
2242 let mut revision_props = self.props.clone();
2243 revision_props.incremental_dir = Some(incremental_dir);
2244 revision_props.compile_flags.push(String::from("-Zincremental-info"));
2246 let revision_cx = TestCx {
2247 config: self.config,
2248 props: &revision_props,
2249 testpaths: self.testpaths,
2250 revision: self.revision,
2253 if self.config.verbose {
2254 print!("revision={:?} revision_props={:#?}", revision, revision_props);
2257 if revision.starts_with("rpass") {
2258 revision_cx.run_rpass_test();
2259 } else if revision.starts_with("rfail") {
2260 revision_cx.run_rfail_test();
2261 } else if revision.starts_with("cfail") {
2262 revision_cx.run_cfail_test();
2265 "revision name must begin with rpass, rfail, or cfail");
2269 /// Directory where incremental work products are stored.
2270 fn incremental_dir(&self) -> PathBuf {
2271 self.output_base_name().with_extension("inc")
2274 fn run_rmake_test(&self) {
2275 // FIXME(#11094): we should fix these tests
2276 if self.config.host != self.config.target {
2280 let cwd = env::current_dir().unwrap();
2281 let src_root = self.config.src_base.parent().unwrap()
2284 let src_root = cwd.join(&src_root);
2286 let tmpdir = cwd.join(self.output_base_name());
2287 if tmpdir.exists() {
2288 self.aggressive_rm_rf(&tmpdir).unwrap();
2290 self.create_dir_racy(&tmpdir);
2292 let host = &self.config.host;
2293 let make = if host.contains("bitrig") || host.contains("dragonfly") ||
2294 host.contains("freebsd") || host.contains("netbsd") ||
2295 host.contains("openbsd") {
2301 let mut cmd = Command::new(make);
2302 cmd.current_dir(&self.testpaths.file)
2303 .env("TARGET", &self.config.target)
2304 .env("PYTHON", &self.config.docck_python)
2306 .env("RUST_BUILD_STAGE", &self.config.stage_id)
2307 .env("RUSTC", cwd.join(&self.config.rustc_path))
2308 .env("RUSTDOC", cwd.join(&self.config.rustdoc_path))
2309 .env("TMPDIR", &tmpdir)
2310 .env("LD_LIB_PATH_ENVVAR", procsrv::dylib_env_var())
2311 .env("HOST_RPATH_DIR", cwd.join(&self.config.compile_lib_path))
2312 .env("TARGET_RPATH_DIR", cwd.join(&self.config.run_lib_path))
2313 .env("LLVM_COMPONENTS", &self.config.llvm_components)
2314 .env("LLVM_CXXFLAGS", &self.config.llvm_cxxflags);
2316 // We don't want RUSTFLAGS set from the outside to interfere with
2317 // compiler flags set in the test cases:
2318 cmd.env_remove("RUSTFLAGS");
2320 if self.config.target.contains("msvc") {
2321 // We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
2322 // and that `lib.exe` lives next to it.
2323 let lib = Path::new(&self.config.cc).parent().unwrap().join("lib.exe");
2325 // MSYS doesn't like passing flags of the form `/foo` as it thinks it's
2326 // a path and instead passes `C:\msys64\foo`, so convert all
2327 // `/`-arguments to MSVC here to `-` arguments.
2328 let cflags = self.config.cflags.split(' ').map(|s| s.replace("/", "-"))
2329 .collect::<Vec<_>>().join(" ");
2331 cmd.env("IS_MSVC", "1")
2332 .env("IS_WINDOWS", "1")
2333 .env("MSVC_LIB", format!("'{}' -nologo", lib.display()))
2334 .env("CC", format!("'{}' {}", self.config.cc, cflags))
2335 .env("CXX", &self.config.cxx);
2337 cmd.env("CC", format!("{} {}", self.config.cc, self.config.cflags))
2338 .env("CXX", format!("{} {}", self.config.cxx, self.config.cflags));
2340 if self.config.target.contains("windows") {
2341 cmd.env("IS_WINDOWS", "1");
2345 let output = cmd.output().expect("failed to spawn `make`");
2346 if !output.status.success() {
2348 status: Status::Normal(output.status),
2349 stdout: String::from_utf8_lossy(&output.stdout).into_owned(),
2350 stderr: String::from_utf8_lossy(&output.stderr).into_owned(),
2351 cmdline: format!("{:?}", cmd),
2353 self.fatal_proc_rec("make failed", &res);
2357 fn aggressive_rm_rf(&self, path: &Path) -> io::Result<()> {
2358 for e in path.read_dir()? {
2360 let path = entry.path();
2361 if entry.file_type()?.is_dir() {
2362 self.aggressive_rm_rf(&path)?;
2364 // Remove readonly files as well on windows (by default we can't)
2365 fs::remove_file(&path).or_else(|e| {
2366 if cfg!(windows) && e.kind() == io::ErrorKind::PermissionDenied {
2367 let mut meta = entry.metadata()?.permissions();
2368 meta.set_readonly(false);
2369 fs::set_permissions(&path, meta)?;
2370 fs::remove_file(&path)
2377 fs::remove_dir(path)
2380 fn run_ui_test(&self) {
2381 println!("ui: {}", self.testpaths.file.display());
2383 let proc_res = self.compile_test();
2385 let expected_stderr_path = self.expected_output_path("stderr");
2386 let expected_stderr = self.load_expected_output(&expected_stderr_path);
2388 let expected_stdout_path = self.expected_output_path("stdout");
2389 let expected_stdout = self.load_expected_output(&expected_stdout_path);
2391 let normalized_stdout = self.normalize_output(&proc_res.stdout);
2392 let normalized_stderr = self.normalize_output(&proc_res.stderr);
2395 errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout);
2396 errors += self.compare_output("stderr", &normalized_stderr, &expected_stderr);
2399 println!("To update references, run this command from build directory:");
2400 let relative_path_to_file =
2401 self.testpaths.relative_dir
2402 .join(self.testpaths.file.file_name().unwrap());
2403 println!("{}/update-references.sh '{}' '{}'",
2404 self.config.src_base.display(),
2405 self.config.build_base.display(),
2406 relative_path_to_file.display());
2407 self.fatal_proc_rec(&format!("{} errors occurred comparing output.", errors),
2412 fn run_mir_opt_test(&self) {
2413 let proc_res = self.compile_test();
2415 if !proc_res.status.success() {
2416 self.fatal_proc_rec("compilation failed!", &proc_res);
2419 let proc_res = self.exec_compiled_test();
2421 if !proc_res.status.success() {
2422 self.fatal_proc_rec("test run failed!", &proc_res);
2424 self.check_mir_dump();
2427 fn check_mir_dump(&self) {
2428 let mut test_file_contents = String::new();
2429 fs::File::open(self.testpaths.file.clone()).unwrap()
2430 .read_to_string(&mut test_file_contents)
2432 if let Some(idx) = test_file_contents.find("// END RUST SOURCE") {
2433 let (_, tests_text) = test_file_contents.split_at(idx + "// END_RUST SOURCE".len());
2434 let tests_text_str = String::from(tests_text);
2435 let mut curr_test : Option<&str> = None;
2436 let mut curr_test_contents = Vec::new();
2437 for l in tests_text_str.lines() {
2438 debug!("line: {:?}", l);
2439 if l.starts_with("// START ") {
2440 let (_, t) = l.split_at("// START ".len());
2441 curr_test = Some(t);
2442 } else if l.starts_with("// END") {
2443 let (_, t) = l.split_at("// END ".len());
2444 if Some(t) != curr_test {
2445 panic!("mismatched START END test name");
2447 self.compare_mir_test_output(curr_test.unwrap(), &curr_test_contents);
2449 curr_test_contents.clear();
2450 } else if l.is_empty() {
2452 } else if l.starts_with("// ") {
2453 let (_, test_content) = l.split_at("// ".len());
2454 curr_test_contents.push(test_content);
2460 fn compare_mir_test_output(&self, test_name: &str, expected_content: &Vec<&str>) {
2461 let mut output_file = PathBuf::new();
2462 output_file.push(self.get_mir_dump_dir());
2463 output_file.push(test_name);
2464 debug!("comparing the contests of: {:?}", output_file);
2465 debug!("with: {:?}", expected_content);
2467 let mut dumped_file = fs::File::open(output_file.clone()).unwrap();
2468 let mut dumped_string = String::new();
2469 dumped_file.read_to_string(&mut dumped_string).unwrap();
2470 let mut dumped_lines = dumped_string.lines().filter(|l| !l.is_empty());
2471 let mut expected_lines = expected_content.iter().filter(|l| !l.is_empty());
2473 // We expect each non-empty line from expected_content to appear
2474 // in the dump in order, but there may be extra lines interleaved
2475 while let Some(expected_line) = expected_lines.next() {
2476 let e_norm = normalize_mir_line(expected_line);
2477 if e_norm.is_empty() {
2480 let mut found = false;
2481 while let Some(dumped_line) = dumped_lines.next() {
2482 let d_norm = normalize_mir_line(dumped_line);
2483 debug!("found: {:?}", d_norm);
2484 debug!("expected: {:?}", e_norm);
2485 if e_norm == d_norm {
2491 let normalize_all = dumped_string.lines()
2492 .map(nocomment_mir_line)
2493 .filter(|l| !l.is_empty())
2494 .collect::<Vec<_>>()
2496 panic!("ran out of mir dump output to match against.\n\
2497 Did not find expected line: {:?}\n\
2501 expected_content.join("\n"),
2507 fn get_mir_dump_dir(&self) -> PathBuf {
2508 let mut mir_dump_dir = PathBuf::from(self.config.build_base
2512 debug!("input_file: {:?}", self.testpaths.file);
2513 mir_dump_dir.push(self.testpaths.file.file_stem().unwrap().to_str().unwrap());
2517 fn normalize_output(&self, output: &str) -> String {
2518 let parent_dir = self.testpaths.file.parent().unwrap();
2519 let parent_dir_str = parent_dir.display().to_string();
2520 output.replace(&parent_dir_str, "$DIR")
2521 .replace("\\", "/") // normalize for paths on windows
2522 .replace("\r\n", "\n") // normalize for linebreaks on windows
2523 .replace("\t", "\\t") // makes tabs visible
2526 fn expected_output_path(&self, kind: &str) -> PathBuf {
2527 let extension = match self.revision {
2528 Some(r) => format!("{}.{}", r, kind),
2529 None => kind.to_string(),
2531 self.testpaths.file.with_extension(extension)
2534 fn load_expected_output(&self, path: &Path) -> String {
2536 return String::new();
2539 let mut result = String::new();
2540 match File::open(path).and_then(|mut f| f.read_to_string(&mut result)) {
2543 self.fatal(&format!("failed to load expected output from `{}`: {}",
2549 fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize {
2550 if actual == expected {
2554 println!("normalized {}:\n{}\n", kind, actual);
2555 println!("expected {}:\n{}\n", kind, expected);
2556 println!("diff of {}:\n", kind);
2557 for line in uidiff::diff_lines(actual, expected) {
2558 println!("{}", line);
2561 let output_file = self.output_base_name().with_extension(kind);
2562 match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) {
2565 self.fatal(&format!("failed to write {} to `{}`: {}",
2566 kind, output_file.display(), e))
2570 println!("\nThe actual {0} differed from the expected {0}.", kind);
2571 println!("Actual {} saved to {}", kind, output_file.display());
2581 pub struct ProcRes {
2594 pub fn fatal(&self, err: Option<&str>) -> ! {
2595 if let Some(e) = err {
2596 println!("\nerror: {}", e);
2602 ------------------------------------------\n\
2604 ------------------------------------------\n\
2606 ------------------------------------------\n\
2608 ------------------------------------------\n\
2610 self.status, self.cmdline, self.stdout,
2617 fn code(&self) -> Option<i32> {
2619 Status::Parsed(i) => Some(i),
2620 Status::Normal(ref e) => e.code(),
2624 fn success(&self) -> bool {
2626 Status::Parsed(i) => i == 0,
2627 Status::Normal(ref e) => e.success(),
2632 impl fmt::Display for Status {
2633 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2635 Status::Parsed(i) => write!(f, "exit code: {}", i),
2636 Status::Normal(ref e) => e.fmt(f),
2641 enum TargetLocation {
2643 ThisDirectory(PathBuf),
2646 fn normalize_mir_line(line: &str) -> String {
2647 nocomment_mir_line(line).replace(char::is_whitespace, "")
2650 fn nocomment_mir_line(line: &str) -> &str {
2651 if let Some(idx) = line.find("//") {
2652 let (l, _) = line.split_at(idx);