]> git.lizzy.rs Git - rust.git/blobdiff - tests/lint_message_convention.rs
removing unsafe from test fn's && renaming shrink to sugg_span
[rust.git] / tests / lint_message_convention.rs
index 45e0d7336c13a4281dce9173765a697e85010da3..b4d94dc983fec11fecc2efc20e8dbf006193ae07 100644 (file)
@@ -1,3 +1,7 @@
+#![cfg_attr(feature = "deny-warnings", deny(warnings))]
+#![warn(rust_2018_idioms, unused_lifetimes)]
+
+use std::ffi::OsStr;
 use std::path::PathBuf;
 
 use regex::RegexSet;
@@ -27,18 +31,17 @@ fn new(path: PathBuf) -> Self {
         ])
         .unwrap();
 
-        // sometimes the first character is capitalized and it is legal (like in "Iterator...") or
+        // sometimes the first character is capitalized and it is legal (like in "C-like enum variants") or
         // we want to ask a question ending in "?"
         let exceptions_set: RegexSet = RegexSet::new(&[
-            r".*error: I see you're using a LinkedList! Perhaps you meant some other data structure?",
             r".*C-like enum variant discriminant is not portable to 32-bit targets",
-            r".*Iterator::step_by(0) will panic at runtime",
             r".*did you mean `unix`?",
             r".*the arguments may be inverted...",
             r".*Intel x86 assembly syntax used",
             r".*AT&T x86 assembly syntax used",
-            r".*remove .* the return type...",
+            r".*remove .*the return type...",
             r"note: Clippy version: .*",
+            r"the compiler unexpectedly panicked. this is a bug.",
         ])
         .unwrap();
 
@@ -47,7 +50,7 @@ fn new(path: PathBuf) -> Self {
             .filter(|line| regex_set.matches(line).matched_any())
             // ignore exceptions
             .filter(|line| !exceptions_set.matches(line).matched_any())
-            .map(|s| s.to_owned())
+            .map(ToOwned::to_owned)
             .collect::<Vec<String>>();
 
         Message { path, bad_lines }
@@ -56,6 +59,11 @@ fn new(path: PathBuf) -> Self {
 
 #[test]
 fn lint_message_convention() {
+    // disable the test inside the rustc test suite
+    if option_env!("RUSTC_TEST_SUITE").is_some() {
+        return;
+    }
+
     // make sure that lint messages:
     // * are not capitalized
     // * don't have puncuation at the end of the last sentence
@@ -71,32 +79,33 @@ fn lint_message_convention() {
 
     // gather all .stderr files
     let tests = test_dirs
-        .map(|dir| {
+        .flat_map(|dir| {
             std::fs::read_dir(dir)
                 .expect("failed to read dir")
                 .map(|direntry| direntry.unwrap().path())
         })
-        .flatten()
-        .filter(|file| matches!(file.extension().map(|s| s.to_str()), Some(Some("stderr"))));
+        .filter(|file| matches!(file.extension().map(OsStr::to_str), Some(Some("stderr"))));
 
     // get all files that have any "bad lines" in them
     let bad_tests: Vec<Message> = tests
-        .map(|path| Message::new(path))
+        .map(Message::new)
         .filter(|message| !message.bad_lines.is_empty())
         .collect();
 
-    bad_tests.iter().for_each(|message| {
+    for message in &bad_tests {
         eprintln!(
             "error: the test '{}' contained the following nonconforming lines :",
             message.path.display()
         );
         message.bad_lines.iter().for_each(|line| eprintln!("{}", line));
         eprintln!("\n\n");
-    });
+    }
 
-    eprintln!("\n\n\nLint message should not start with a capital letter and should not have punctuation at the end of the message unless multiple sentences are needed.");
+    eprintln!(
+        "\n\n\nLint message should not start with a capital letter and should not have punctuation at the end of the message unless multiple sentences are needed."
+    );
     eprintln!("Check out the rustc-dev-guide for more information:");
-    eprintln!("https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure");
+    eprintln!("https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure\n\n\n");
 
     assert!(bad_tests.is_empty());
 }