|
1 |
| -use run_make_support::{python_command, rustdoc}; |
| 1 | +// This test ensures that all items from `foo` are correctly generated into the `redirect-map.json` |
| 2 | +// file with `--generate-redirect-map` rustdoc option. |
| 3 | + |
| 4 | +use std::path::Path; |
| 5 | + |
| 6 | +use run_make_support::rfs::read_to_string; |
| 7 | +use run_make_support::{path, rustdoc, serde_json}; |
2 | 8 |
|
3 | 9 | fn main() {
|
4 | 10 | let out_dir = "out";
|
| 11 | + let crate_name = "foo"; |
5 | 12 | rustdoc()
|
6 | 13 | .input("foo.rs")
|
| 14 | + .crate_name(crate_name) |
7 | 15 | .arg("-Zunstable-options")
|
8 | 16 | .arg("--generate-redirect-map")
|
9 | 17 | .out_dir(&out_dir)
|
10 | 18 | .run();
|
11 |
| - // FIXME (GuillaumeGomez): Port the python script to Rust as well. |
12 |
| - python_command().arg("validate_json.py").arg(&out_dir).run(); |
| 19 | + |
| 20 | + let generated = read_to_string(path(out_dir).join(crate_name).join("redirect-map.json")); |
| 21 | + let expected = read_to_string("expected.json"); |
| 22 | + let generated: serde_json::Value = |
| 23 | + serde_json::from_str(&generated).expect("failed to parse JSON"); |
| 24 | + let expected: serde_json::Value = |
| 25 | + serde_json::from_str(&expected).expect("failed to parse JSON"); |
| 26 | + let expected = expected.as_object().unwrap(); |
| 27 | + |
| 28 | + let mut differences = Vec::new(); |
| 29 | + for (key, expected_value) in expected.iter() { |
| 30 | + match generated.get(key) { |
| 31 | + Some(value) => { |
| 32 | + if expected_value != value { |
| 33 | + differences.push(format!( |
| 34 | + "values for key `{key}` don't match: `{expected_value:?}` != `{value:?}`" |
| 35 | + )); |
| 36 | + } |
| 37 | + } |
| 38 | + None => differences.push(format!("missing key `{key}`")), |
| 39 | + } |
| 40 | + } |
| 41 | + for (key, data) in generated.as_object().unwrap().iter() { |
| 42 | + if !expected.contains_key(key) { |
| 43 | + differences.push(format!("Extra data not expected: key: `{key}`, data: `{data}`")); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + if !differences.is_empty() { |
| 48 | + eprintln!("Found differences in JSON files:"); |
| 49 | + for diff in differences { |
| 50 | + eprintln!("=> {diff}"); |
| 51 | + } |
| 52 | + panic!("Found differences in JSON files"); |
| 53 | + } |
13 | 54 | }
|
0 commit comments