assert!(self.code_block.is_some() && self.code_block_start.is_some());
// See if code block begins with #![rustfmt::skip].
- let fmt_skip = self
- .code_block
- .as_ref()
- .unwrap()
- .lines()
- .nth(0)
- .unwrap_or("")
- == "#![rustfmt::skip]";
+ let fmt_skip = self.fmt_skip();
if self.config_name.is_none() && !fmt_skip {
write_message(&format!(
true
}
+ /// True if the code block starts with #![rustfmt::skip]
+ fn fmt_skip(&self) -> bool {
+ self.code_block
+ .as_ref()
+ .unwrap()
+ .lines()
+ .nth(0)
+ .unwrap_or("")
+ == "#![rustfmt::skip]"
+ }
+
fn has_parsing_errors<T: Write>(&self, session: &Session<'_, T>) -> bool {
if session.has_parsing_errors() {
write_message(&format!(
#[test]
fn configuration_snippet_tests() {
+ super::init_log();
let blocks = get_code_blocks();
let failures = blocks
.iter()
+ .filter(|block| !block.fmt_skip())
.map(ConfigCodeBlock::formatted_is_idempotent)
.fold(0, |acc, r| acc + (!r as u32));
code_blocks
}
+
+#[test]
+fn check_unstable_option_tracking_issue_numbers() {
+ // Ensure that tracking issue links point to the correct issue number
+ let tracking_issue =
+ regex::Regex::new(r"\(tracking issue: \[#(?P<number>\d+)\]\((?P<link>\S+)\)\)")
+ .expect("failed creating configuration pattern");
+
+ let lines = BufReader::new(
+ fs::File::open(Path::new(CONFIGURATIONS_FILE_NAME))
+ .unwrap_or_else(|_| panic!("couldn't read file {}", CONFIGURATIONS_FILE_NAME)),
+ )
+ .lines()
+ .map(Result::unwrap)
+ .enumerate();
+
+ for (idx, line) in lines {
+ if let Some(capture) = tracking_issue.captures(&line) {
+ let number = capture.name("number").unwrap().as_str();
+ let link = capture.name("link").unwrap().as_str();
+ assert!(
+ link.ends_with(number),
+ "{} on line {} does not point to issue #{}",
+ link,
+ idx + 1,
+ number,
+ );
+ }
+ }
+}