Skip to content

Migrate validate_json.py script to rust in run-make/rustdoc-map-file test #129149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3149,6 +3149,7 @@ dependencies = [
"gimli 0.31.0",
"object 0.36.2",
"regex",
"serde_json",
"similar",
"wasmparser 0.214.0",
]
Expand Down
1 change: 1 addition & 0 deletions src/tools/run-make-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ wasmparser = { version = "0.214", default-features = false, features = ["std"] }
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
gimli = "0.31.0"
build_helper = { path = "../build_helper" }
serde_json = "1.0"
1 change: 1 addition & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub use bstr;
pub use gimli;
pub use object;
pub use regex;
pub use serde_json;
pub use wasmparser;

// Re-exports of external dependencies.
Expand Down
47 changes: 44 additions & 3 deletions tests/run-make/rustdoc-map-file/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
use run_make_support::{python_command, rustdoc};
// 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;

use run_make_support::rfs::read_to_string;
use run_make_support::{path, rustdoc, serde_json};

fn main() {
let out_dir = "out";
let crate_name = "foo";
rustdoc()
.input("foo.rs")
.crate_name(crate_name)
.arg("-Zunstable-options")
.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 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();

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:?}`"
));
}
}
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}`"));
}
}

if !differences.is_empty() {
eprintln!("Found differences in JSON files:");
for diff in differences {
eprintln!("=> {diff}");
}
panic!("Found differences in JSON files");
}
}
41 changes: 0 additions & 41 deletions tests/run-make/rustdoc-map-file/validate_json.py

This file was deleted.

Loading