diff --git a/tests/reftest.rs b/tests/reftest.rs index 4dfe41530cf..23de22a0a57 100644 --- a/tests/reftest.rs +++ b/tests/reftest.rs @@ -7,25 +7,24 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(collections, core, env, io, hash, os, path, std_misc, test)] +#![feature(collections, core, exit_status, fs_walk, io, old_io, path, path_ext, std_misc, test)] #[macro_use] extern crate bitflags; extern crate png; extern crate test; extern crate url; -use std::ascii::AsciiExt; use std::env; -use std::old_io as io; -use std::old_io::{File, Reader, Command, IoResult}; -use std::old_io::process::ExitStatus; -use std::old_io::fs::PathExtensions; -use std::old_path::Path; +use std::ffi::OsStr; +use std::fs::{PathExt, File, walk_dir}; +use std::io::Read; +use std::old_io::{Reader, IoResult}; +use std::path::{Path, PathBuf}; +use std::process::{Command, Stdio}; use std::thunk::Thunk; use test::{AutoColor, DynTestName, DynTestFn, TestDesc, TestOpts, TestDescAndFn, ShouldPanic}; use test::run_tests_console; use url::Url; - bitflags!( flags RenderMode: u32 { const CPU_RENDERING = 0x00000001, @@ -68,11 +67,12 @@ fn main() { let mut all_tests = vec!(); println!("Scanning {} for manifests\n", base_path); - for file in io::fs::walk_dir(&Path::new(base_path)).unwrap() { - let maybe_extension = file.extension_str(); + for file in walk_dir(base_path).unwrap() { + let file = file.unwrap().path(); + let maybe_extension = file.extension(); match maybe_extension { Some(extension) => { - if extension.to_ascii_lowercase().as_slice() == "list" && file.is_file() { + if extension == OsStr::from_str("list") && file.is_file() { let mut tests = parse_lists(&file, servo_args, render_mode, all_tests.len()); println!("\t{} [{} tests]", file.display(), tests.len()); all_tests.append(&mut tests); @@ -106,12 +106,11 @@ fn run(test_opts: TestOpts, all_tests: Vec, // Verify that we're passing in valid servo arguments. Otherwise, servo // will exit before we've run any tests, and it will appear to us as if // all the tests are failing. - let mut command = match Command::new(servo_path()) - .args(servo_args.as_slice()).spawn() { + let output = match Command::new(&servo_path()).args(&servo_args).output() { Ok(p) => p, Err(e) => panic!("failed to execute process: {}", e), }; - let stderr = command.stderr.as_mut().unwrap().read_to_string().unwrap(); + let stderr = String::from_utf8(output.stderr).unwrap(); if stderr.as_slice().contains("Unrecognized") { println!("Servo: {}", stderr.as_slice()); @@ -130,7 +129,7 @@ enum ReftestKind { struct Reftest { name: String, kind: ReftestKind, - files: [Path; 2], + files: [PathBuf; 2], id: usize, servo_args: Vec, render_mode: RenderMode, @@ -149,9 +148,12 @@ struct TestLine<'a> { fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_offset: usize) -> Vec { let mut tests = Vec::new(); - let contents = File::open_mode(file, io::Open, io::Read) - .and_then(|mut f| f.read_to_string()) - .ok().expect("Could not read file"); + let contents = { + let mut f = File::open(file).unwrap(); + let mut contents = String::new(); + f.read_to_string(&mut contents).unwrap(); + contents + }; for line in contents.as_slice().lines() { // ignore comments or empty lines @@ -183,7 +185,7 @@ fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_o part => panic!("reftest line: '{}' has invalid kind '{}'", line, part) }; - let base = Path::new(env::current_dir().unwrap().to_str().unwrap()).join(file.dir_path()); + let base = env::current_dir().unwrap().join(file.parent().unwrap()); let file_left = base.join(test_line.file_left); let file_right = base.join(test_line.file_right); @@ -244,16 +246,18 @@ fn make_test(reftest: Reftest) -> TestDescAndFn { fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec) { let png_filename = format!("/tmp/servo-reftest-{:06}-{}.png", reftest.id, side); - let mut command = Command::new(servo_path()); + let mut command = Command::new(&servo_path()); command + .stdout(Stdio::null()) + .stderr(Stdio::null()) .args(&reftest.servo_args[..]) // Allows pixel perfect rendering of Ahem font for reftests. .arg("-Z") .arg("disable-text-aa") .args(["-f", "-o"].as_slice()) .arg(png_filename.as_slice()) - .arg({ - let mut url = Url::from_file_path(&reftest.files[side]).unwrap(); + .arg(&{ + let mut url = Url::from_file_path(&*reftest.files[side]).unwrap(); url.fragment = reftest.fragment_identifier.clone(); url.to_string() }); @@ -275,7 +279,7 @@ fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec) { Ok(status) => status, Err(e) => panic!("failed to execute process: {}", e), }; - assert_eq!(retval, ExitStatus(0)); + assert!(retval.success()); let image = png::load_png(&png_filename).unwrap(); let rgba8_bytes = match image.pixels { @@ -285,9 +289,9 @@ fn capture(reftest: &Reftest, side: usize) -> (u32, u32, Vec) { (image.width, image.height, rgba8_bytes) } -fn servo_path() -> Path { +fn servo_path() -> PathBuf { let current_exe = env::current_exe().ok().expect("Could not locate current executable"); - Path::new(current_exe.to_str().unwrap()).dir_path().join("servo") + current_exe.parent().unwrap().join("servo") } fn check_reftest(reftest: Reftest) {