From dffe82b26ee2c456e47275fccb6112b9d160e717 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 26 Mar 2023 13:51:02 -0700 Subject: [PATCH] Perform build-time alerts in test suite using build-alert crate --- tests/features/Cargo.toml | 4 +-- tests/features/lib.rs | 17 +++++++++- tests/features/macro/Cargo.toml | 16 --------- tests/features/macro/lib.rs | 59 --------------------------------- 4 files changed, 18 insertions(+), 78 deletions(-) delete mode 100644 tests/features/macro/Cargo.toml delete mode 100644 tests/features/macro/lib.rs diff --git a/tests/features/Cargo.toml b/tests/features/Cargo.toml index 22c719928f..7c9a937159 100644 --- a/tests/features/Cargo.toml +++ b/tests/features/Cargo.toml @@ -9,7 +9,7 @@ publish = false path = "lib.rs" [dependencies] -syn-test-suite-feature-check = { path = "macro" } +build-alert = "0.1" [features] -all-features = ["syn-test-suite-feature-check/all-features"] +all-features = [] diff --git a/tests/features/lib.rs b/tests/features/lib.rs index 5aad327b8a..506b42cd72 100644 --- a/tests/features/lib.rs +++ b/tests/features/lib.rs @@ -1 +1,16 @@ -syn_test_suite_feature_check::check!(); +#[cfg(debug_assertions)] +build_alert::yellow! {" +NOTE: use --release + Syn's test suite has some tests that run on every source file + and test case in the rust-lang/rust repo, which can be pretty + slow in debug mode. Consider running cargo test with `--release` + to speed things up. +"} + +#[cfg(not(feature = "all-features"))] +build_alert::red! {" +ERROR: use --all-features + Syn's test suite normally only works with all-features enabled. + Run again with `--all-features`, or run with `--features test` + to bypass this check. +"} diff --git a/tests/features/macro/Cargo.toml b/tests/features/macro/Cargo.toml deleted file mode 100644 index 4d1f69161c..0000000000 --- a/tests/features/macro/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "syn-test-suite-feature-check" -version = "0.0.0" -authors = ["David Tolnay "] -edition = "2021" -publish = false - -[lib] -path = "lib.rs" -proc-macro = true - -[dependencies] -termcolor = "1" - -[features] -all-features = [] diff --git a/tests/features/macro/lib.rs b/tests/features/macro/lib.rs deleted file mode 100644 index 62f361626e..0000000000 --- a/tests/features/macro/lib.rs +++ /dev/null @@ -1,59 +0,0 @@ -#![allow( - clippy::let_underscore_untyped, - clippy::toplevel_ref_arg, - clippy::uninlined_format_args -)] - -use proc_macro::TokenStream; -use std::io::Write; -use std::process; -use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; - -const DEBUG_NOTE: &str = ": use --release - Syn's test suite has some tests that run on every source file - and test case in the rust-lang/rust repo, which can be pretty - slow in debug mode. Consider running cargo test with `--release` - to speed things up."; - -const FEATURES_ERROR: &str = ": use --all-features - Syn's test suite normally only works with all-features enabled. - Run again with `--all-features`, or run with `--features test` - to bypass this check."; - -#[proc_macro] -pub fn check(_input: TokenStream) -> TokenStream { - let ref mut stderr = StandardStream::stderr(ColorChoice::Auto); - let mut needs_newline = true; - - if cfg!(debug_assertions) { - let yellow = ColorSpec::new().set_fg(Some(Color::Yellow)).clone(); - let _ = writeln!(stderr); - let _ = stderr.set_color(yellow.clone().set_bold(true)); - let _ = write!(stderr, "NOTE"); - for line in DEBUG_NOTE.lines() { - let _ = stderr.set_color(&yellow); - let _ = writeln!(stderr, "{}", line); - } - let _ = stderr.reset(); - let _ = writeln!(stderr); - needs_newline = false; - } - - if cfg!(not(feature = "all-features")) { - let red = ColorSpec::new().set_fg(Some(Color::Red)).clone(); - if needs_newline { - let _ = writeln!(stderr); - } - let _ = stderr.set_color(red.clone().set_bold(true)); - let _ = write!(stderr, "ERROR"); - for line in FEATURES_ERROR.lines() { - let _ = stderr.set_color(&red); - let _ = writeln!(stderr, "{}", line); - } - let _ = stderr.reset(); - let _ = writeln!(stderr); - process::exit(1); - } - - TokenStream::new() -}