|
| 1 | +use std::fs::copy; |
| 2 | +use std::path::{Path, PathBuf}; |
| 3 | + |
| 4 | +use run_make_support::{copy_dir_all, recursive_diff, rustdoc, tmp_dir}; |
| 5 | + |
| 6 | +#[derive(PartialEq)] |
| 7 | +enum JsonOutput { |
| 8 | + Yes, |
| 9 | + No, |
| 10 | +} |
| 11 | + |
| 12 | +fn generate_docs(out_dir: &Path, json_output: JsonOutput) { |
| 13 | + let mut rustdoc = rustdoc(); |
| 14 | + rustdoc.input("src/lib.rs").crate_name("foobar").crate_type("lib").out_dir(&out_dir); |
| 15 | + if json_output == JsonOutput::Yes { |
| 16 | + rustdoc.arg("-Zunstable-options").output_format("json"); |
| 17 | + } |
| 18 | + rustdoc.run(); |
| 19 | +} |
| 20 | + |
| 21 | +fn main() { |
| 22 | + let out_dir = tmp_dir().join("rustdoc"); |
| 23 | + let tmp_out_dir = tmp_dir().join("tmp-rustdoc"); |
| 24 | + |
| 25 | + // Generate HTML docs. |
| 26 | + generate_docs(&out_dir, JsonOutput::No); |
| 27 | + |
| 28 | + // Copy first output for to check if it's exactly same after second compilation. |
| 29 | + copy_dir_all(&out_dir, &tmp_out_dir); |
| 30 | + |
| 31 | + // Generate html docs once again on same output. |
| 32 | + generate_docs(&out_dir, JsonOutput::No); |
| 33 | + |
| 34 | + // Generate json doc on the same output. |
| 35 | + generate_docs(&out_dir, JsonOutput::Yes); |
| 36 | + |
| 37 | + // Check if expected json file is generated. |
| 38 | + assert!(out_dir.join("foobar.json").is_file()); |
| 39 | + |
| 40 | + // Copy first json output to check if it's exactly same after second compilation. |
| 41 | + copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json")).unwrap(); |
| 42 | + |
| 43 | + // Generate json doc on the same output. |
| 44 | + generate_docs(&out_dir, JsonOutput::Yes); |
| 45 | + |
| 46 | + // Check if all docs(including both json and html formats) are still the same after multiple |
| 47 | + // compilations. |
| 48 | + recursive_diff(&out_dir, &tmp_out_dir); |
| 49 | +} |
0 commit comments