From 01386e649265a71d9d91cf9ec138d6f046dc438b Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Wed, 29 Jun 2016 22:58:57 +0100 Subject: Reject invalid urls in linkchecker For example root-relative links will now be rejected. Also remove some exceptions which have since been fixed and fix a typo in the broken redirect handling. --- src/tools/linkchecker/main.rs | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'src/tools') diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index 4b74833eaf7..80c37d55975 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -138,22 +138,6 @@ fn check(cache: &mut Cache, return None; } - if file.ends_with("std/sys/ext/index.html") { - return None; - } - - if let Some(file) = file.to_str() { - // FIXME(#31948) - if file.contains("ParseFloatError") { - return None; - } - // weird reexports, but this module is on its way out, so chalk it up to - // "rustdoc weirdness" and move on from there - if file.contains("scoped_tls") { - return None; - } - } - let mut parser = UrlParser::new(); parser.base_url(base); @@ -170,12 +154,24 @@ fn check(cache: &mut Cache, // Search for anything that's the regex 'href[ ]*=[ ]*".*?"' with_attrs_in_source(&contents, " href", |url, i| { + // Ignore external URLs + if url.starts_with("http:") || url.starts_with("https:") || + url.starts_with("javascript:") || url.starts_with("ftp:") || + url.starts_with("irc:") || url.starts_with("data:") { + return; + } // Once we've plucked out the URL, parse it using our base url and - // then try to extract a file path. If either of these fail then we - // just keep going. + // then try to extract a file path. let (parsed_url, path) = match url_to_file_path(&parser, url) { Some((url, path)) => (url, PathBuf::from(path)), - None => return, + None => { + *errors = true; + println!("{}:{}: invalid link - {}", + pretty_file.display(), + i + 1, + url); + return; + } }; // Alright, if we've found a file name then this file had better @@ -197,10 +193,11 @@ fn check(cache: &mut Cache, Ok(res) => res, Err(LoadError::IOError(err)) => panic!(format!("{}", err)), Err(LoadError::BrokenRedirect(target, _)) => { - print!("{}:{}: broken redirect to {}", - pretty_file.display(), - i + 1, - target.display()); + *errors = true; + println!("{}:{}: broken redirect to {}", + pretty_file.display(), + i + 1, + target.display()); return; } Err(LoadError::IsRedirect) => unreachable!(), -- cgit 1.4.1-3-g733a5 From 737d854521021ae3da426694f92c6d4d12c72938 Mon Sep 17 00:00:00 2001 From: ggomez Date: Wed, 29 Jun 2016 17:25:35 +0200 Subject: Improve runtest output It now prints only unexpected errors and expected errors which weren't found --- src/tools/compiletest/src/runtest.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/tools') diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 953e060465a..577da5c5af1 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1012,8 +1012,7 @@ actual:\n\ // Parse the JSON output from the compiler and extract out the messages. let actual_errors = json::parse_output(&file_name, &proc_res.stderr, &proc_res); - let mut unexpected = 0; - let mut not_found = 0; + let mut unexpected = Vec::new(); let mut found = vec![false; expected_errors.len()]; for actual_error in &actual_errors { let opt_index = @@ -1045,12 +1044,13 @@ actual:\n\ .map_or(String::from("message"), |k| k.to_string()), actual_error.msg)); - unexpected += 1; + unexpected.push(actual_error.clone()); } } } } + let mut not_found = Vec::new(); // anything not yet found is a problem for (index, expected_error) in expected_errors.iter().enumerate() { if !found[index] { @@ -1062,18 +1062,22 @@ actual:\n\ .map_or("message".into(), |k| k.to_string()), expected_error.msg)); - not_found += 1; + not_found.push(expected_error.clone()); } } - if unexpected > 0 || not_found > 0 { + if unexpected.len() > 0 || not_found.len() > 0 { self.error( &format!("{} unexpected errors found, {} expected errors not found", - unexpected, not_found)); + unexpected.len(), not_found.len())); print!("status: {}\ncommand: {}\n", proc_res.status, proc_res.cmdline); - println!("actual errors (from JSON output): {:#?}\n", actual_errors); - println!("expected errors (from test file): {:#?}\n", expected_errors); + if unexpected.len() > 0 { + println!("unexpected errors (from JSON output): {:#?}\n", unexpected); + } + if not_found.len() > 0 { + println!("not found errors (from test file): {:#?}\n", not_found); + } panic!(); } } -- cgit 1.4.1-3-g733a5