diff --git a/Cargo.toml b/Cargo.toml index 8774079d2..d284f8220 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ fold = [] clone-impls = [] extra-traits = [] proc-macro = ["proc-macro2/proc-macro", "quote/proc-macro"] +test = ["syn-test-suite/all-features"] [dependencies] proc-macro2 = { version = "1.0.7", default-features = false } @@ -46,6 +47,7 @@ rayon = "1.0" ref-cast = "1.0" regex = "1.0" reqwest = { version = "0.10", features = ["blocking"] } +syn-test-suite = { version = "0", path = "tests/features" } tar = "0.4" termcolor = "1.0" walkdir = "2.1" @@ -67,4 +69,4 @@ targets = ["x86_64-unknown-linux-gnu"] all-features = true [workspace] -members = ["dev", "json"] +members = ["dev", "json", "tests/features"] diff --git a/tests/features/Cargo.toml b/tests/features/Cargo.toml new file mode 100644 index 000000000..8f6b3de07 --- /dev/null +++ b/tests/features/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "syn-test-suite" +version = "0.0.0" +edition = "2018" +publish = false + +[lib] +path = "lib.rs" + +[dependencies] +syn-test-suite-feature-check = { path = "macro" } + +[features] +all-features = ["syn-test-suite-feature-check/all-features"] diff --git a/tests/features/error.rs b/tests/features/error.rs deleted file mode 100644 index 10ac88965..000000000 --- a/tests/features/error.rs +++ /dev/null @@ -1 +0,0 @@ -"Hello! You want: cargo test --release --all-features" diff --git a/tests/features/lib.rs b/tests/features/lib.rs new file mode 100644 index 000000000..5aad327b8 --- /dev/null +++ b/tests/features/lib.rs @@ -0,0 +1 @@ +syn_test_suite_feature_check::check!(); diff --git a/tests/features/macro/Cargo.toml b/tests/features/macro/Cargo.toml new file mode 100644 index 000000000..4480a9053 --- /dev/null +++ b/tests/features/macro/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "syn-test-suite-feature-check" +version = "0.0.0" +edition = "2018" +publish = false + +[lib] +path = "lib.rs" +proc-macro = true + +[dependencies] +termcolor = "1.0" + +[features] +all-features = [] diff --git a/tests/features/macro/lib.rs b/tests/features/macro/lib.rs new file mode 100644 index 000000000..d4a2c85bc --- /dev/null +++ b/tests/features/macro/lib.rs @@ -0,0 +1,43 @@ +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); + + 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"); + let _ = stderr.set_color(&yellow); + let _ = writeln!(stderr, "{}", DEBUG_NOTE); + let _ = stderr.reset(); + } + + if cfg!(not(feature = "all-features")) { + let red = ColorSpec::new().set_fg(Some(Color::Red)).clone(); + let _ = writeln!(stderr); + let _ = stderr.set_color(red.clone().set_bold(true)); + let _ = write!(stderr, "ERROR"); + let _ = stderr.set_color(&red); + let _ = writeln!(stderr, "{}", FEATURES_ERROR); + let _ = stderr.reset(); + process::exit(1); + } + + TokenStream::new() +} diff --git a/tests/features/mod.rs b/tests/features/mod.rs deleted file mode 100644 index 83fbe13e7..000000000 --- a/tests/features/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -#[allow(unused_macros)] -macro_rules! hide_from_rustfmt { - ($mod:item) => { - $mod - }; -} - -#[cfg(not(all( - feature = "derive", - feature = "full", - feature = "parsing", - feature = "printing", - feature = "visit", - feature = "visit-mut", - feature = "fold", - feature = "clone-impls", - feature = "extra-traits", - feature = "proc-macro", -)))] -hide_from_rustfmt! { - mod error; -} diff --git a/tests/test_asyncness.rs b/tests/test_asyncness.rs index e09e816d4..0efef5976 100644 --- a/tests/test_asyncness.rs +++ b/tests/test_asyncness.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_attribute.rs b/tests/test_attribute.rs index e1b0142ba..c26bd090e 100644 --- a/tests/test_attribute.rs +++ b/tests/test_attribute.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_derive_input.rs b/tests/test_derive_input.rs index e3685aeae..96563b7f7 100644 --- a/tests/test_derive_input.rs +++ b/tests/test_derive_input.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_generics.rs b/tests/test_generics.rs index e863b7790..9957c0e4e 100644 --- a/tests/test_generics.rs +++ b/tests/test_generics.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_grouping.rs b/tests/test_grouping.rs index 4e43ab8a1..c53ab3462 100644 --- a/tests/test_grouping.rs +++ b/tests/test_grouping.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_ident.rs b/tests/test_ident.rs index 7578381e7..ee01bfcc9 100644 --- a/tests/test_ident.rs +++ b/tests/test_ident.rs @@ -1,5 +1,3 @@ -mod features; - use proc_macro2::{Ident, Span, TokenStream}; use std::str::FromStr; use syn::Result; diff --git a/tests/test_iterators.rs b/tests/test_iterators.rs index f1072977f..2c8359c15 100644 --- a/tests/test_iterators.rs +++ b/tests/test_iterators.rs @@ -1,8 +1,6 @@ use syn::punctuated::{Pair, Punctuated}; use syn::Token; -mod features; - #[macro_use] mod macros; diff --git a/tests/test_lit.rs b/tests/test_lit.rs index d4495ce40..5053a01da 100644 --- a/tests/test_lit.rs +++ b/tests/test_lit.rs @@ -1,5 +1,3 @@ -mod features; - use proc_macro2::{Span, TokenStream, TokenTree}; use quote::ToTokens; use std::str::FromStr; diff --git a/tests/test_meta.rs b/tests/test_meta.rs index 618296e2c..d37dda948 100644 --- a/tests/test_meta.rs +++ b/tests/test_meta.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_pat.rs b/tests/test_pat.rs index cce4b8091..8cba735fe 100644 --- a/tests/test_pat.rs +++ b/tests/test_pat.rs @@ -1,5 +1,3 @@ -mod features; - use quote::quote; use syn::Pat; diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs index f0559bb5d..08d3c1e03 100644 --- a/tests/test_precedence.rs +++ b/tests/test_precedence.rs @@ -18,8 +18,6 @@ extern crate rustc_ast; extern crate rustc_data_structures; extern crate rustc_span; -mod features; - use quote::quote; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use regex::Regex; diff --git a/tests/test_receiver.rs b/tests/test_receiver.rs index 7169891ef..923df96ba 100644 --- a/tests/test_receiver.rs +++ b/tests/test_receiver.rs @@ -1,5 +1,3 @@ -mod features; - use syn::{parse_quote, FnArg, Receiver, TraitItemMethod}; #[test] diff --git a/tests/test_round_trip.rs b/tests/test_round_trip.rs index e4caf9f83..4dde5f25c 100644 --- a/tests/test_round_trip.rs +++ b/tests/test_round_trip.rs @@ -9,8 +9,6 @@ extern crate rustc_parse as parse; extern crate rustc_session; extern crate rustc_span; -mod features; - use quote::quote; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rustc_ast::ast; diff --git a/tests/test_should_parse.rs b/tests/test_should_parse.rs index d4f7ac342..180d85991 100644 --- a/tests/test_should_parse.rs +++ b/tests/test_should_parse.rs @@ -1,5 +1,3 @@ -mod features; - macro_rules! should_parse { ($name:ident, { $($in:tt)* }) => { #[test] diff --git a/tests/test_size.rs b/tests/test_size.rs index 386d4df88..01e840115 100644 --- a/tests/test_size.rs +++ b/tests/test_size.rs @@ -1,7 +1,5 @@ #![cfg(target_pointer_width = "64")] -mod features; - use std::mem; use syn::*; diff --git a/tests/test_token_trees.rs b/tests/test_token_trees.rs index 5d7610bb9..75c7e40c7 100644 --- a/tests/test_token_trees.rs +++ b/tests/test_token_trees.rs @@ -1,5 +1,3 @@ -mod features; - #[macro_use] mod macros; diff --git a/tests/test_visibility.rs b/tests/test_visibility.rs index 21c49c996..21f9adf28 100644 --- a/tests/test_visibility.rs +++ b/tests/test_visibility.rs @@ -1,5 +1,3 @@ -mod features; - use proc_macro2::TokenStream; use syn::parse::{Parse, ParseStream}; use syn::{Result, Visibility};