Skip to content

Commit

Permalink
Add libtest-mimic (servo#558)
Browse files Browse the repository at this point in the history
* 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.

* appease clippy
  • Loading branch information
untitaker authored Oct 28, 2024
1 parent 83e8f65 commit 8ca1bc6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions rcdom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ markup5ever = { version = "0.14", path = "../markup5ever" }
xml5ever = { version = "0.20", path = "../xml5ever" }

[dev-dependencies]
libtest-mimic = "0.8.1"
serde_json = "1.0"

[[test]]
Expand Down
6 changes: 2 additions & 4 deletions rcdom/tests/html-tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::io::Read;
use std::path::Path;
use std::{char, env};

use util::runner::Test;
use util::runner::{run_all, Test};

mod util {
pub mod runner;
Expand Down Expand Up @@ -481,7 +481,5 @@ fn tests(src_dir: &Path) -> Vec<Test> {
}

fn main() {
for test in tests(Path::new(env!("CARGO_MANIFEST_DIR"))) {
test.run();
}
run_all(tests(Path::new(env!("CARGO_MANIFEST_DIR"))));
}
6 changes: 2 additions & 4 deletions rcdom/tests/html-tree-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use html5ever::tendril::{StrTendril, TendrilSink};
use html5ever::{parse_document, parse_fragment, ParseOpts};
use html5ever::{LocalName, QualName};
use rcdom::{Handle, NodeData, RcDom};
use util::runner::Test;
use util::runner::{run_all, Test};

mod util {
pub mod runner;
Expand Down Expand Up @@ -297,7 +297,5 @@ fn main() {
}
}

for test in tests(src_dir, &ignores) {
test.run();
}
run_all(tests(src_dir, &ignores));
}
18 changes: 17 additions & 1 deletion rcdom/tests/util/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use libtest_mimic::{Arguments, Trial};

/// Simple container for storing tests for later execution
pub struct Test {
pub name: String,
pub skip: bool,
pub test: Box<dyn Fn()>,
pub test: Box<dyn Fn() + Send + Sync>,
}

impl Test {
Expand All @@ -30,3 +32,17 @@ impl Test {
}
}
}

pub fn run_all(tests: Vec<Test>) {
let mut harness_tests = Vec::new();

for test in tests {
let harness_test = Trial::test(test.name.clone(), move || {
test.run();
Ok(())
});
harness_tests.push(harness_test);
}
let args = Arguments::from_args();
libtest_mimic::run(&args, harness_tests).exit();
}
6 changes: 2 additions & 4 deletions rcdom/tests/xml-tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::io::Read;
use std::path::Path;

use util::find_tests::foreach_xml5lib_test;
use util::runner::Test;
use util::runner::{run_all, Test};

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

fn main() {
for test in tests(Path::new(env!("CARGO_MANIFEST_DIR"))) {
test.run();
}
run_all(tests(Path::new(env!("CARGO_MANIFEST_DIR"))));
}
6 changes: 2 additions & 4 deletions rcdom/tests/xml-tree-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::io::BufRead;
use std::path::Path;
use std::{env, fs, io, iter, mem};
use util::find_tests::foreach_xml5lib_test;
use util::runner::Test;
use util::runner::{run_all, Test};
use xml5ever::driver::parse_document;
use xml5ever::tendril::TendrilSink;

Expand Down Expand Up @@ -236,7 +236,5 @@ fn main() {
}
}

for test in tests(src_dir, &ignores) {
test.run();
}
run_all(tests(src_dir, &ignores));
}

0 comments on commit 8ca1bc6

Please sign in to comment.