Merge pull request #3365 from SimonSapin/command-line-argument-filenames

Try to parse command line argument as file names
This commit is contained in:
Simon Sapin 2014-09-16 20:32:40 +01:00
commit 14f7d2dabd
6 changed files with 50 additions and 32 deletions

1
Cargo.lock generated
View file

@ -8,6 +8,7 @@ dependencies = [
"msg 0.0.1", "msg 0.0.1",
"net 0.0.1", "net 0.0.1",
"script 0.0.1", "script 0.0.1",
"url 0.1.0 (git+https://github.com/servo/rust-url#678bb4d52638b1cfdab78ef8e521566c9240fb1a)",
"util 0.0.1", "util 0.0.1",
] ]

View file

@ -45,3 +45,6 @@ path = "components/layout"
[dependencies.gfx] [dependencies.gfx]
path = "components/gfx" path = "components/gfx"
[dependencies.url]
git = "https://github.com/servo/rust-url"

View file

@ -57,8 +57,6 @@ use std::os;
use std::task::TaskBuilder; use std::task::TaskBuilder;
#[cfg(not(test), target_os="android")] #[cfg(not(test), target_os="android")]
use std::string; use std::string;
#[cfg(not(test))]
use url::{Url, UrlParser};
#[cfg(not(test), target_os="android")] #[cfg(not(test), target_os="android")]
#[no_mangle] #[no_mangle]
@ -125,12 +123,15 @@ pub fn run(opts: opts::Opts) {
font_cache_task, font_cache_task,
time_profiler_chan_clone); time_profiler_chan_clone);
let base_url = Url::from_directory_path(&os::getcwd()).unwrap();
let mut url_parser = UrlParser::new();
let url_parser = url_parser.base_url(&base_url);
// Send the URL command to the constellation. // Send the URL command to the constellation.
for url in opts.urls.iter() { let cwd = os::getcwd();
let url = url_parser.parse(url.as_slice()).ok().expect("URL parsing failed"); for &url in opts.urls.iter() {
let url = match url::Url::parse(url.as_slice()) {
Ok(url) => url,
Err(url::RelativeUrlWithoutBase)
=> url::Url::from_file_path(&cwd.join(url)).unwrap(),
Err(_) => fail!("URL parsing failed"),
};
let ConstellationChan(ref chan) = constellation_chan; let ConstellationChan(ref chan) = constellation_chan;
chan.send(InitLoadUrlMsg(url)); chan.send(InitLoadUrlMsg(url));

View file

@ -1,6 +1,7 @@
== basic_width_px.html basic_width_em.html == basic_width_px.html basic_width_em.html
== br.html br-ref.html == br.html br-ref.html
== hello_a.html hello_b.html # `?` and `#` in the name is a test for https://github.com/servo/servo/issues/3340
== hello_a?foo#bar.html hello_b.html
== margin_a.html margin_b.html == margin_a.html margin_b.html
== root_pseudo_a.html root_pseudo_b.html == root_pseudo_a.html root_pseudo_b.html
== first_child_pseudo_a.html first_child_pseudo_b.html == first_child_pseudo_a.html first_child_pseudo_b.html
@ -100,11 +101,11 @@ experimental == vertical-lr-blocks.html vertical-lr-blocks_ref.html
== root_margin_collapse_a.html root_margin_collapse_b.html == root_margin_collapse_a.html root_margin_collapse_b.html
# Should be == with expected failure: # Should be == with expected failure:
!= ../html/acid2.html#top acid2_ref.html fragment=top != ../html/acid2.html acid2_ref.html
# Should be != with expected failure: # Should be != with expected failure:
# FIXME: use the real test when pixel-snapping for scrolling is fixed. # FIXME: use the real test when pixel-snapping for scrolling is fixed.
#== ../html/acid2.html#top acid2_ref_broken.html #fragment=top == ../html/acid2.html acid2_ref_broken.html
flaky_gpu,flaky_linux == acid2_noscroll.html acid2_ref_broken.html flaky_gpu,flaky_linux == acid2_noscroll.html acid2_ref_broken.html
!= inline_background_a.html inline_background_ref.html != inline_background_a.html inline_background_ref.html

View file

@ -13,15 +13,18 @@ extern crate png;
extern crate std; extern crate std;
extern crate test; extern crate test;
extern crate regex; extern crate regex;
extern crate url;
use std::ascii::StrAsciiExt; use std::ascii::StrAsciiExt;
use std::io; use std::io;
use std::io::{File, Reader, Command}; use std::io::{File, Reader, Command};
use std::io::process::ExitStatus; use std::io::process::ExitStatus;
use std::os; use std::os;
use std::path::Path;
use test::{AutoColor, DynTestName, DynTestFn, TestDesc, TestOpts, TestDescAndFn}; use test::{AutoColor, DynTestName, DynTestFn, TestDesc, TestOpts, TestDescAndFn};
use test::run_tests_console; use test::run_tests_console;
use regex::Regex; use regex::Regex;
use url::Url;
bitflags!( bitflags!(
@ -71,9 +74,8 @@ fn main() {
match maybe_extension { match maybe_extension {
Some(extension) => { Some(extension) => {
if extension.to_ascii_lower().as_slice() == "list" && file.is_file() { if extension.to_ascii_lower().as_slice() == "list" && file.is_file() {
let manifest = file.as_str().unwrap(); let tests = parse_lists(&file, servo_args, render_mode, all_tests.len());
let tests = parse_lists(manifest, servo_args, render_mode, all_tests.len()); println!("\t{} [{} tests]", file.display(), tests.len());
println!("\t{} [{} tests]", manifest, tests.len());
all_tests.push_all_move(tests); all_tests.push_all_move(tests);
} }
} }
@ -111,12 +113,13 @@ enum ReftestKind {
struct Reftest { struct Reftest {
name: String, name: String,
kind: ReftestKind, kind: ReftestKind,
files: [String, ..2], files: [Path, ..2],
id: uint, id: uint,
servo_args: Vec<String>, servo_args: Vec<String>,
render_mode: RenderMode, render_mode: RenderMode,
is_flaky: bool, is_flaky: bool,
experimental: bool, experimental: bool,
fragment_identifier: Option<String>,
} }
struct TestLine<'a> { struct TestLine<'a> {
@ -126,10 +129,9 @@ struct TestLine<'a> {
file_right: &'a str, file_right: &'a str,
} }
fn parse_lists(file: &str, servo_args: &[String], render_mode: RenderMode, id_offset: uint) -> Vec<TestDescAndFn> { fn parse_lists(file: &Path, servo_args: &[String], render_mode: RenderMode, id_offset: uint) -> Vec<TestDescAndFn> {
let mut tests = Vec::new(); let mut tests = Vec::new();
let file_path = Path::new(file); let contents = File::open_mode(file, io::Open, io::Read)
let contents = File::open_mode(&file_path, io::Open, io::Read)
.and_then(|mut f| f.read_to_string()) .and_then(|mut f| f.read_to_string())
.ok().expect("Could not read file"); .ok().expect("Could not read file");
@ -162,14 +164,14 @@ fn parse_lists(file: &str, servo_args: &[String], render_mode: RenderMode, id_of
"!=" => Different, "!=" => Different,
part => fail!("reftest line: '{:s}' has invalid kind '{:s}'", line, part) part => fail!("reftest line: '{:s}' has invalid kind '{:s}'", line, part)
}; };
let src_path = file_path.dir_path(); let base = file.dir_path();
let src_dir = src_path.display().to_string(); let file_left = base.join(test_line.file_left);
let file_left = src_dir.clone().append("/").append(test_line.file_left); let file_right = base.join(test_line.file_right);
let file_right = src_dir.append("/").append(test_line.file_right);
let mut conditions_list = test_line.conditions.split(','); let mut conditions_list = test_line.conditions.split(',');
let mut flakiness = RenderMode::empty(); let mut flakiness = RenderMode::empty();
let mut experimental = false; let mut experimental = false;
let mut fragment_identifier = None;
for condition in conditions_list { for condition in conditions_list {
match condition { match condition {
"flaky_cpu" => flakiness.insert(CpuRendering), "flaky_cpu" => flakiness.insert(CpuRendering),
@ -179,6 +181,9 @@ fn parse_lists(file: &str, servo_args: &[String], render_mode: RenderMode, id_of
"experimental" => experimental = true, "experimental" => experimental = true,
_ => (), _ => (),
} }
if condition.starts_with("fragment=") {
fragment_identifier = Some(condition.slice_from("fragment=".len()).to_string());
}
} }
let reftest = Reftest { let reftest = Reftest {
@ -190,6 +195,7 @@ fn parse_lists(file: &str, servo_args: &[String], render_mode: RenderMode, id_of
servo_args: servo_args.iter().map(|x| x.clone()).collect(), servo_args: servo_args.iter().map(|x| x.clone()).collect(),
is_flaky: render_mode.intersects(flakiness), is_flaky: render_mode.intersects(flakiness),
experimental: experimental, experimental: experimental,
fragment_identifier: fragment_identifier,
}; };
tests.push(make_test(reftest)); tests.push(make_test(reftest));
@ -212,27 +218,33 @@ fn make_test(reftest: Reftest) -> TestDescAndFn {
} }
fn capture(reftest: &Reftest, side: uint) -> (u32, u32, Vec<u8>) { fn capture(reftest: &Reftest, side: uint) -> (u32, u32, Vec<u8>) {
let filename = format!("/tmp/servo-reftest-{:06u}-{:u}.png", reftest.id, side); let png_filename = format!("/tmp/servo-reftest-{:06u}-{:u}.png", reftest.id, side);
let mut args = reftest.servo_args.clone(); let mut command = Command::new("target/servo");
command
.args(reftest.servo_args.as_slice())
// Allows pixel perfect rendering of Ahem font for reftests.
.arg("--disable-text-aa")
.args(["-f", "-o"])
.arg(png_filename.as_slice())
.arg({
let mut url = Url::from_file_path(&reftest.files[side]).unwrap();
url.fragment = reftest.fragment_identifier.clone();
url.to_string()
});
// GPU rendering is the default // GPU rendering is the default
if reftest.render_mode.contains(CpuRendering) { if reftest.render_mode.contains(CpuRendering) {
args.push("-c".to_string()); command.arg("-c");
} }
if reftest.experimental { if reftest.experimental {
args.push("--experimental".to_string()); command.arg("--experimental");
} }
// Allows pixel perfect rendering of Ahem font for reftests. let retval = match command.status() {
args.push("--disable-text-aa".to_string());
args.push_all(["-f".to_string(), "-o".to_string(), filename.clone(),
reftest.files[side].clone()]);
let retval = match Command::new("target/servo").args(args.as_slice()).status() {
Ok(status) => status, Ok(status) => status,
Err(e) => fail!("failed to execute process: {}", e), Err(e) => fail!("failed to execute process: {}", e),
}; };
assert!(retval == ExitStatus(0)); assert!(retval == ExitStatus(0));
let image = png::load_png(&from_str::<Path>(filename.as_slice()).unwrap()).unwrap(); let image = png::load_png(&from_str::<Path>(png_filename.as_slice()).unwrap()).unwrap();
let rgba8_bytes = match image.pixels { let rgba8_bytes = match image.pixels {
png::RGBA8(pixels) => pixels, png::RGBA8(pixels) => pixels,
_ => fail!(), _ => fail!(),