Skip to content

Commit 1a7126b

Browse files
Add full test for rustdoc map file
1 parent 2b59e76 commit 1a7126b

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTDOC) -Z unstable-options --generate-redirect-map foo.rs -o "$(TMPDIR)/out"
5+
"$(PYTHON)" validate_json.py "$(TMPDIR)/out"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"foo/macro.foo!.html": "foo/macro.foo.html",
3+
"foo/private/struct.Quz.html": "foo/struct.Quz.html",
4+
"foo/hidden/struct.Bar.html": "foo/struct.Bar.html"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub use private::Quz;
2+
pub use hidden::Bar;
3+
4+
mod private {
5+
pub struct Quz;
6+
}
7+
8+
#[doc(hidden)]
9+
pub mod hidden {
10+
pub struct Bar;
11+
}
12+
13+
#[macro_export]
14+
macro_rules! foo {
15+
() => {}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import sys
5+
import json
6+
7+
8+
def find_redirect_map_file(folder, errors):
9+
for root, dirs, files in os.walk(folder):
10+
for name in files:
11+
if not name.endswith("redirect-map.json"):
12+
continue
13+
with open(os.path.join(root, name)) as f:
14+
data = json.load(f)
15+
with open("expected.json") as f:
16+
expected = json.load(f)
17+
for key in expected:
18+
if expected[key] != data.get(key):
19+
errors.append("Expected `{}` for key `{}`, found: `{}`".format(
20+
expected[key], key, data.get(key)))
21+
else:
22+
del data[key]
23+
for key in data:
24+
errors.append("Extra data not expected: key: `{}`, data: `{}`".format(
25+
key, data[key]))
26+
return True
27+
return False
28+
29+
30+
if len(sys.argv) != 2:
31+
print("Expected doc directory to check!")
32+
sys.exit(1)
33+
34+
errors = []
35+
if not find_redirect_map_file(sys.argv[1], errors):
36+
print("Didn't find the map file in `{}`...".format(sys.argv[1]))
37+
sys.exit(1)
38+
for err in errors:
39+
print("=> {}".format(err))
40+
if len(errors) != 0:
41+
sys.exit(1)

0 commit comments

Comments
 (0)