1 #[macro_use] 2 extern crate log; 3 extern crate env_logger; 4 5 use std::env; 6 use std::fmt; 7 use std::process; 8 use std::str; 9 10 struct Foo; 11 12 impl fmt::Display for Foo { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result13 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 14 info!("test"); 15 f.write_str("bar") 16 } 17 } 18 main()19fn main() { 20 env_logger::init(); 21 if env::var("YOU_ARE_TESTING_NOW").is_ok() { 22 return info!("{}", Foo); 23 } 24 25 let exe = env::current_exe().unwrap(); 26 let out = process::Command::new(exe) 27 .env("YOU_ARE_TESTING_NOW", "1") 28 .env("RUST_LOG", "debug") 29 .output() 30 .unwrap_or_else(|e| panic!("Unable to start child process: {}", e)); 31 if out.status.success() { 32 return; 33 } 34 35 println!("test failed: {}", out.status); 36 println!("--- stdout\n{}", str::from_utf8(&out.stdout).unwrap()); 37 println!("--- stderr\n{}", str::from_utf8(&out.stderr).unwrap()); 38 process::exit(1); 39 } 40