2024-08-12 07:20:21 -05:00
|
|
|
// This test verifies that rustdoc `-o -` prints JSON on stdout and doesn't generate
|
|
|
|
// a JSON file.
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use run_make_support::path_helpers::{cwd, has_extension, read_dir_entries_recursive};
|
2024-08-31 17:08:38 -05:00
|
|
|
use run_make_support::{rustdoc, serde_json};
|
2024-08-12 07:20:21 -05:00
|
|
|
|
|
|
|
fn main() {
|
2024-08-31 17:08:38 -05:00
|
|
|
let json_string = rustdoc()
|
2024-08-12 07:20:21 -05:00
|
|
|
.input("foo.rs")
|
2024-08-15 07:44:48 -05:00
|
|
|
.out_dir("-")
|
2024-08-12 07:20:21 -05:00
|
|
|
.arg("-Zunstable-options")
|
|
|
|
.output_format("json")
|
|
|
|
.run()
|
2024-08-31 17:08:38 -05:00
|
|
|
.stdout_utf8();
|
|
|
|
|
|
|
|
// First we check that we generate the JSON in the stdout.
|
|
|
|
let json_value: serde_json::Value =
|
|
|
|
serde_json::from_str(&json_string).expect("stdout should be valid json");
|
|
|
|
|
|
|
|
// We don't care to test the specifics of the JSON, as that's done
|
|
|
|
// elsewhere, just check that it has a format_version (as all JSON output
|
|
|
|
// should).
|
|
|
|
let format_version = json_value["format_version"]
|
|
|
|
.as_i64()
|
|
|
|
.expect("json output should contain format_version field");
|
|
|
|
assert!(format_version > 30);
|
2024-08-12 07:20:21 -05:00
|
|
|
|
|
|
|
// Then we check it didn't generate any JSON file.
|
|
|
|
read_dir_entries_recursive(cwd(), |path| {
|
|
|
|
if path.is_file() && has_extension(path, "json") {
|
|
|
|
panic!("Found a JSON file {path:?}");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|