Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libtest-mimic #558

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}