tests: load JSON fixtures at runtime for crates.io archives - #444
tests: load JSON fixtures at runtime for crates.io archives#444rome-xi wants to merge 6 commits into
Conversation
|
Please run cargo fmt so CI is happy, looks good with that :) |
emilio
left a comment
There was a problem hiding this comment.
(Ticking request changes so I notice when it gets updated)
Signed-off-by: rome-xi <rome-xi@users.noreply.github.com>
Co-authored-by: rome-xi <rome-xi@users.noreply.github.com>
c811ec6 to
07c058c
Compare
Miri cannot open() css-parsing-tests files (they stay excluded from the crates.io package, so include_str! is not an option). Signed-off-by: rome-xi <2685138823@qq.com>
emilio
left a comment
There was a problem hiding this comment.
Hmm, I don't think ignoring them in miri is good... can we keep the include_str! in miri instead?
Miri isolation cannot open() excluded fixtures; embed them under cfg(miri) while non-miri still loads at runtime for crates.io archives. Signed-off-by: rome-xi <2685138823@qq.com>
Thanks — updated so miri still uses include_str! for the JSON fixtures, while non-miri keeps runtime load for crates.io archives. Dropped the miri ignores on those tests. |
| "stylesheet_bytes.json" => include_str!("css-parsing-tests/stylesheet_bytes.json"), | ||
| "An+B.json" => include_str!("css-parsing-tests/An+B.json"), | ||
| "urange.json" => include_str!("css-parsing-tests/urange.json"), | ||
| other => panic!("unknown css-parsing-tests fixture: {other}"), |
There was a problem hiding this comment.
This seems unfortunate, let's just make it a macro like:
macro_rules! css_parsing_test_json {
($path:tt) {
#[cfg(miri)]
String::from(include_str!($path))
#[cfg(not(miri))]
std::fs::read_to_string(&format!("{}/src/{}", env!(..), $path)).unwrap()
}
}
Seems like that should work?
There was a problem hiding this comment.
Done — replaced the match helper with css_parsing_test_json! as suggested (miri: include_str!, otherwise fs::read_to_string via CARGO_MANIFEST_DIR). Pushed in 28f5c96.
Per emilio review: replace the match-based miri helper with a css_parsing_test_json! macro so include_str! stays on the miri path without listing every fixture name.
Closes #213.
Replace
include_str!for the CSS parsing JSON fixtures withstd::fs::read_to_stringsocargo testcompiles from the crates.io package (those files are inexclude). Missing fixtures still fail at runtime (no silent green); they can be--skipped when packaging.