From 341eb6d6f5c636575a42a5d3d75739755c17aade Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 4 Nov 2020 17:37:46 -0500 Subject: [PATCH 1/8] Give a better error when rustdoc tests fail - Run the default rustdoc against the current rustdoc - Diff output recursively - Colorize diff output --- src/tools/compiletest/src/json.rs | 11 ++-- src/tools/compiletest/src/runtest.rs | 72 +++++++++++++++++++++++++-- src/tools/compiletest/tidy-rustdoc.sh | 38 ++++++++++++++ 3 files changed, 113 insertions(+), 8 deletions(-) create mode 100755 src/tools/compiletest/tidy-rustdoc.sh diff --git a/src/tools/compiletest/src/json.rs b/src/tools/compiletest/src/json.rs index 19aec0ea598f9..8d23227fdb8b7 100644 --- a/src/tools/compiletest/src/json.rs +++ b/src/tools/compiletest/src/json.rs @@ -153,11 +153,14 @@ fn parse_line(file_name: &str, line: &str, output: &str, proc_res: &ProcRes) -> if serde_json::from_str::(line).is_ok() { vec![] } else { - proc_res.fatal(Some(&format!( - "failed to decode compiler output as json: \ + proc_res.fatal( + Some(&format!( + "failed to decode compiler output as json: \ `{}`\nline: {}\noutput: {}", - error, line, output - ))); + error, line, output + )), + || (), + ); } } } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index d46f905e6cc52..819f7257eee6a 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -287,6 +287,7 @@ pub fn compute_stamp_hash(config: &Config) -> String { format!("{:x}", hash.finish()) } +#[derive(Copy, Clone)] struct TestCx<'test> { config: &'test Config, props: &'test TestProps, @@ -2208,7 +2209,12 @@ impl<'test> TestCx<'test> { fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! { self.error(err); - proc_res.fatal(None); + proc_res.fatal(None, || ()); + } + + fn fatal_proc_rec_with_ctx(&self, err: &str, proc_res: &ProcRes, ctx: impl FnOnce(Self)) -> ! { + self.error(err); + proc_res.fatal(None, || ctx(*self)); } // codegen tests (using FileCheck) @@ -2325,15 +2331,72 @@ impl<'test> TestCx<'test> { let res = self.cmd2procres( Command::new(&self.config.docck_python) .arg(root.join("src/etc/htmldocck.py")) - .arg(out_dir) + .arg(&out_dir) .arg(&self.testpaths.file), ); if !res.status.success() { - self.fatal_proc_rec("htmldocck failed!", &res); + self.fatal_proc_rec_with_ctx("htmldocck failed!", &res, |mut this| { + this.compare_to_default_rustdoc(&out_dir) + }); } } } + fn compare_to_default_rustdoc(&mut self, out_dir: &Path) { + println!("info: generating a diff against nightly rustdoc"); + + let suffix = + self.safe_revision().map_or("nightly".into(), |path| path.to_owned() + "-nightly"); + let compare_dir = output_base_dir(self.config, self.testpaths, Some(&suffix)); + let _ = fs::remove_dir_all(&compare_dir); + create_dir_all(&compare_dir).unwrap(); + + // We need to create a new struct for the lifetimes on `config` to work. + let new_rustdoc = TestCx { + config: &Config { + // FIXME: use beta or a user-specified rustdoc instead of hardcoding + // the default toolchain + rustdoc_path: Some("rustdoc".into()), + ..self.config.clone() + }, + ..*self + }; + let proc_res = new_rustdoc.document(&compare_dir); + if !proc_res.status.success() { + proc_res.fatal(Some("failed to run nightly rustdoc"), || ()); + } + + // NOTE: this is fine since compiletest never runs out-of-tree + let tidy = concat!(env!("CARGO_MANIFEST_DIR"), "/tidy-rustdoc.sh"); + // FIXME: this overwrites `out_dir` in place, maybe we should make a copy? + let status = Command::new(tidy) + .arg(out_dir) + .spawn() + .expect("tidy-rustdoc not found") + .wait() + .unwrap(); + if !status.success() { + self.fatal("failed to run tidy - is installed?"); + } + let status = Command::new(tidy).arg(&compare_dir).spawn().unwrap().wait().unwrap(); + if !status.success() { + self.fatal("failed to run tidy"); + } + + let diff_pid = Command::new("diff") + .args(&["-u", "-r"]) + .args(&[out_dir, &compare_dir]) + .stdout(Stdio::piped()) + .spawn() + .expect("failed to run `diff`"); + Command::new("delta") + .stdin(diff_pid.stdout.unwrap()) + .spawn() + .expect("delta not found") + .wait() + .unwrap(); + } + fn get_lines>( &self, path: &P, @@ -3590,7 +3653,7 @@ pub struct ProcRes { } impl ProcRes { - pub fn fatal(&self, err: Option<&str>) -> ! { + pub fn fatal(&self, err: Option<&str>, ctx: impl FnOnce()) -> ! { if let Some(e) = err { println!("\nerror: {}", e); } @@ -3612,6 +3675,7 @@ impl ProcRes { json::extract_rendered(&self.stdout), json::extract_rendered(&self.stderr), ); + ctx(); // Use resume_unwind instead of panic!() to prevent a panic message + backtrace from // compiletest, which is unnecessary noise. std::panic::resume_unwind(Box::new(())); diff --git a/src/tools/compiletest/tidy-rustdoc.sh b/src/tools/compiletest/tidy-rustdoc.sh new file mode 100755 index 0000000000000..ce2c99d94d0c5 --- /dev/null +++ b/src/tools/compiletest/tidy-rustdoc.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -euo pipefail + +indir="${1:?Missing argument 1: input directory}" + +tidy () { + { + # new-inline-tags is workaround for: + # https://github.com/rust-lang/stdarch/issues/945 + # https://github.com/rust-lang/mdBook/issues/1372 + command tidy \ + --indent yes \ + --indent-spaces 2 \ + --wrap 0 \ + --show-warnings no \ + --markup yes \ + --quiet yes \ + --new-inline-tags 'c t' \ + "$@" \ + >/dev/null \ + || { + # tidy exits with code 1 if there were any warnings :facepalm: + status=$? + if [ $status != 0 ] && [ $status != 1 ] + then + echo "While tidying $1" >&2 + exit 1 + fi + } + } | sed -E 's/#[0-9]+(-[0-9]+)?/#line/g' +} + +find "$indir" -type f -name '*.html' -print0 \ +| while IFS= read -d '' -r file +do + tidy -modify "$file" +done From c0eedc0b6ad30dfa1eb2b225246b4b3debed1cdb Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 6 Nov 2020 17:37:29 -0500 Subject: [PATCH 2/8] Address review comments - remove unused args - Fix formatting - Improve naming - Fix typo --- src/tools/compiletest/src/runtest.rs | 15 ++++++++---- src/tools/compiletest/tidy-rustdoc.sh | 35 +++++++++------------------ 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 819f7257eee6a..59c650d94cdcf 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2212,9 +2212,14 @@ impl<'test> TestCx<'test> { proc_res.fatal(None, || ()); } - fn fatal_proc_rec_with_ctx(&self, err: &str, proc_res: &ProcRes, ctx: impl FnOnce(Self)) -> ! { + fn fatal_proc_rec_with_ctx( + &self, + err: &str, + proc_res: &ProcRes, + on_failure: impl FnOnce(Self), + ) -> ! { self.error(err); - proc_res.fatal(None, || ctx(*self)); + proc_res.fatal(None, || on_failure(*self)); } // codegen tests (using FileCheck) @@ -2376,7 +2381,7 @@ impl<'test> TestCx<'test> { .wait() .unwrap(); if !status.success() { - self.fatal("failed to run tidy - is installed?"); + self.fatal("failed to run tidy - is it installed?"); } let status = Command::new(tidy).arg(&compare_dir).spawn().unwrap().wait().unwrap(); if !status.success() { @@ -3653,7 +3658,7 @@ pub struct ProcRes { } impl ProcRes { - pub fn fatal(&self, err: Option<&str>, ctx: impl FnOnce()) -> ! { + pub fn fatal(&self, err: Option<&str>, on_failure: impl FnOnce()) -> ! { if let Some(e) = err { println!("\nerror: {}", e); } @@ -3675,7 +3680,7 @@ impl ProcRes { json::extract_rendered(&self.stdout), json::extract_rendered(&self.stderr), ); - ctx(); + on_failure(); // Use resume_unwind instead of panic!() to prevent a panic message + backtrace from // compiletest, which is unnecessary noise. std::panic::resume_unwind(Box::new(())); diff --git a/src/tools/compiletest/tidy-rustdoc.sh b/src/tools/compiletest/tidy-rustdoc.sh index ce2c99d94d0c5..b31957058e8c1 100755 --- a/src/tools/compiletest/tidy-rustdoc.sh +++ b/src/tools/compiletest/tidy-rustdoc.sh @@ -5,30 +5,17 @@ set -euo pipefail indir="${1:?Missing argument 1: input directory}" tidy () { - { - # new-inline-tags is workaround for: - # https://github.com/rust-lang/stdarch/issues/945 - # https://github.com/rust-lang/mdBook/issues/1372 - command tidy \ - --indent yes \ - --indent-spaces 2 \ - --wrap 0 \ - --show-warnings no \ - --markup yes \ - --quiet yes \ - --new-inline-tags 'c t' \ - "$@" \ - >/dev/null \ - || { - # tidy exits with code 1 if there were any warnings :facepalm: - status=$? - if [ $status != 0 ] && [ $status != 1 ] - then - echo "While tidying $1" >&2 - exit 1 - fi - } - } | sed -E 's/#[0-9]+(-[0-9]+)?/#line/g' + command tidy \ + --indent yes \ + --indent-spaces 2 \ + --wrap 0 \ + --show-warnings no \ + --markup yes \ + --quiet yes \ + "$@" \ + >/dev/null \ + # tidy exits with code 1 if there were any warnings + || [ $? -eq 1 ] } find "$indir" -type f -name '*.html' -print0 \ From acd6ce2347b80fedfc52df0c2a64127535e186f3 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 6 Nov 2020 18:01:50 -0500 Subject: [PATCH 3/8] Fix bugs --- src/tools/compiletest/src/main.rs | 2 +- src/tools/compiletest/src/runtest.rs | 4 +++- src/tools/compiletest/tidy-rustdoc.sh | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 2b167ac8e9fb2..32347db5dbb1c 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -379,7 +379,7 @@ pub fn run_tests(config: Config) { } Err(e) => { // We don't know if tests passed or not, but if there was an error - // during testing we don't want to just suceeed (we may not have + // during testing we don't want to just succeed (we may not have // tested something), so fail. // // This should realistically "never" happen, so don't try to make diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 59c650d94cdcf..8a0d671ed559c 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2394,12 +2394,14 @@ impl<'test> TestCx<'test> { .stdout(Stdio::piped()) .spawn() .expect("failed to run `diff`"); - Command::new("delta") + let status = Command::new("delta") + .arg("--paging=never") .stdin(diff_pid.stdout.unwrap()) .spawn() .expect("delta not found") .wait() .unwrap(); + assert!(status.success()); } fn get_lines>( diff --git a/src/tools/compiletest/tidy-rustdoc.sh b/src/tools/compiletest/tidy-rustdoc.sh index b31957058e8c1..407e9169af541 100755 --- a/src/tools/compiletest/tidy-rustdoc.sh +++ b/src/tools/compiletest/tidy-rustdoc.sh @@ -14,8 +14,7 @@ tidy () { --quiet yes \ "$@" \ >/dev/null \ - # tidy exits with code 1 if there were any warnings - || [ $? -eq 1 ] + || [ $? -eq 1 ] # tidy exits with code 1 if there were any warnings } find "$indir" -type f -name '*.html' -print0 \ From 975471ca4d5e141c4c885d4715e06671f862eeb7 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 7 Nov 2020 12:12:29 -0500 Subject: [PATCH 4/8] Fall back to `diff` if `delta` isn't installed --- src/tools/compiletest/src/runtest.rs | 34 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8a0d671ed559c..8319b8aba76eb 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2388,20 +2388,26 @@ impl<'test> TestCx<'test> { self.fatal("failed to run tidy"); } - let diff_pid = Command::new("diff") - .args(&["-u", "-r"]) - .args(&[out_dir, &compare_dir]) - .stdout(Stdio::piped()) - .spawn() - .expect("failed to run `diff`"); - let status = Command::new("delta") - .arg("--paging=never") - .stdin(diff_pid.stdout.unwrap()) - .spawn() - .expect("delta not found") - .wait() - .unwrap(); - assert!(status.success()); + let has_delta = Command::new("delta") + .arg("--version") + .status() + .map_or(false, |status| status.success()); + let mut diff = Command::new("diff"); + diff.args(&["-u", "-r"]).args(&[out_dir, &compare_dir]); + + if has_delta { + let diff_pid = diff.stdout(Stdio::piped()).spawn().expect("failed to run `diff`"); + let status = Command::new("delta") + .arg("--paging=never") + .stdin(diff_pid.stdout.unwrap()) + .status() + .unwrap(); + assert!(status.success()); + } else { + eprintln!("warning: `delta` not installed, falling back to `diff --color`"); + diff.arg("--color").spawn().expect("failed to run `diff`").wait().unwrap(); + assert!(status.success() || status.code() == Some(1)); + } } fn get_lines>( From 619880e5546d7a0a5b33ee22b972e4acd6bbcf37 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 7 Nov 2020 13:04:52 -0500 Subject: [PATCH 5/8] Fix tests with auxiliary docs --- src/tools/compiletest/src/runtest.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8319b8aba76eb..6eb7edf85aa5f 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1729,7 +1729,7 @@ impl<'test> TestCx<'test> { self.config.target.contains("vxworks") && !self.is_vxworks_pure_static() } - fn compose_and_run_compiler(&self, mut rustc: Command, input: Option) -> ProcRes { + fn build_all_auxiliary(&self, rustc: &mut Command) -> PathBuf { let aux_dir = self.aux_output_dir_name(); if !self.props.aux_builds.is_empty() { @@ -1748,6 +1748,11 @@ impl<'test> TestCx<'test> { rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir.display(), lib_name)); } + aux_dir + } + + fn compose_and_run_compiler(&self, mut rustc: Command, input: Option) -> ProcRes { + let aux_dir = self.build_all_auxiliary(&mut rustc); self.props.unset_rustc_env.clone().iter().fold(&mut rustc, |rustc, v| rustc.env_remove(v)); rustc.envs(self.props.rustc_env.clone()); self.compose_and_run( @@ -2359,13 +2364,26 @@ impl<'test> TestCx<'test> { // We need to create a new struct for the lifetimes on `config` to work. let new_rustdoc = TestCx { config: &Config { - // FIXME: use beta or a user-specified rustdoc instead of hardcoding - // the default toolchain + // FIXME: use beta or a user-specified rustdoc instead of + // hardcoding the default toolchain rustdoc_path: Some("rustdoc".into()), + // Needed for building auxiliary docs below + rustc_path: "rustc".into(), ..self.config.clone() }, ..*self }; + + let output_file = TargetLocation::ThisDirectory(new_rustdoc.aux_output_dir_name()); + let mut rustc = new_rustdoc.make_compile_args( + &new_rustdoc.testpaths.file, + output_file, + EmitMetadata::No, + AllowUnused::Yes, + ); + rustc.arg("-L").arg(&new_rustdoc.aux_output_dir_name()); + new_rustdoc.build_all_auxiliary(&mut dbg!(rustc)); + let proc_res = new_rustdoc.document(&compare_dir); if !proc_res.status.success() { proc_res.fatal(Some("failed to run nightly rustdoc"), || ()); @@ -2390,6 +2408,7 @@ impl<'test> TestCx<'test> { let has_delta = Command::new("delta") .arg("--version") + .stdout(Stdio::null()) .status() .map_or(false, |status| status.success()); let mut diff = Command::new("diff"); From e6e4a0ab63edb18d28e7de57b10e80f95ffd7666 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 7 Nov 2020 13:10:29 -0500 Subject: [PATCH 6/8] Capture stdout and stderr of diff so they'll be printed at the end --- src/tools/compiletest/src/runtest.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 6eb7edf85aa5f..7e17cac8b83b9 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2382,7 +2382,7 @@ impl<'test> TestCx<'test> { AllowUnused::Yes, ); rustc.arg("-L").arg(&new_rustdoc.aux_output_dir_name()); - new_rustdoc.build_all_auxiliary(&mut dbg!(rustc)); + new_rustdoc.build_all_auxiliary(&mut rustc); let proc_res = new_rustdoc.document(&compare_dir); if !proc_res.status.success() { @@ -2414,19 +2414,25 @@ impl<'test> TestCx<'test> { let mut diff = Command::new("diff"); diff.args(&["-u", "-r"]).args(&[out_dir, &compare_dir]); - if has_delta { + let output = if has_delta { let diff_pid = diff.stdout(Stdio::piped()).spawn().expect("failed to run `diff`"); - let status = Command::new("delta") + let output = Command::new("delta") .arg("--paging=never") .stdin(diff_pid.stdout.unwrap()) - .status() + // Capture output and print it explicitly so it will in turn be + // captured by libtest. + .output() .unwrap(); - assert!(status.success()); + assert!(output.status.success()); + output } else { eprintln!("warning: `delta` not installed, falling back to `diff --color`"); - diff.arg("--color").spawn().expect("failed to run `diff`").wait().unwrap(); - assert!(status.success() || status.code() == Some(1)); - } + let output = diff.arg("--color").output().unwrap(); + assert!(output.status.success() || output.status.code() == Some(1)); + output + }; + println!("{}", String::from_utf8_lossy(&output.stdout)); + eprintln!("{}", String::from_utf8_lossy(&output.stderr)); } fn get_lines>( From 4d44d77c4d97f46bbfd184e3995e0278b8c3d096 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 14 Nov 2020 02:44:33 -0500 Subject: [PATCH 7/8] Use default git pager instead of hard-coding `delta` --- src/tools/compiletest/src/runtest.rs | 32 ++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 7e17cac8b83b9..46bf007c64956 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2358,6 +2358,7 @@ impl<'test> TestCx<'test> { let suffix = self.safe_revision().map_or("nightly".into(), |path| path.to_owned() + "-nightly"); let compare_dir = output_base_dir(self.config, self.testpaths, Some(&suffix)); + // Don't give an error if the directory didn't already exist let _ = fs::remove_dir_all(&compare_dir); create_dir_all(&compare_dir).unwrap(); @@ -2406,18 +2407,28 @@ impl<'test> TestCx<'test> { self.fatal("failed to run tidy"); } - let has_delta = Command::new("delta") - .arg("--version") - .stdout(Stdio::null()) - .status() - .map_or(false, |status| status.success()); + let pager = { + let output = Command::new("git").args(&["config", "--get", "core.pager"]).output().ok(); + output.and_then(|out| { + if out.status.success() { + Some(String::from_utf8(out.stdout).expect("invalid UTF8 in git pager")) + } else { + None + } + }) + }; let mut diff = Command::new("diff"); diff.args(&["-u", "-r"]).args(&[out_dir, &compare_dir]); - let output = if has_delta { + let output = if let Some(pager) = pager { let diff_pid = diff.stdout(Stdio::piped()).spawn().expect("failed to run `diff`"); - let output = Command::new("delta") - .arg("--paging=never") + let pager = pager.trim(); + if self.config.verbose { + eprintln!("using pager {}", pager); + } + let output = Command::new(pager) + // disable paging; we want this to be non-interactive + .env("PAGER", "") .stdin(diff_pid.stdout.unwrap()) // Capture output and print it explicitly so it will in turn be // captured by libtest. @@ -2426,7 +2437,10 @@ impl<'test> TestCx<'test> { assert!(output.status.success()); output } else { - eprintln!("warning: `delta` not installed, falling back to `diff --color`"); + eprintln!("warning: no pager configured, falling back to `diff --color`"); + eprintln!( + "help: try configuring a git pager (e.g. `delta`) with `git config --global core.pager delta`" + ); let output = diff.arg("--color").output().unwrap(); assert!(output.status.success() || output.status.code() == Some(1)); output From 25a3ffe5d4768e37fe98c9637db84af4714549d4 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 20 Nov 2020 22:58:46 -0500 Subject: [PATCH 8/8] Move from bash to rust --- src/tools/compiletest/src/runtest.rs | 49 ++++++++++++++++++--------- src/tools/compiletest/tidy-rustdoc.sh | 24 ------------- 2 files changed, 33 insertions(+), 40 deletions(-) delete mode 100755 src/tools/compiletest/tidy-rustdoc.sh diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 46bf007c64956..ca9fad41b5624 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2390,22 +2390,39 @@ impl<'test> TestCx<'test> { proc_res.fatal(Some("failed to run nightly rustdoc"), || ()); } - // NOTE: this is fine since compiletest never runs out-of-tree - let tidy = concat!(env!("CARGO_MANIFEST_DIR"), "/tidy-rustdoc.sh"); - // FIXME: this overwrites `out_dir` in place, maybe we should make a copy? - let status = Command::new(tidy) - .arg(out_dir) - .spawn() - .expect("tidy-rustdoc not found") - .wait() - .unwrap(); - if !status.success() { - self.fatal("failed to run tidy - is it installed?"); - } - let status = Command::new(tidy).arg(&compare_dir).spawn().unwrap().wait().unwrap(); - if !status.success() { - self.fatal("failed to run tidy"); - } + #[rustfmt::skip] + let tidy_args = [ + "--indent", "yes", + "--indent-spaces", "2", + "--wrap", "0", + "--show-warnings", "no", + "--markup", "yes", + "--quiet", "yes", + "-modify", + ]; + let tidy_dir = |dir| { + let tidy = |file: &_| { + Command::new("tidy") + .args(&tidy_args) + .arg(file) + .spawn() + .unwrap_or_else(|err| { + self.fatal(&format!("failed to run tidy - is it installed? - {}", err)) + }) + .wait() + .unwrap() + }; + for entry in walkdir::WalkDir::new(dir) { + let entry = entry.expect("failed to read file"); + if entry.file_type().is_file() + && entry.path().extension().and_then(|p| p.to_str()) == Some("html".into()) + { + tidy(entry.path()); + } + } + }; + tidy_dir(out_dir); + tidy_dir(&compare_dir); let pager = { let output = Command::new("git").args(&["config", "--get", "core.pager"]).output().ok(); diff --git a/src/tools/compiletest/tidy-rustdoc.sh b/src/tools/compiletest/tidy-rustdoc.sh deleted file mode 100755 index 407e9169af541..0000000000000 --- a/src/tools/compiletest/tidy-rustdoc.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -indir="${1:?Missing argument 1: input directory}" - -tidy () { - command tidy \ - --indent yes \ - --indent-spaces 2 \ - --wrap 0 \ - --show-warnings no \ - --markup yes \ - --quiet yes \ - "$@" \ - >/dev/null \ - || [ $? -eq 1 ] # tidy exits with code 1 if there were any warnings -} - -find "$indir" -type f -name '*.html' -print0 \ -| while IFS= read -d '' -r file -do - tidy -modify "$file" -done