diff --git a/Cargo.toml b/Cargo.toml index 79ac0a62..1b453468 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,5 +21,8 @@ git = "https://github.com/reem/rust-mac" [dependencies.html5ever_macros] path = "macros" +[dev-dependencies] +rustc-serialize = "0" + [dev-dependencies.test_util] path = "test_util" diff --git a/Makefile.in b/Makefile.in index 5caff59b..738a118a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -10,9 +10,12 @@ VPATH := %VPATH% RUSTC ?= rustc -RUST_DIRS := -L $(VPATH)/target -L $(VPATH)/target/deps +RUST_DIRS := -L $(VPATH)/target/debug -L $(VPATH)/target/debug/deps -RUSTC_CMD := $(RUSTC) -D warnings -C rpath $(RUST_DIRS) --extern time=`find $(VPATH)/target/deps -name 'libtime-*.rlib'` --extern log=`find $(VPATH)/target/deps -name 'liblog-*.rlib'` $(RUSTFLAGS) +RUSTC_CMD := $(RUSTC) -D warnings -C rpath $(RUST_DIRS) \ + --extern time=`find $(VPATH)/target/debug/deps -name 'libtime-*.rlib'` \ + --extern log=`find $(VPATH)/target/debug/deps -name 'liblog-*.rlib'` \ + $(RUSTFLAGS) # We build the library itself using Cargo. CARGO_SOURCES := $(shell find $(VPATH)/src $(VPATH)/macros/src -type f -name '*.rs') diff --git a/benches/tokenizer.rs b/benches/tokenizer.rs index 806edc8f..2c5a6d84 100644 --- a/benches/tokenizer.rs +++ b/benches/tokenizer.rs @@ -7,18 +7,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(box_syntax, core, old_io, old_path, std_misc, start, test)] +#![feature(box_syntax, core, std_misc, start, test, io, path)] extern crate test; extern crate html5ever; -use std::old_io as io; -use std::{env, cmp, rt}; +use std::{fs, env, cmp, rt}; +use std::path::PathBuf; +use std::io::Read; use std::default::Default; use test::{black_box, Bencher, TestDesc, TestDescAndFn}; use test::{DynTestName, DynBenchFn, TDynBenchFn}; -use test::ShouldFail::No; +use test::ShouldPanic::No; use html5ever::tokenizer::{TokenSink, Token, Tokenizer, TokenizerOpts}; @@ -43,13 +44,14 @@ struct Bench { impl Bench { fn new(name: &str, size: Option, clone_only: bool, opts: TokenizerOpts) -> Bench { - let mut path = Path::new(env!("CARGO_MANIFEST_DIR")); + let mut path = PathBuf::new(env!("CARGO_MANIFEST_DIR")); path.push("data/bench/"); path.push(name); - let mut file = io::File::open(&path).ok().expect("can't open file"); + let mut file = fs::File::open(&path).ok().expect("can't open file"); // Read the file and treat it as an infinitely repeating sequence of characters. - let file_input = file.read_to_string().ok().expect("can't read file"); + let mut file_input = String::new(); + file.read_to_string(&mut file_input).ok().expect("can't read file"); let size = size.unwrap_or(file_input.len()); let mut stream = file_input.as_slice().chars().cycle(); @@ -107,7 +109,7 @@ fn make_bench(name: &str, size: Option, clone_only: bool, (if opts.exact_errors { " (exact errors)" } else { "" }).to_string(), ].concat().to_string()), ignore: false, - should_fail: No, + should_panic: No, }, testfn: DynBenchFn(box Bench::new(name, size, clone_only, opts)), } diff --git a/examples/noop-tokenize.rs b/examples/noop-tokenize.rs index 8ee7b59e..911c191f 100644 --- a/examples/noop-tokenize.rs +++ b/examples/noop-tokenize.rs @@ -9,7 +9,7 @@ // Run a single benchmark once. For use with profiling tools. -#![feature(core, test, io, path, fs)] +#![feature(core, test, io, path)] extern crate test; extern crate html5ever; diff --git a/examples/print-rcdom.rs b/examples/print-rcdom.rs index 19860140..d315a51c 100644 --- a/examples/print-rcdom.rs +++ b/examples/print-rcdom.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(plugin, old_io)] +#![feature(plugin, old_io, collections)] #![plugin(string_cache_plugin)] extern crate html5ever; diff --git a/examples/print-tree-actions.rs b/examples/print-tree-actions.rs index cbdf8243..e1f8905f 100644 --- a/examples/print-tree-actions.rs +++ b/examples/print-tree-actions.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(old_io)] +#![feature(old_io, collections)] extern crate string_cache; diff --git a/examples/tokenize.rs b/examples/tokenize.rs index 0b776571..dbf77aa0 100644 --- a/examples/tokenize.rs +++ b/examples/tokenize.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(core, old_io)] +#![feature(core, old_io, collections)] extern crate html5ever; diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 9885db95..9bcecfbd 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -9,5 +9,8 @@ authors = [ "The html5ever Project Developers" ] name = "html5ever_macros" plugin = true +[dependencies] +rustc-serialize = "0" + [dependencies.mac] git = "https://github.com/reem/rust-mac" diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 9e761108..c2b4bc01 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -11,12 +11,12 @@ #![crate_type="dylib"] #![feature(plugin_registrar, quote)] -#![feature(rustc_private, core, collections, old_path, old_io, std_misc)] +#![feature(rustc_private, core, collections, std_misc, path)] #![deny(warnings)] extern crate syntax; extern crate rustc; -extern crate "serialize" as rustc_serialize; +extern crate "rustc-serialize" as rustc_serialize; #[macro_use] extern crate mac; diff --git a/macros/src/named_entities.rs b/macros/src/named_entities.rs index cb475ea6..8a752e57 100644 --- a/macros/src/named_entities.rs +++ b/macros/src/named_entities.rs @@ -9,8 +9,8 @@ #![allow(unused_imports)] // for quotes -use std::old_io as io; -use std::old_path as path; +use std::path::PathBuf; +use std::fs; use std::str::FromStr; use std::collections::HashMap; @@ -83,7 +83,6 @@ pub fn expand(cx: &mut ExtCtxt, sp: Span, tt: &[TokenTree]) -> Box match e.node { ExprLit(ref s) => match s.node { @@ -96,14 +95,14 @@ pub fn expand(cx: &mut ExtCtxt, sp: Span, tt: &[TokenTree]) -> Box( - src_dir: Path, + src_dir: &Path, subdir: &'static str, - ext: &'static str, + ext: &'static OsStr, mut mk: Mk) - where Mk: FnMut(&str, io::File) + where Mk: FnMut(&Path, fs::File) { - let test_dir_path = src_dir.join_many(&["html5lib-tests", subdir]); - let test_files = io::fs::readdir(&test_dir_path).unwrap(); - for path in test_files.into_iter() { - let path_str = path.filename_str().unwrap(); - if path_str.ends_with(ext) { - let file = io::File::open(&path).unwrap(); - mk(path_str, file); + let mut test_dir_path = src_dir.to_path_buf(); + test_dir_path.push("html5lib-tests"); + test_dir_path.push(subdir); + + let test_files = fs::read_dir(&test_dir_path).unwrap(); + for entry in test_files { + let path = entry.unwrap().path(); + if path.extension() == Some(ext) { + let file = fs::File::open(&path).unwrap(); + mk(&path, file); } } } diff --git a/tests/tokenizer.rs b/tests/tokenizer.rs index 8acd3fd1..65cb34e0 100644 --- a/tests/tokenizer.rs +++ b/tests/tokenizer.rs @@ -7,12 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(core, old_io, old_path, plugin, rustc_private, start, std_misc, test)] +#![feature(core, plugin, start, std_misc, test, path)] #![plugin(string_cache_plugin)] extern crate test; -extern crate serialize; +extern crate "rustc-serialize" as rustc_serialize; extern crate string_cache; extern crate html5ever; @@ -21,14 +21,14 @@ extern crate test_util; use test_util::foreach_html5lib_test; use std::{num, char, env, rt}; +use std::ffi::OsStr; use std::mem::replace; use std::default::Default; -use std::old_path::Path; +use std::path::Path; use std::thunk::Thunk; use test::{TestDesc, TestDescAndFn, DynTestName, DynTestFn}; -use test::ShouldFail::No; -use serialize::json; -use serialize::json::Json; +use test::ShouldPanic::No; +use rustc_serialize::json::Json; use std::collections::BTreeMap; use std::borrow::Cow::Borrowed; @@ -307,7 +307,7 @@ fn mk_test(desc: String, input: String, expect: Vec, opts: TokenizerOpts) desc: TestDesc { name: DynTestName(desc), ignore: false, - should_fail: No, + should_panic: No, }, testfn: DynTestFn(Thunk::new(move || { // Split up the input at different points to test incremental tokenization. @@ -327,12 +327,12 @@ fn mk_test(desc: String, input: String, expect: Vec, opts: TokenizerOpts) } } -fn mk_tests(tests: &mut Vec, path_str: &str, js: &Json) { +fn mk_tests(tests: &mut Vec, filename: &str, js: &Json) { let obj = js.get_obj(); let mut input = js.find("input").unwrap().get_str(); let mut expect = js.find("output").unwrap().clone(); let desc = format!("tok: {}: {}", - path_str, js.find("description").unwrap().get_str()); + filename, js.find("description").unwrap().get_str()); // "Double-escaped" tests require additional processing of // the input and output. @@ -388,17 +388,17 @@ fn mk_tests(tests: &mut Vec, path_str: &str, js: &Json) { } } -fn tests(src_dir: Path) -> Vec { +fn tests(src_dir: &Path) -> Vec { let mut tests = vec!(); - foreach_html5lib_test(src_dir, "tokenizer", ".test", |path_str, mut file| { - let js = json::from_reader(&mut file as &mut Reader) - .ok().expect("json parse error"); + foreach_html5lib_test(src_dir, "tokenizer", + OsStr::from_str("test"), |path, mut file| { + let js = Json::from_reader(&mut file).ok().expect("json parse error"); match js.get_obj().get(&"tests".to_string()) { Some(&Json::Array(ref lst)) => { for test in lst.iter() { - mk_tests(&mut tests, path_str.as_slice(), test); + mk_tests(&mut tests, path.file_name().unwrap().to_str().unwrap(), test); } } diff --git a/tests/tree_builder.rs b/tests/tree_builder.rs index 5eafa0fa..6f65cbbc 100644 --- a/tests/tree_builder.rs +++ b/tests/tree_builder.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(core, old_io, old_path, plugin, start, std_misc, test)] +#![feature(core, plugin, start, std_misc, test, io, path)] #![plugin(string_cache_plugin)] @@ -19,16 +19,17 @@ extern crate test_util; use test_util::foreach_html5lib_test; -use std::old_io as io; -use std::{env, rt}; +use std::{fs, io, env, rt}; +use std::io::BufReadExt; +use std::ffi::OsStr; use std::iter::repeat; use std::mem::replace; use std::default::Default; -use std::old_path::Path; +use std::path::Path; use std::collections::{HashSet, HashMap}; use std::thunk::Thunk; use test::{TestDesc, TestDescAndFn, DynTestName, DynTestFn}; -use test::ShouldFail::No; +use test::ShouldPanic::No; use html5ever::sink::common::{Document, Doctype, Text, Comment, Element}; use html5ever::sink::rcdom::{RcDom, Handle}; @@ -45,7 +46,9 @@ fn parse_tests>(mut lines: It) -> Vec ( match key.take() { None => (), - Some(key) => assert!(test.insert(key, replace(&mut val, String::new())).is_none()), + Some(key) => { + assert!(test.insert(key, replace(&mut val, String::new())).is_none()); + } } )); @@ -61,12 +64,13 @@ fn parse_tests>(mut lines: It) -> Vec { if line.starts_with("#") { finish_val!(); - if line.as_slice() == "#data\n" { + if line.as_slice() == "#data" { finish_test!(); } - key = Some(line[1..].trim_right_matches('\n').to_string()); + key = Some(line[1..].to_string()); } else { val.push_str(line.as_slice()); + val.push('\n'); } } } @@ -138,7 +142,7 @@ static IGNORE_SUBSTRS: &'static [&'static str] fn make_test( tests: &mut Vec, ignores: &HashSet, - path_str: &str, + filename: &str, idx: usize, fields: HashMap) { @@ -151,7 +155,7 @@ fn make_test( let expected = get_field("document"); let context = fields.get("document-fragment") .map(|field| Atom::from_slice(field.as_slice().trim_right_matches('\n'))); - let name = format!("tb: {}-{}", path_str, idx); + let name = format!("tb: {}-{}", filename, idx); let ignore = ignores.contains(&name) || IGNORE_SUBSTRS.iter().any(|&ig| data.as_slice().contains(ig)); @@ -159,7 +163,7 @@ fn make_test( desc: TestDesc { name: DynTestName(name), ignore: ignore, - should_fail: No, + should_panic: No, }, testfn: DynTestFn(Thunk::new(move || { let mut result = String::new(); @@ -194,17 +198,19 @@ fn make_test( }); } -fn tests(src_dir: Path, ignores: &HashSet) -> Vec { +fn tests(src_dir: &Path, ignores: &HashSet) -> Vec { let mut tests = vec!(); - foreach_html5lib_test(src_dir, "tree-construction", ".dat", |path_str, file| { - let mut buf = io::BufferedReader::new(file); + foreach_html5lib_test(src_dir, "tree-construction", + OsStr::from_str("dat"), |path, file| { + let buf = io::BufReader::new(file); let lines = buf.lines() .map(|res| res.ok().expect("couldn't read")); let data = parse_tests(lines); for (i, test) in data.into_iter().enumerate() { - make_test(&mut tests, ignores, path_str, i, test); + make_test(&mut tests, ignores, path.file_name().unwrap().to_str().unwrap(), + i, test); } }); @@ -220,8 +226,8 @@ fn start(argc: isize, argv: *const *const u8) -> isize { let src_dir = Path::new(env!("CARGO_MANIFEST_DIR")); let mut ignores = HashSet::new(); { - let f = io::File::open(&src_dir.join("data/test/ignore")).unwrap(); - let mut r = io::BufferedReader::new(f); + let f = fs::File::open(&src_dir.join("data/test/ignore")).unwrap(); + let r = io::BufReader::new(f); for ln in r.lines() { ignores.insert(ln.unwrap().as_slice().trim_right().to_string()); }