Make cargo test fail more helpfully

This commit is contained in:
David Tolnay 2020-05-15 19:25:51 -07:00
parent 242a3b413e
commit 9289ffcf38
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
24 changed files with 76 additions and 58 deletions

View File

@ -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"]

14
tests/features/Cargo.toml Normal file
View File

@ -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"]

View File

@ -1 +0,0 @@
"Hello! You want: cargo test --release --all-features"

1
tests/features/lib.rs Normal file
View File

@ -0,0 +1 @@
syn_test_suite_feature_check::check!();

View File

@ -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 = []

View File

@ -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()
}

View File

@ -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;
}

View File

@ -1,5 +1,3 @@
mod features;
#[macro_use]
mod macros;

View File

@ -1,5 +1,3 @@
mod features;
#[macro_use]
mod macros;

View File

@ -1,5 +1,3 @@
mod features;
#[macro_use]
mod macros;

View File

@ -1,5 +1,3 @@
mod features;
#[macro_use]
mod macros;

View File

@ -1,5 +1,3 @@
mod features;
#[macro_use]
mod macros;

View File

@ -1,5 +1,3 @@
mod features;
use proc_macro2::{Ident, Span, TokenStream};
use std::str::FromStr;
use syn::Result;

View File

@ -1,8 +1,6 @@
use syn::punctuated::{Pair, Punctuated};
use syn::Token;
mod features;
#[macro_use]
mod macros;

View File

@ -1,5 +1,3 @@
mod features;
use proc_macro2::{Span, TokenStream, TokenTree};
use quote::ToTokens;
use std::str::FromStr;

View File

@ -1,5 +1,3 @@
mod features;
#[macro_use]
mod macros;

View File

@ -1,5 +1,3 @@
mod features;
use quote::quote;
use syn::Pat;

View File

@ -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;

View File

@ -1,5 +1,3 @@
mod features;
use syn::{parse_quote, FnArg, Receiver, TraitItemMethod};
#[test]

View File

@ -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;

View File

@ -1,5 +1,3 @@
mod features;
macro_rules! should_parse {
($name:ident, { $($in:tt)* }) => {
#[test]

View File

@ -1,7 +1,5 @@
#![cfg(target_pointer_width = "64")]
mod features;
use std::mem;
use syn::*;

View File

@ -1,5 +1,3 @@
mod features;
#[macro_use]
mod macros;

View File

@ -1,5 +1,3 @@
mod features;
use proc_macro2::TokenStream;
use syn::parse::{Parse, ParseStream};
use syn::{Result, Visibility};