Add full test for rustdoc map file

This commit is contained in:
Guillaume Gomez 2021-02-15 21:45:38 +01:00
parent 2b59e7667d
commit 1a7126b30b
4 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,5 @@
-include ../tools.mk
all:
$(RUSTDOC) -Z unstable-options --generate-redirect-map foo.rs -o "$(TMPDIR)/out"
"$(PYTHON)" validate_json.py "$(TMPDIR)/out"

View File

@ -0,0 +1,5 @@
{
"foo/macro.foo!.html": "foo/macro.foo.html",
"foo/private/struct.Quz.html": "foo/struct.Quz.html",
"foo/hidden/struct.Bar.html": "foo/struct.Bar.html"
}

View File

@ -0,0 +1,16 @@
pub use private::Quz;
pub use hidden::Bar;
mod private {
pub struct Quz;
}
#[doc(hidden)]
pub mod hidden {
pub struct Bar;
}
#[macro_export]
macro_rules! foo {
() => {}
}

View File

@ -0,0 +1,41 @@
#!/usr/bin/env python
import os
import sys
import json
def find_redirect_map_file(folder, errors):
for root, dirs, files in os.walk(folder):
for name in files:
if not name.endswith("redirect-map.json"):
continue
with open(os.path.join(root, name)) as f:
data = json.load(f)
with open("expected.json") as f:
expected = json.load(f)
for key in expected:
if expected[key] != data.get(key):
errors.append("Expected `{}` for key `{}`, found: `{}`".format(
expected[key], key, data.get(key)))
else:
del data[key]
for key in data:
errors.append("Extra data not expected: key: `{}`, data: `{}`".format(
key, data[key]))
return True
return False
if len(sys.argv) != 2:
print("Expected doc directory to check!")
sys.exit(1)
errors = []
if not find_redirect_map_file(sys.argv[1], errors):
print("Didn't find the map file in `{}`...".format(sys.argv[1]))
sys.exit(1)
for err in errors:
print("=> {}".format(err))
if len(errors) != 0:
sys.exit(1)