Skip to content

Commit

Permalink
Rip out rustc-test
Browse files Browse the repository at this point in the history
Fixes #251
  • Loading branch information
kornelski committed Dec 22, 2024
1 parent 33ab3b8 commit 00aa03b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 87 deletions.
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -23,10 +22,6 @@ debug_trace = []
# Unstable: for internal use only
integration_test = []

[[test]]
harness = false
name = "integration_tests"

[[bench]]
harness = false
name = "bench"
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures/element_content_replacement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ impl TestFixture<TestCase> for ElementContentReplacementTests {
}
}

test_fixture!(ElementContentReplacementTests);
#[test]
fn test_element_content_replacement() {
ElementContentReplacementTests::run_tests();
}
5 changes: 0 additions & 5 deletions tests/fixtures/mod.rs

This file was deleted.

5 changes: 4 additions & 1 deletion tests/fixtures/selector_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ impl TestFixture<TestCase> for SelectorMatchingTests {
}
}

test_fixture!(SelectorMatchingTests);
#[test]
fn test_selector_matching() {
SelectorMatchingTests::run_tests();
}
5 changes: 4 additions & 1 deletion tests/fixtures/token_capturing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,7 @@ impl TestFixture<TestCase> for TokenCapturingTests {
}
}

test_fixture!(TokenCapturingTests);
#[test]
fn test_token_capturing() {
TokenCapturingTests::run_tests();
}
58 changes: 12 additions & 46 deletions tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,22 @@ pub mod suites;

pub use self::input::Input;

pub trait TestFixture<T> {
pub trait TestFixture<T: std::fmt::Debug> {
fn test_cases() -> Vec<T>;
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<TestDescAndFn> {
$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<T: std::fmt::Debug> 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<TestDescAndFn> {
let mut tests = Vec::default();

$(tests.extend($m::get_tests());)+

tests
}
};
}
2 changes: 1 addition & 1 deletion tests/harness/suites/html5lib_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions tests/harness/suites/selectors_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,7 +66,7 @@ pub fn get_test_cases(suite: &'static str) -> Vec<TestCase> {
}

test_cases.push(TestCase {
description,
_description: description,
selector: selector.clone(),
input,
expected: read_test_file(suite, &expected_file),
Expand Down
31 changes: 7 additions & 24 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 00aa03b

Please sign in to comment.