Skip to content

Commit 72f5b65

Browse files
committed
Add libtest-mimic
servo#528 regressed the DX significantly, add a lighter and more maintained test harness to get basic functionality like "run one test" back.
1 parent 83e8f65 commit 72f5b65

6 files changed

+23
-17
lines changed

rcdom/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ markup5ever = { version = "0.14", path = "../markup5ever" }
2121
xml5ever = { version = "0.20", path = "../xml5ever" }
2222

2323
[dev-dependencies]
24+
libtest-mimic = "0.8.1"
2425
serde_json = "1.0"
2526

2627
[[test]]

rcdom/tests/html-tokenizer.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use std::io::Read;
2828
use std::path::Path;
2929
use std::{char, env};
3030

31-
use util::runner::Test;
31+
use util::runner::{run_all, Test};
3232

3333
mod util {
3434
pub mod runner;
@@ -481,7 +481,5 @@ fn tests(src_dir: &Path) -> Vec<Test> {
481481
}
482482

483483
fn main() {
484-
for test in tests(Path::new(env!("CARGO_MANIFEST_DIR"))) {
485-
test.run();
486-
}
484+
run_all(tests(Path::new(env!("CARGO_MANIFEST_DIR"))));
487485
}

rcdom/tests/html-tree-builder.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use html5ever::tendril::{StrTendril, TendrilSink};
2424
use html5ever::{parse_document, parse_fragment, ParseOpts};
2525
use html5ever::{LocalName, QualName};
2626
use rcdom::{Handle, NodeData, RcDom};
27-
use util::runner::Test;
27+
use util::runner::{run_all, Test};
2828

2929
mod util {
3030
pub mod runner;
@@ -297,7 +297,5 @@ fn main() {
297297
}
298298
}
299299

300-
for test in tests(src_dir, &ignores) {
301-
test.run();
302-
}
300+
run_all(tests(src_dir, &ignores));
303301
}

rcdom/tests/util/runner.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10+
use libtest_mimic::{Arguments, Trial};
11+
1012
/// Simple container for storing tests for later execution
1113
pub struct Test {
1214
pub name: String,
1315
pub skip: bool,
14-
pub test: Box<dyn Fn()>,
16+
pub test: Box<dyn Fn() + Send + Sync>,
1517
}
1618

1719
impl Test {
@@ -30,3 +32,14 @@ impl Test {
3032
}
3133
}
3234
}
35+
36+
pub fn run_all(tests: Vec<Test>) {
37+
let mut harness_tests = Vec::new();
38+
39+
for test in tests {
40+
let harness_test = Trial::test(test.name.clone(), move || Ok(test.run()));
41+
harness_tests.push(harness_test);
42+
}
43+
let args = Arguments::from_args();
44+
libtest_mimic::run(&args, harness_tests).exit();
45+
}

rcdom/tests/xml-tokenizer.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::io::Read;
1616
use std::path::Path;
1717

1818
use util::find_tests::foreach_xml5lib_test;
19-
use util::runner::Test;
19+
use util::runner::{run_all, Test};
2020

2121
use markup5ever::buffer_queue::BufferQueue;
2222
use xml5ever::tendril::{SliceExt, StrTendril};
@@ -372,7 +372,5 @@ fn tests(src_dir: &Path) -> Vec<Test> {
372372
}
373373

374374
fn main() {
375-
for test in tests(Path::new(env!("CARGO_MANIFEST_DIR"))) {
376-
test.run();
377-
}
375+
run_all(tests(Path::new(env!("CARGO_MANIFEST_DIR"))));
378376
}

rcdom/tests/xml-tree-builder.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::io::BufRead;
1515
use std::path::Path;
1616
use std::{env, fs, io, iter, mem};
1717
use util::find_tests::foreach_xml5lib_test;
18-
use util::runner::Test;
18+
use util::runner::{run_all, Test};
1919
use xml5ever::driver::parse_document;
2020
use xml5ever::tendril::TendrilSink;
2121

@@ -236,7 +236,5 @@ fn main() {
236236
}
237237
}
238238

239-
for test in tests(src_dir, &ignores) {
240-
test.run();
241-
}
239+
run_all(tests(src_dir, &ignores));
242240
}

0 commit comments

Comments
 (0)