Skip to content

Commit

Permalink
Migrate run-make/rustdoc-verify-output-files to rmake.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 25, 2024
1 parent ee60406 commit ae57ec7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ run-make/rlib-format-packed-bundled-libs/Makefile
run-make/rmeta-preferred/Makefile
run-make/rustc-macro-dep-files/Makefile
run-make/rustdoc-io-error/Makefile
run-make/rustdoc-verify-output-files/Makefile
run-make/sanitizer-cdylib-link/Makefile
run-make/sanitizer-dylib-link/Makefile
run-make/sanitizer-staticlib-link/Makefile
Expand Down
32 changes: 0 additions & 32 deletions tests/run-make/rustdoc-verify-output-files/Makefile

This file was deleted.

67 changes: 67 additions & 0 deletions tests/run-make/rustdoc-verify-output-files/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use std::fs::{copy, read, read_dir};
use std::path::{Path, PathBuf};

use run_make_support::{copy_dir_all, rustdoc, tmp_dir};

fn generate_docs(out_dir: &Path, json_output: bool) {
let mut rustdoc = rustdoc();
rustdoc.input("src/lib.rs").crate_name("foobar").crate_type("lib").out_dir(&out_dir);
if json_output {
rustdoc.arg("-Zunstable-options").output_format("json");
}
rustdoc.run();
}

fn read_file(path: PathBuf) -> Vec<u8> {
match read(&path) {
Ok(c) => c,
Err(e) => panic!("Failed to read `{}`: {:?}", path.display(), e),
}
}

fn recursive_diff(dir1: &Path, dir2: &Path) {
for entry in read_dir(dir1).unwrap() {
let entry = entry.unwrap();
let entry_name = entry.file_name();
let path = entry.path();

if path.is_dir() {
recursive_diff(&path, &dir2.join(entry_name));
} else {
let file1 = read_file(path);
let file2 = read_file(dir2.join(entry_name));

assert!(file1 == file2);
}
}
}

fn main() {
let out_dir = tmp_dir().join("rustdoc");
let tmp_out_dir = tmp_dir().join("tmp-rustdoc");

// Generate HTML docs.
generate_docs(&out_dir, false);

// Copy first output for to check if it's exactly same after second compilation.
copy_dir_all(&out_dir, &tmp_out_dir).unwrap();

// Generate html docs once again on same output.
generate_docs(&out_dir, false);

// Generate json doc on the same output.
generate_docs(&out_dir, true);

// Check if expected json file is generated.
assert!(out_dir.join("foobar.json").is_file());

// Copy first json output to check if it's exactly same after second compilation.
copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json")).unwrap();

// Generate json doc on the same output.
generate_docs(&out_dir, true);

// Check if all docs(including both json and html formats) are still the same after multiple
// compilations.
recursive_diff(&out_dir, &tmp_out_dir);
}

0 comments on commit ae57ec7

Please sign in to comment.