diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2014-09-16 20:32:40 +0100 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2014-09-16 20:32:40 +0100 |
commit | 14f7d2dabdbe63f7728cb4ed6fa6a012d7de2cec (patch) | |
tree | 0e1d30d952ce070a436259dda09cfdf5b1bb34a1 | |
parent | ef56335efe393e0ac06eb923b29b823b27b21c7c (diff) | |
parent | 4768423eaa987e1d75a0b41995596aca652ae2aa (diff) | |
download | servo-14f7d2dabdbe63f7728cb4ed6fa6a012d7de2cec.tar.gz servo-14f7d2dabdbe63f7728cb4ed6fa6a012d7de2cec.zip |
Merge pull request #3365 from SimonSapin/command-line-argument-filenames
Try to parse command line argument as file names
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/lib.rs | 15 | ||||
-rw-r--r-- | tests/ref/basic.list | 7 | ||||
-rw-r--r-- | tests/ref/hello_a?foo#bar.html (renamed from tests/ref/hello_a.html) | 0 | ||||
-rw-r--r-- | tests/reftest.rs | 56 |
6 files changed, 50 insertions, 32 deletions
diff --git a/Cargo.lock b/Cargo.lock index 8220a58ce77..837f7413738 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,7 @@ dependencies = [ "msg 0.0.1", "net 0.0.1", "script 0.0.1", + "url 0.1.0 (git+https://github.com/servo/rust-url#678bb4d52638b1cfdab78ef8e521566c9240fb1a)", "util 0.0.1", ] diff --git a/Cargo.toml b/Cargo.toml index e825de157b0..2472f99be99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,3 +45,6 @@ path = "components/layout" [dependencies.gfx] path = "components/gfx" + +[dependencies.url] +git = "https://github.com/servo/rust-url" diff --git a/src/lib.rs b/src/lib.rs index bb01ad7c739..a00d935ade3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,8 +57,6 @@ use std::os; use std::task::TaskBuilder; #[cfg(not(test), target_os="android")] use std::string; -#[cfg(not(test))] -use url::{Url, UrlParser}; #[cfg(not(test), target_os="android")] #[no_mangle] @@ -125,12 +123,15 @@ pub fn run(opts: opts::Opts) { font_cache_task, 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. - for url in opts.urls.iter() { - let url = url_parser.parse(url.as_slice()).ok().expect("URL parsing failed"); + let cwd = os::getcwd(); + 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; chan.send(InitLoadUrlMsg(url)); diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 9e325df466d..87ba15eac36 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -1,6 +1,7 @@ == basic_width_px.html basic_width_em.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 == root_pseudo_a.html root_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 # 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: # 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 != inline_background_a.html inline_background_ref.html diff --git a/tests/ref/hello_a.html b/tests/ref/hello_a?foo#bar.html index 6ef40f0f03c..6ef40f0f03c 100644 --- a/tests/ref/hello_a.html +++ b/tests/ref/hello_a?foo#bar.html diff --git a/tests/reftest.rs b/tests/reftest.rs index a092b6b32be..b07f7ce71ea 100644 --- a/tests/reftest.rs +++ b/tests/reftest.rs @@ -13,15 +13,18 @@ extern crate png; extern crate std; extern crate test; extern crate regex; +extern crate url; use std::ascii::StrAsciiExt; use std::io; use std::io::{File, Reader, Command}; use std::io::process::ExitStatus; use std::os; +use std::path::Path; use test::{AutoColor, DynTestName, DynTestFn, TestDesc, TestOpts, TestDescAndFn}; use test::run_tests_console; use regex::Regex; +use url::Url; bitflags!( @@ -71,9 +74,8 @@ fn main() { match maybe_extension { Some(extension) => { if extension.to_ascii_lower().as_slice() == "list" && file.is_file() { - let manifest = file.as_str().unwrap(); - let tests = parse_lists(manifest, servo_args, render_mode, all_tests.len()); - println!("\t{} [{} tests]", manifest, tests.len()); + let tests = parse_lists(&file, servo_args, render_mode, all_tests.len()); + println!("\t{} [{} tests]", file.display(), tests.len()); all_tests.push_all_move(tests); } } @@ -111,12 +113,13 @@ enum ReftestKind { struct Reftest { name: String, kind: ReftestKind, - files: [String, ..2], + files: [Path, ..2], id: uint, servo_args: Vec<String>, render_mode: RenderMode, is_flaky: bool, experimental: bool, + fragment_identifier: Option<String>, } struct TestLine<'a> { @@ -126,10 +129,9 @@ struct TestLine<'a> { 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 file_path = Path::new(file); - let contents = File::open_mode(&file_path, io::Open, io::Read) + let contents = File::open_mode(file, io::Open, io::Read) .and_then(|mut f| f.read_to_string()) .ok().expect("Could not read file"); @@ -162,14 +164,14 @@ fn parse_lists(file: &str, servo_args: &[String], render_mode: RenderMode, id_of "!=" => Different, part => fail!("reftest line: '{:s}' has invalid kind '{:s}'", line, part) }; - let src_path = file_path.dir_path(); - let src_dir = src_path.display().to_string(); - let file_left = src_dir.clone().append("/").append(test_line.file_left); - let file_right = src_dir.append("/").append(test_line.file_right); + let base = file.dir_path(); + let file_left = base.join(test_line.file_left); + let file_right = base.join(test_line.file_right); let mut conditions_list = test_line.conditions.split(','); let mut flakiness = RenderMode::empty(); let mut experimental = false; + let mut fragment_identifier = None; for condition in conditions_list { match condition { "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, _ => (), } + if condition.starts_with("fragment=") { + fragment_identifier = Some(condition.slice_from("fragment=".len()).to_string()); + } } 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(), is_flaky: render_mode.intersects(flakiness), experimental: experimental, + fragment_identifier: fragment_identifier, }; 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>) { - let filename = format!("/tmp/servo-reftest-{:06u}-{:u}.png", reftest.id, side); - let mut args = reftest.servo_args.clone(); + let png_filename = format!("/tmp/servo-reftest-{:06u}-{:u}.png", reftest.id, side); + 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 if reftest.render_mode.contains(CpuRendering) { - args.push("-c".to_string()); + command.arg("-c"); } if reftest.experimental { - args.push("--experimental".to_string()); + command.arg("--experimental"); } - // Allows pixel perfect rendering of Ahem font for reftests. - 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() { + let retval = match command.status() { Ok(status) => status, Err(e) => fail!("failed to execute process: {}", e), }; 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 { png::RGBA8(pixels) => pixels, _ => fail!(), |