diff --git a/Cargo.toml b/Cargo.toml index f413f8e6..47e7b679 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,17 @@ name = "html5ever" # https://github.com/rust-lang/cargo/issues/1512 doctest = false +[[test]] +name = "tree_builder" +harness = false + +[[test]] +name = "tokenizer" +harness = false + +[[test]] +name = "serializer" + [features] unstable = ["tendril/unstable", "string_cache/unstable"] heap_size = ["heapsize", "heapsize_plugin"] @@ -32,6 +43,7 @@ heapsize_plugin = { version = "0.1.0", optional = true } [dev-dependencies] rustc-serialize = "0.3.15" +rustc-test = "0.1" [build-dependencies] phf_codegen = "0.7.3" diff --git a/scripts/shrink-test-output.py b/scripts/shrink-test-output.py index 74be7b3b..568848b9 100755 --- a/scripts/shrink-test-output.py +++ b/scripts/shrink-test-output.py @@ -10,6 +10,7 @@ import re import sys +import subprocess REPLACEMENTS = { @@ -21,11 +22,12 @@ r'^test .* \.\.\. ({0})$'.format('|'.join(REPLACEMENTS.keys()))) -def main(): +def main(args): + process = subprocess.Popen(args, stdout=subprocess.PIPE) while True: - line = sys.stdin.readline() + line = process.stdout.readline() if len(line) is 0: - break + return process.wait() match = TEST_RESULT_RE.match(line) if match: sys.stdout.write(REPLACEMENTS[match.group(1)]) @@ -35,4 +37,4 @@ def main(): if __name__ == '__main__': - sys.exit(main()) + sys.exit(main(sys.argv[1:])) diff --git a/scripts/travis-build.sh b/scripts/travis-build.sh index f3169ff0..fa4ed3f5 100755 --- a/scripts/travis-build.sh +++ b/scripts/travis-build.sh @@ -10,18 +10,11 @@ set -ex -# Test without unstable first, to make sure src/tree_builder/rules.expanded.rs is up-to-date. -cargo test --no-run -cargo test | ./scripts/shrink-test-output.py -r=${PIPESTATUS[0]} -if [ $r -ne 0 ]; then exit $r; fi +./scripts/shrink-test-output.py cargo test --color always if [ $TRAVIS_RUST_VERSION = nightly ] then - cargo test --no-run --features unstable - cargo test --features unstable | ./scripts/shrink-test-output.py - r=${PIPESTATUS[0]} - if [ $r -ne 0 ]; then exit $r; fi + ./scripts/shrink-test-output.py cargo test --color always --features unstable cargo test --manifest-path capi/Cargo.toml fi diff --git a/tests/tokenizer.rs b/tests/tokenizer.rs index 38875e3f..2faebfe2 100644 --- a/tests/tokenizer.rs +++ b/tests/tokenizer.rs @@ -7,12 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(feature = "unstable", feature(test))] - -#[cfg(feature = "unstable")] extern crate test; extern crate rustc_serialize; #[macro_use] extern crate string_cache; extern crate tendril; +extern crate test; extern crate html5ever; @@ -24,8 +22,8 @@ use std::ffi::OsStr; use std::mem::replace; use std::default::Default; use std::path::Path; -#[cfg(feature = "unstable")] use test::{TestDesc, TestDescAndFn, DynTestName, DynTestFn}; -#[cfg(feature = "unstable")] use test::ShouldPanic::No; +use test::{TestDesc, TestDescAndFn, DynTestName, DynTestFn}; +use test::ShouldPanic::No; use rustc_serialize::json::Json; use std::collections::BTreeMap; use std::borrow::Cow::Borrowed; @@ -308,7 +306,6 @@ fn unescape_json(js: &Json) -> Json { } } -#[cfg(feature = "unstable")] fn mk_test(desc: String, input: String, expect: Vec, opts: TokenizerOpts) -> TestDescAndFn { TestDescAndFn { @@ -335,7 +332,6 @@ fn mk_test(desc: String, input: String, expect: Vec, opts: TokenizerOpts) } } -#[cfg(feature = "unstable")] fn mk_tests(tests: &mut Vec, filename: &str, js: &Json) { let obj = js.get_obj(); let mut input = js.find("input").unwrap().get_str(); @@ -397,7 +393,6 @@ fn mk_tests(tests: &mut Vec, filename: &str, js: &Json) { } } -#[cfg(feature = "unstable")] fn tests(src_dir: &Path) -> Vec { let mut tests = vec!(); @@ -420,9 +415,7 @@ fn tests(src_dir: &Path) -> Vec { tests } -#[cfg(feature = "unstable")] -#[test] -fn run() { +fn main() { let args: Vec<_> = env::args().collect(); test::test_main(&args, tests(Path::new(env!("CARGO_MANIFEST_DIR")))); } diff --git a/tests/tree_builder.rs b/tests/tree_builder.rs index 290ebeaa..527512c0 100644 --- a/tests/tree_builder.rs +++ b/tests/tree_builder.rs @@ -7,9 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(feature = "unstable", feature(test))] - -#[cfg(feature = "unstable")] extern crate test; +extern crate test; #[macro_use] extern crate string_cache; extern crate tendril; @@ -26,8 +24,8 @@ use std::mem::replace; use std::default::Default; use std::path::Path; use std::collections::{HashSet, HashMap}; -#[cfg(feature = "unstable")] use test::{TestDesc, TestDescAndFn, DynTestName, DynTestFn}; -#[cfg(feature = "unstable")] use test::ShouldPanic::No; +use test::{TestDesc, TestDescAndFn, DynTestName, TestFn}; +use test::ShouldPanic::No; use html5ever::{ParseOpts, parse_document, parse_fragment}; use html5ever::rcdom::{Comment, Document, Doctype, Element, Handle, RcDom}; @@ -152,7 +150,6 @@ fn serialize(buf: &mut String, indent: usize, handle: Handle) { } } -#[cfg(feature = "unstable")] fn make_test( tests: &mut Vec, ignores: &HashSet, @@ -176,7 +173,6 @@ fn make_test( } } -#[cfg(feature = "unstable")] fn make_test_desc_with_scripting_flag( ignores: &HashSet, name: &str, @@ -209,7 +205,7 @@ fn make_test_desc_with_scripting_flag( ignore: ignore, should_panic: No, }, - testfn: DynTestFn(Box::new(move || { + testfn: TestFn::dyn_test_fn(move || { // Do this here because Tendril isn't Send. let data = StrTendril::from_slice(&data); let mut result = String::new(); @@ -239,11 +235,10 @@ fn make_test_desc_with_scripting_flag( panic!("\ninput: {}\ngot:\n{}\nexpected:\n{}\n", data, result, expected); } - })), + }), } } -#[cfg(feature = "unstable")] fn context_name(context: &str) -> QualName { if context.starts_with("svg ") { QualName::new(ns!(svg), Atom::from(&context[4..])) @@ -254,7 +249,6 @@ fn context_name(context: &str) -> QualName { } } -#[cfg(feature = "unstable")] fn tests(src_dir: &Path, ignores: &HashSet) -> Vec { let mut tests = vec!(); @@ -274,9 +268,7 @@ fn tests(src_dir: &Path, ignores: &HashSet) -> Vec { tests } -#[cfg(feature = "unstable")] -#[test] -fn run() { +fn main() { let args: Vec<_> = env::args().collect(); let src_dir = Path::new(env!("CARGO_MANIFEST_DIR")); let mut ignores = HashSet::new();