2024-08-16 08:09:04 -05:00
|
|
|
// This test ensures that all items from `foo` are correctly generated into the `redirect-map.json`
|
|
|
|
// file with `--generate-redirect-map` rustdoc option.
|
|
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
2024-08-16 05:19:39 -05:00
|
|
|
use run_make_support::rfs::read_to_string;
|
2024-08-16 08:09:04 -05:00
|
|
|
use run_make_support::{path, rustdoc, serde_json};
|
2024-05-07 03:31:58 -05:00
|
|
|
|
|
|
|
fn main() {
|
2024-06-06 14:34:34 -05:00
|
|
|
let out_dir = "out";
|
2024-08-16 08:09:04 -05:00
|
|
|
let crate_name = "foo";
|
2024-05-07 03:31:58 -05:00
|
|
|
rustdoc()
|
|
|
|
.input("foo.rs")
|
2024-08-16 08:09:04 -05:00
|
|
|
.crate_name(crate_name)
|
2024-05-07 03:31:58 -05:00
|
|
|
.arg("-Zunstable-options")
|
|
|
|
.arg("--generate-redirect-map")
|
2024-08-15 07:44:48 -05:00
|
|
|
.out_dir(&out_dir)
|
2024-05-07 03:31:58 -05:00
|
|
|
.run();
|
2024-08-16 05:19:39 -05:00
|
|
|
|
2024-08-16 08:09:04 -05:00
|
|
|
let generated = read_to_string(path(out_dir).join(crate_name).join("redirect-map.json"));
|
|
|
|
let expected = read_to_string("expected.json");
|
|
|
|
let generated: serde_json::Value =
|
|
|
|
serde_json::from_str(&generated).expect("failed to parse JSON");
|
|
|
|
let expected: serde_json::Value =
|
|
|
|
serde_json::from_str(&expected).expect("failed to parse JSON");
|
|
|
|
let expected = expected.as_object().unwrap();
|
2024-08-16 05:19:39 -05:00
|
|
|
|
2024-08-16 08:09:04 -05:00
|
|
|
let mut differences = Vec::new();
|
|
|
|
for (key, expected_value) in expected.iter() {
|
|
|
|
match generated.get(key) {
|
|
|
|
Some(value) => {
|
|
|
|
if expected_value != value {
|
|
|
|
differences.push(format!(
|
|
|
|
"values for key `{key}` don't match: `{expected_value:?}` != `{value:?}`"
|
|
|
|
));
|
2024-08-16 05:19:39 -05:00
|
|
|
}
|
|
|
|
}
|
2024-08-16 08:09:04 -05:00
|
|
|
None => differences.push(format!("missing key `{key}`")),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (key, data) in generated.as_object().unwrap().iter() {
|
|
|
|
if !expected.contains_key(key) {
|
|
|
|
differences.push(format!("Extra data not expected: key: `{key}`, data: `{data}`"));
|
2024-08-16 05:19:39 -05:00
|
|
|
}
|
2024-08-16 08:09:04 -05:00
|
|
|
}
|
2024-08-16 05:19:39 -05:00
|
|
|
|
2024-08-16 08:09:04 -05:00
|
|
|
if !differences.is_empty() {
|
|
|
|
eprintln!("Found differences in JSON files:");
|
|
|
|
for diff in differences {
|
|
|
|
eprintln!("=> {diff}");
|
|
|
|
}
|
|
|
|
panic!("Found differences in JSON files");
|
2024-08-16 05:19:39 -05:00
|
|
|
}
|
2024-05-07 03:31:58 -05:00
|
|
|
}
|