Skip to content

Commit 26b325b

Browse files
Migrate validate_json.py script to rust in run-make/rustdoc-map-file test
1 parent d626fbd commit 26b325b

File tree

3 files changed

+48
-44
lines changed

3 files changed

+48
-44
lines changed

src/tools/run-make-support/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub use bstr;
3838
pub use gimli;
3939
pub use object;
4040
pub use regex;
41+
pub use serde_json;
4142
pub use wasmparser;
4243

4344
// Re-exports of external dependencies.
+47-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use run_make_support::{python_command, rustdoc};
1+
use run_make_support::path_helpers::read_dir_entries_recursive;
2+
use run_make_support::rfs::read_to_string;
3+
use run_make_support::{jzon, rustdoc};
24

35
fn main() {
46
let out_dir = "out";
@@ -8,6 +10,48 @@ fn main() {
810
.arg("--generate-redirect-map")
911
.out_dir(&out_dir)
1012
.run();
11-
// FIXME (GuillaumeGomez): Port the python script to Rust as well.
12-
python_command().arg("validate_json.py").arg(&out_dir).run();
13+
14+
let mut found_file = false;
15+
read_dir_entries_recursive(&out_dir, |path| {
16+
if !found_file
17+
&& path.is_file()
18+
&& path.file_name().map(|name| name == "redirect-map.json").unwrap_or(false)
19+
{
20+
found_file = true;
21+
let generated = read_to_string(path);
22+
let expected = read_to_string("expected.json");
23+
let generated = jzon::parse(&generated).expect("failed to parse JSON");
24+
let expected = jzon::parse(&expected).expect("failed to parse JSON");
25+
26+
let mut differences = Vec::new();
27+
for (key, expected_value) in expected.entries() {
28+
match generated.get(key) {
29+
Some(value) => {
30+
if expected_value != value {
31+
differences.push(format!("values for key `{key}` don't match"));
32+
}
33+
}
34+
None => differences.push(format!("missing key `{key}`")),
35+
}
36+
}
37+
for (key, data) in generated.entries() {
38+
if !expected.has_key(key) {
39+
differences
40+
.push(format!("Extra data not expected: key: `{key}`, data: `{data}`"));
41+
}
42+
}
43+
44+
if !differences.is_empty() {
45+
eprintln!("Found differences in JSON files:");
46+
for diff in differences {
47+
eprintln!("=> {diff}");
48+
}
49+
std::process::exit(1);
50+
}
51+
}
52+
});
53+
54+
if !found_file {
55+
panic!("`redirect-map.json` file was not found");
56+
}
1357
}

tests/run-make/rustdoc-map-file/validate_json.py

-41
This file was deleted.

0 commit comments

Comments
 (0)