Skip to content

Commit 45137fc

Browse files
Migrate run-make/rustdoc-verify-output-files to rmake.rs
1 parent ee60406 commit 45137fc

File tree

3 files changed

+73
-33
lines changed

3 files changed

+73
-33
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ run-make/rlib-format-packed-bundled-libs/Makefile
227227
run-make/rmeta-preferred/Makefile
228228
run-make/rustc-macro-dep-files/Makefile
229229
run-make/rustdoc-io-error/Makefile
230-
run-make/rustdoc-verify-output-files/Makefile
231230
run-make/sanitizer-cdylib-link/Makefile
232231
run-make/sanitizer-dylib-link/Makefile
233232
run-make/sanitizer-staticlib-link/Makefile

tests/run-make/rustdoc-verify-output-files/Makefile

-32
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use std::fs::{copy, read, read_dir};
2+
use std::path::{Path, PathBuf};
3+
4+
use run_make_support::{copy_dir_all, rustdoc, tmp_dir};
5+
6+
fn generate_docs(out_dir: &Path, json_output: bool) {
7+
let mut rustdoc = rustdoc();
8+
rustdoc
9+
.input("src/lib.rs")
10+
.crate_name("foobar")
11+
.crate_type("lib")
12+
.out_dir(&out_dir);
13+
if json_output {
14+
rustdoc
15+
.arg("-Zunstable-options")
16+
.output_format("json");
17+
}
18+
rustdoc.run();
19+
}
20+
21+
fn read_file(path: PathBuf) -> Vec<u8> {
22+
match read(&path) {
23+
Ok(c) => c,
24+
Err(e) => panic!("Failed to read `{}`: {:?}", path.display(), e),
25+
}
26+
}
27+
28+
fn recursive_diff(dir1: &Path, dir2: &Path) {
29+
for entry in read_dir(dir1).unwrap() {
30+
let entry = entry.unwrap();
31+
let entry_name = entry.file_name();
32+
let path = entry.path();
33+
34+
if path.is_dir() {
35+
recursive_diff(&path, &dir2.join(entry_name));
36+
} else {
37+
let file1 = read_file(path);
38+
let file2 = read_file(dir2.join(entry_name));
39+
40+
assert!(file1 == file2);
41+
}
42+
}
43+
}
44+
45+
fn main() {
46+
let out_dir = tmp_dir().join("rustdoc");
47+
let tmp_out_dir = tmp_dir().join("tmp-rustdoc");
48+
49+
// Generate HTML docs.
50+
generate_docs(&out_dir, false);
51+
52+
// Copy first output for to check if it's exactly same after second compilation.
53+
copy_dir_all(&out_dir, &tmp_out_dir).unwrap();
54+
55+
// Generate html docs once again on same output.
56+
generate_docs(&out_dir, false);
57+
58+
// Generate json doc on the same output.
59+
generate_docs(&out_dir, true);
60+
61+
// Check if expected json file is generated.
62+
assert!(out_dir.join("foobar.json").is_file());
63+
64+
// Copy first json output to check if it's exactly same after second compilation.
65+
copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json")).unwrap();
66+
67+
// Generate json doc on the same output.
68+
generate_docs(&out_dir, true);
69+
70+
// Check if all docs(including both json and html formats) are still the same after multiple
71+
// compilations.
72+
recursive_diff(&out_dir, &tmp_out_dir);
73+
}

0 commit comments

Comments
 (0)