Skip to content

Commit

Permalink
Migrate validate_json.py script to rust in `run-make/rustdoc-map-fi…
Browse files Browse the repository at this point in the history
…le` test
  • Loading branch information
GuillaumeGomez committed Aug 16, 2024
1 parent 54468b2 commit ec7e0ea
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 44 deletions.
50 changes: 47 additions & 3 deletions tests/run-make/rustdoc-map-file/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use run_make_support::{python_command, rustdoc};
use run_make_support::path_helpers::read_dir_entries_recursive;
use run_make_support::rfs::read_to_string;
use run_make_support::{jzon, rustdoc};

fn main() {
let out_dir = "out";
Expand All @@ -8,6 +10,48 @@ fn main() {
.arg("--generate-redirect-map")
.out_dir(&out_dir)
.run();
// FIXME (GuillaumeGomez): Port the python script to Rust as well.
python_command().arg("validate_json.py").arg(&out_dir).run();

let mut found_file = false;
read_dir_entries_recursive(&out_dir, |path| {
if !found_file
&& path.is_file()
&& path.file_name().map(|name| name == "redirect-map.json").unwrap_or(false)
{
found_file = true;
let generated = read_to_string(path);
let expected = read_to_string("expected.json");
let generated = jzon::parse(&generated).expect("failed to parse JSON");
let expected = jzon::parse(&expected).expect("failed to parse JSON");

let mut differences = Vec::new();
for (key, expected_value) in expected.entries() {
match generated.get(key) {
Some(value) => {
if expected_value != value {
differences.push(format!("values for key `{key}` don't match"));
}
}
None => differences.push(format!("missing key `{key}`")),
}
}
for (key, data) in generated.entries() {
if !expected.has_key(key) {
differences
.push(format!("Extra data not expected: key: `{key}`, data: `{data}`"));
}
}

if !differences.is_empty() {
eprintln!("Found differences in JSON files:");
for diff in differences {
eprintln!("=> {diff}");
}
std::process::exit(1);
}
}
});

if !found_file {
panic!("`redirect-map.json` file was not found");
}
}
41 changes: 0 additions & 41 deletions tests/run-make/rustdoc-map-file/validate_json.py

This file was deleted.

0 comments on commit ec7e0ea

Please sign in to comment.