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

Rip out rustc-test #252

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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;
}
Loading