Make tidy errors red

This makes it easier to see them (and makes people go owo).
This commit is contained in:
Nilstrieb 2022-12-30 12:23:05 +01:00
parent f9cc011269
commit 75b3ee26cb
3 changed files with 28 additions and 13 deletions

View File

@ -2675,9 +2675,9 @@ dependencies = [
[[package]] [[package]]
name = "owo-colors" name = "owo-colors"
version = "3.4.0" version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]] [[package]]
name = "packed_simd_2" name = "packed_simd_2"
@ -5203,9 +5203,9 @@ dependencies = [
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.2" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [ dependencies = [
"winapi-util", "winapi-util",
] ]
@ -5309,6 +5309,7 @@ dependencies = [
"lazy_static", "lazy_static",
"miropt-test-tools", "miropt-test-tools",
"regex", "regex",
"termcolor",
"walkdir", "walkdir",
] ]

View File

@ -11,6 +11,7 @@ miropt-test-tools = { path = "../miropt-test-tools" }
lazy_static = "1" lazy_static = "1"
walkdir = "2" walkdir = "2"
ignore = "0.4.18" ignore = "0.4.18"
termcolor = "1.1.3"
[[bin]] [[bin]]
name = "rust-tidy" name = "rust-tidy"

View File

@ -3,6 +3,10 @@
//! This library contains the tidy lints and exposes it //! This library contains the tidy lints and exposes it
//! to be used by tools. //! to be used by tools.
use std::fmt::Display;
use termcolor::WriteColor;
/// A helper macro to `unwrap` a result except also print out details like: /// A helper macro to `unwrap` a result except also print out details like:
/// ///
/// * The expression that failed /// * The expression that failed
@ -26,18 +30,27 @@ macro_rules! t {
} }
macro_rules! tidy_error { macro_rules! tidy_error {
($bad:expr, $fmt:expr) => ({ ($bad:expr, $($fmt:tt)*) => ({
*$bad = true; $crate::tidy_error($bad, format_args!($($fmt)*)).expect("failed to output error");
eprint!("tidy error: ");
eprintln!($fmt);
});
($bad:expr, $fmt:expr, $($arg:tt)*) => ({
*$bad = true;
eprint!("tidy error: ");
eprintln!($fmt, $($arg)*);
}); });
} }
fn tidy_error(bad: &mut bool, args: impl Display) -> std::io::Result<()> {
use std::io::Write;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream};
*bad = true;
let mut stderr = StandardStream::stdout(ColorChoice::Auto);
stderr.set_color(ColorSpec::new().set_fg(Some(Color::Red)))?;
write!(&mut stderr, "tidy error")?;
stderr.set_color(&ColorSpec::new())?;
writeln!(&mut stderr, ": {args}")?;
Ok(())
}
pub mod alphabetical; pub mod alphabetical;
pub mod bins; pub mod bins;
pub mod debug_artifacts; pub mod debug_artifacts;