From 6e2ba6557718dd4792191ccf65ea53a58a3674d4 Mon Sep 17 00:00:00 2001 From: Kornel Date: Sun, 22 Dec 2024 11:53:13 +0000 Subject: [PATCH] Rip out rustc-test Fixes #251 --- Cargo.toml | 6 -- tests/fixtures/element_content_replacement.rs | 5 +- tests/fixtures/mod.rs | 5 -- tests/fixtures/selector_matching.rs | 5 +- tests/fixtures/token_capturing.rs | 5 +- tests/harness/mod.rs | 58 ++++--------------- tests/harness/suites/html5lib_tests/mod.rs | 2 +- tests/harness/suites/selectors_tests.rs | 5 +- tests/integration_tests.rs | 31 +++------- 9 files changed, 35 insertions(+), 87 deletions(-) delete mode 100644 tests/fixtures/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 78d23242..a4dc5cdc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ categories = ["parser-implementations", "web-programming"] keywords = ["html", "css-selectors", "parser", "rewriter", "streaming"] readme = "README.md" include = ["/Cargo.toml", "/LICENSE", "/README.md", "/media", "/src"] -autotests = false edition = "2021" [lib] @@ -23,10 +22,6 @@ debug_trace = [] # Unstable: for internal use only integration_test = [] -[[test]] -harness = false -name = "integration_tests" - [[bench]] harness = false name = "bench" @@ -55,7 +50,6 @@ serde_derive = "1.0.19" serde_json = "1.0.65" static_assertions = "1.1.0" rand = "0.8.5" -rustc-test = "0.3.1" itertools = "0.13" [lints.rust] diff --git a/tests/fixtures/element_content_replacement.rs b/tests/fixtures/element_content_replacement.rs index b7ba5d9d..d52a072a 100644 --- a/tests/fixtures/element_content_replacement.rs +++ b/tests/fixtures/element_content_replacement.rs @@ -49,4 +49,7 @@ impl TestFixture for ElementContentReplacementTests { } } -test_fixture!(ElementContentReplacementTests); +#[test] +fn test_element_content_replacement() { + ElementContentReplacementTests::run_tests(); +} diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs deleted file mode 100644 index 219adfd3..00000000 --- a/tests/fixtures/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -test_modules!( - token_capturing, - selector_matching, - element_content_replacement -); diff --git a/tests/fixtures/selector_matching.rs b/tests/fixtures/selector_matching.rs index 8400faf4..91fbfedd 100644 --- a/tests/fixtures/selector_matching.rs +++ b/tests/fixtures/selector_matching.rs @@ -86,4 +86,7 @@ impl TestFixture for SelectorMatchingTests { } } -test_fixture!(SelectorMatchingTests); +#[test] +fn test_selector_matching() { + SelectorMatchingTests::run_tests(); +} diff --git a/tests/fixtures/token_capturing.rs b/tests/fixtures/token_capturing.rs index 5adc776f..db58a251 100644 --- a/tests/fixtures/token_capturing.rs +++ b/tests/fixtures/token_capturing.rs @@ -258,4 +258,7 @@ impl TestFixture for TokenCapturingTests { } } -test_fixture!(TokenCapturingTests); +#[test] +fn test_token_capturing() { + TokenCapturingTests::run_tests(); +} diff --git a/tests/harness/mod.rs b/tests/harness/mod.rs index 01d9bb91..65dbc5a4 100644 --- a/tests/harness/mod.rs +++ b/tests/harness/mod.rs @@ -17,56 +17,22 @@ pub mod suites; pub use self::input::Input; -pub trait TestFixture { +pub trait TestFixture { fn test_cases() -> Vec; fn run(test: &T); -} - -macro_rules! create_test { - ($name:expr, $should_panic:expr, $body:tt) => {{ - use rustc_test::{TestDesc, TestDescAndFn, TestFn, TestName}; - - TestDescAndFn { - desc: TestDesc { - name: TestName::DynTestName($name), - ignore: false, - should_panic: $should_panic, - allow_fail: false, - }, - testfn: TestFn::DynTestFn(Box::new(move || $body)), + fn run_tests() { + for test in Self::test_cases() { + let d = DumpOnPanic(&test); + Self::run(&test); + std::mem::forget(d); } - }}; + } } -macro_rules! test_fixture { - ($fixture:ident) => { - use rustc_test::{ShouldPanic, TestDescAndFn}; - - pub fn get_tests() -> Vec { - $fixture::test_cases() - .into_iter() - .map(|t| { - create_test!(t.description.to_owned(), ShouldPanic::No, { - $fixture::run(&t); - }) - }) - .collect() - } - }; +struct DumpOnPanic<'a, T: std::fmt::Debug>(&'a T); +impl Drop for DumpOnPanic<'_, T> { + fn drop(&mut self) { + eprintln!("test case failed: {:?}", self.0); + } } -macro_rules! test_modules { - ($($m:ident),+) => { - $(mod $m;)+ - - use rustc_test::TestDescAndFn; - - pub fn get_tests() -> Vec { - let mut tests = Vec::default(); - - $(tests.extend($m::get_tests());)+ - - tests - } - }; -} diff --git a/tests/harness/suites/html5lib_tests/mod.rs b/tests/harness/suites/html5lib_tests/mod.rs index 2ab75a35..b7181f6d 100644 --- a/tests/harness/suites/html5lib_tests/mod.rs +++ b/tests/harness/suites/html5lib_tests/mod.rs @@ -24,7 +24,7 @@ pub struct Bailout { pub parsed_chunk: String, } -#[derive(Deserialize, Clone)] +#[derive(Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct TestCase { pub description: String, diff --git a/tests/harness/suites/selectors_tests.rs b/tests/harness/suites/selectors_tests.rs index 76cc3213..6baed8f0 100644 --- a/tests/harness/suites/selectors_tests.rs +++ b/tests/harness/suites/selectors_tests.rs @@ -24,8 +24,9 @@ struct TestData { pub src: String, } +#[derive(Debug)] pub struct TestCase { - pub description: String, + pub _description: String, pub selector: String, pub input: Input, pub expected: String, @@ -65,7 +66,7 @@ pub fn get_test_cases(suite: &'static str) -> Vec { } test_cases.push(TestCase { - description, + _description: description, selector: selector.clone(), input, expected: read_test_file(suite, &expected_file), diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 576ecd09..9c7b71aa 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,27 +1,10 @@ -use cfg_if::cfg_if; +#![cfg(feature = "integration_test")] -cfg_if! { - if #[cfg(feature="integration_test")] { - #[macro_use] - mod harness; +#[macro_use] +mod harness; - mod fixtures; - - use self::fixtures::get_tests; - use rustc_test::test_main; - - fn main() { - let args: Vec<_> = ::std::env::args().collect(); - - test_main(&args, get_tests()); - } - } else { - fn main() { - println!(concat![ - "Integration tests will not run. ", - "To run integration tests either run `./scripts/test.sh` ", - "or pass `--features=integration_test` flag to `cargo test`." - ]); - } - } +mod fixtures { + mod token_capturing; + mod selector_matching; + mod element_content_replacement; }