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 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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
/.vscode/
/.idea/
Cargo.lock
target
**/*.rs.bk
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
32 changes: 17 additions & 15 deletions tests/fixtures/element_content_replacement.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::harness::suites::selectors_tests::{get_test_cases, TestCase};
use crate::harness::TestFixture;
use lol_html::test_utils::Output;
use lol_html::{HtmlRewriter, Settings, element};
use lol_html::html_content::ContentType;
use lol_html::test_utils::Output;
use lol_html::{element, HtmlRewriter, Settings};

// NOTE: Inner element content replacement functionality used as a basis for
// the multiple element methods and it's easy to get it wrong, so we have
Expand All @@ -19,21 +19,20 @@ impl TestFixture<TestCase> for ElementContentReplacementTests {
let mut output = Output::new(encoding.into());

{
let mut rewriter = HtmlRewriter::new(Settings {
element_content_handlers: vec![
element!(test.selector, |el| {
el.set_inner_content(
&format!("<!--Replaced ({}) -->", test.selector),
ContentType::Html,
);

Ok(())
})
],
let mut rewriter = HtmlRewriter::new(
Settings {
element_content_handlers: vec![element!(test.selector, |el| {
el.set_inner_content(
&format!("<!--Replaced ({}) -->", test.selector),
ContentType::Html,
);

Ok(())
})],
encoding,
..Settings::new()
},
|c: &[u8]| output.push(c)
|c: &[u8]| output.push(c),
);

for chunk in test.input.chunks() {
Expand All @@ -49,4 +48,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.

13 changes: 8 additions & 5 deletions tests/fixtures/selector_matching.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::harness::suites::selectors_tests::{get_test_cases, TestCase};
use crate::harness::TestFixture;
use lol_html::test_utils::Output;
use lol_html::{HtmlRewriter, Settings, element, comments, text};
use lol_html::html_content::ContentType;
use lol_html::test_utils::Output;
use lol_html::{comments, element, text, HtmlRewriter, Settings};

pub struct SelectorMatchingTests;

Expand Down Expand Up @@ -65,12 +65,12 @@ impl TestFixture<TestCase> for SelectorMatchingTests {
}

Ok(())
})
}),
],
encoding,
..Settings::new()
},
|c: &[u8]| output.push(c)
|c: &[u8]| output.push(c),
);

for chunk in test.input.chunks() {
Expand All @@ -86,4 +86,7 @@ impl TestFixture<TestCase> for SelectorMatchingTests {
}
}

test_fixture!(SelectorMatchingTests);
#[test]
fn test_selector_matching() {
SelectorMatchingTests::run_tests();
}
10 changes: 7 additions & 3 deletions tests/fixtures/token_capturing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use lol_html::errors::RewritingError;
use lol_html::html_content::{DocumentEnd, TextType};
use lol_html::test_utils::Output;
use lol_html::{
LocalName, LocalNameHash, SharedMemoryLimiter, Namespace, SharedEncoding, StartTagHandlingResult,
Token, TokenCaptureFlags, TransformController, TransformStream, TransformStreamSettings,
LocalName, LocalNameHash, Namespace, SharedEncoding, SharedMemoryLimiter,
StartTagHandlingResult, Token, TokenCaptureFlags, TransformController, TransformStream,
TransformStreamSettings,
};

macro_rules! expect_eql {
Expand Down Expand Up @@ -258,4 +259,7 @@ impl TestFixture<TestCase> for TokenCapturingTests {
}
}

test_fixture!(TokenCapturingTests);
#[test]
fn test_token_capturing() {
TokenCapturingTests::run_tests();
}
59 changes: 12 additions & 47 deletions tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,21 @@ 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)),
}
}};
}

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()
fn run_tests() {
for test in Self::test_cases() {
let d = DumpOnPanic(&test);
Self::run(&test);
std::mem::forget(d);
}
};
}
}

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
}
};
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);
}
}
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 element_content_replacement;
mod selector_matching;
mod token_capturing;
}
Loading