Add warnings when rustdoc html rendering differs

This commit is contained in:
Guillaume Gomez 2017-05-14 15:14:02 +02:00
parent 93cdf5e3c4
commit 274543b9ca
5 changed files with 1765 additions and 3 deletions

1726
src/Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -13,6 +13,9 @@ env_logger = { version = "0.4", default-features = false }
log = "0.3"
pulldown-cmark = { version = "0.0.14", default-features = false }
[target.'cfg(not(stage0))'.dependencies]
html-diff = "0.0.2"
[build-dependencies]
build_helper = { path = "../build_helper" }
gcc = "0.3.50"

@ -75,6 +75,9 @@ use html::item_type::ItemType;
use html::markdown::{self, Markdown, MarkdownHtml, MarkdownSummaryLine, RenderType};
use html::{highlight, layout};
#[cfg(not(stage0))]
use html_diff;
/// A pair of name and its optional document.
pub type NameDoc = (String, Option<String>);
@ -1645,6 +1648,34 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re
Ok(())
}
#[cfg(not(stage0))]
fn get_html_diff(w: &mut fmt::Formatter, md_text: &str, render_type: RenderType,
prefix: &str) -> fmt::Result {
if render_type == RenderType::Pulldown {
let output = format!("{}", Markdown(md_text, render_type));
let old = format!("{}", Markdown(md_text, RenderType::Hoedown));
let differences = html_diff::get_differences(&output, &old);
if !differences.is_empty() {
println!("Differences spotted in {:?}:\n{}",
md_text,
differences.iter()
.map(|s| format!("=> {}", s.to_string()))
.collect::<Vec<String>>()
.join("\n"));
}
write!(w, "<div class='docblock'>{}{}</div>", prefix, output)
} else {
write!(w, "<div class='docblock'>{}{}</div>",
prefix,
Markdown(md_text, render_type))
}
}
#[cfg(stage0)]
fn get_html_diff(w: &mut fmt::Formatter, md_text: &str, render_type: RenderType) -> fmt::Result {
write!(w, "<div class='docblock'>{}</div>", Markdown(md_text, render_type))
}
fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLink,
render_type: RenderType, prefix: &str) -> fmt::Result {
if let Some(s) = item.doc_value() {
@ -1654,7 +1685,7 @@ fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLin
} else {
format!("{}", &plain_summary_line(Some(s)))
};
write!(w, "<div class='docblock'>{}{}</div>", prefix, Markdown(&markdown, render_type))?;
get_html_diff(&markdown, render_type, prefix)?;
} else if !prefix.is_empty() {
write!(w, "<div class='docblock'>{}</div>", prefix)?;
}
@ -1678,7 +1709,7 @@ fn render_assoc_const_value(item: &clean::Item) -> String {
fn document_full(w: &mut fmt::Formatter, item: &clean::Item,
render_type: RenderType, prefix: &str) -> fmt::Result {
if let Some(s) = item.doc_value() {
write!(w, "<div class='docblock'>{}{}</div>", prefix, Markdown(s, render_type))?;
get_html_diff(format!("{}{}", md_render_assoc_item(item), s), render_type, prefix)?;
} else if !prefix.is_empty() {
write!(w, "<div class='docblock'>{}</div>", prefix)?;
}

@ -28,6 +28,8 @@
extern crate arena;
extern crate getopts;
extern crate env_logger;
#[cfg(not(stage0))]
extern crate html_diff;
extern crate libc;
extern crate rustc;
extern crate rustc_data_structures;

@ -15,7 +15,7 @@
// @has issue_12834/fn.foo.html
// @has - //pre 'a + b '
/// ```
/// ```text
/// a + b ∈ Self ∀ a, b ∈ Self
/// ```
pub fn foo() {}