Skip to content

Commit 02ead11

Browse files
authored
Unrolled build for rust-lang#129149
Rollup merge of rust-lang#129149 - GuillaumeGomez:migrate-python-script, r=jieyouxu Migrate `validate_json.py` script to rust in `run-make/rustdoc-map-file` test This PR fixes the FIXME I added for future-me who become present-me. :') Since there are multiple `run-make` tests using python scripts, I suppose more of them will migrate to Rust, hence why I added the `jzon` public reexport to the `run-make-support` crate. cc `@jieyouxu` r? `@Kobzol`
2 parents 569d7e3 + 6b1637c commit 02ead11

File tree

5 files changed

+47
-44
lines changed

5 files changed

+47
-44
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,7 @@ dependencies = [
31493149
"gimli 0.31.0",
31503150
"object 0.36.2",
31513151
"regex",
3152+
"serde_json",
31523153
"similar",
31533154
"wasmparser 0.214.0",
31543155
]

src/tools/run-make-support/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ wasmparser = { version = "0.214", default-features = false, features = ["std"] }
1111
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
1212
gimli = "0.31.0"
1313
build_helper = { path = "../build_helper" }
14+
serde_json = "1.0"

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.
+44-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,54 @@
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};
28

39
fn main() {
410
let out_dir = "out";
11+
let crate_name = "foo";
512
rustdoc()
613
.input("foo.rs")
14+
.crate_name(crate_name)
715
.arg("-Zunstable-options")
816
.arg("--generate-redirect-map")
917
.out_dir(&out_dir)
1018
.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+
}
1354
}

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

-41
This file was deleted.

0 commit comments

Comments
 (0)