2024-08-25 05:34:45 +08:00
|
|
|
#![feature(rustc_private)]
|
|
|
|
|
2024-09-23 02:42:10 +08:00
|
|
|
use clippy_config::{ClippyConfiguration, get_configuration_metadata};
|
2024-08-25 05:34:45 +08:00
|
|
|
use itertools::Itertools;
|
|
|
|
use regex::Regex;
|
|
|
|
use std::borrow::Cow;
|
|
|
|
use std::{env, fs};
|
|
|
|
|
|
|
|
fn metadata() -> impl Iterator<Item = ClippyConfiguration> {
|
|
|
|
get_configuration_metadata()
|
|
|
|
.into_iter()
|
|
|
|
.filter(|config| config.deprecation_reason.is_none())
|
|
|
|
.filter(|config| !config.lints.is_empty())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn book() {
|
|
|
|
let path = "book/src/lint_configuration.md";
|
|
|
|
let current = fs::read_to_string(path).unwrap();
|
|
|
|
|
|
|
|
let configs = metadata().map(|conf| conf.to_markdown_paragraph()).join("\n");
|
|
|
|
let expected = format!(
|
2024-10-05 23:08:04 +08:00
|
|
|
r"<!--
|
2024-08-25 05:34:45 +08:00
|
|
|
This file is generated by `cargo bless --test config-metadata`.
|
|
|
|
Please use that command to update the file and do not edit it by hand.
|
|
|
|
-->
|
|
|
|
|
|
|
|
# Lint Configuration Options
|
|
|
|
|
|
|
|
The following list shows each configuration option, along with a description, its default value, an example
|
|
|
|
and lints affected.
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
{}
|
2024-10-05 23:08:04 +08:00
|
|
|
",
|
2024-08-25 05:34:45 +08:00
|
|
|
configs.trim(),
|
|
|
|
);
|
|
|
|
|
|
|
|
if current != expected {
|
|
|
|
if env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0") {
|
|
|
|
fs::write(path, expected).unwrap();
|
|
|
|
} else {
|
|
|
|
panic!("`{path}` is out of date, run `cargo bless --test config-metadata` to update it");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn changelog() {
|
|
|
|
let path = "CHANGELOG.md";
|
|
|
|
let current = fs::read_to_string(path).unwrap();
|
|
|
|
|
|
|
|
let configs = metadata().map(|conf| conf.to_markdown_link()).join("\n");
|
|
|
|
|
|
|
|
let re = Regex::new(
|
|
|
|
"(?s)\
|
|
|
|
(<!-- begin autogenerated links to configuration documentation -->)\
|
|
|
|
.*\
|
|
|
|
(<!-- end autogenerated links to configuration documentation -->)\
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
let expected = re.replace(¤t, format!("$1\n{configs}\n$2"));
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
matches!(expected, Cow::Owned(_)),
|
|
|
|
"failed to find configuration section in `{path}`"
|
|
|
|
);
|
|
|
|
|
|
|
|
if current != expected {
|
|
|
|
if env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0") {
|
|
|
|
fs::write(path, expected.as_bytes()).unwrap();
|
|
|
|
} else {
|
|
|
|
panic!("`{path}` is out of date, run `cargo bless --test config-metadata` to update it");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|