Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cargo test fail more helpfully #798

Merged
merged 1 commit into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"
Expand All @@ -67,4 +69,4 @@ targets = ["x86_64-unknown-linux-gnu"]
all-features = true

[workspace]
members = ["dev", "json"]
members = ["dev", "json", "tests/features"]
14 changes: 14 additions & 0 deletions tests/features/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 0 additions & 1 deletion tests/features/error.rs

This file was deleted.

1 change: 1 addition & 0 deletions tests/features/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
syn_test_suite_feature_check::check!();
15 changes: 15 additions & 0 deletions tests/features/macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = []
43 changes: 43 additions & 0 deletions tests/features/macro/lib.rs
Original file line number Diff line number Diff line change
@@ -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()
}
22 changes: 0 additions & 22 deletions tests/features/mod.rs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/test_asyncness.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

#[macro_use]
mod macros;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_attribute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

#[macro_use]
mod macros;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_derive_input.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

#[macro_use]
mod macros;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_generics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

#[macro_use]
mod macros;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_grouping.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

#[macro_use]
mod macros;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_ident.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

use proc_macro2::{Ident, Span, TokenStream};
use std::str::FromStr;
use syn::Result;
Expand Down
2 changes: 0 additions & 2 deletions tests/test_iterators.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use syn::punctuated::{Pair, Punctuated};
use syn::Token;

mod features;

#[macro_use]
mod macros;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_lit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

use proc_macro2::{Span, TokenStream, TokenTree};
use quote::ToTokens;
use std::str::FromStr;
Expand Down
2 changes: 0 additions & 2 deletions tests/test_meta.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

#[macro_use]
mod macros;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_pat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

use quote::quote;
use syn::Pat;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions tests/test_receiver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

use syn::{parse_quote, FnArg, Receiver, TraitItemMethod};

#[test]
Expand Down
2 changes: 0 additions & 2 deletions tests/test_round_trip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions tests/test_should_parse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

macro_rules! should_parse {
($name:ident, { $($in:tt)* }) => {
#[test]
Expand Down
2 changes: 0 additions & 2 deletions tests/test_size.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![cfg(target_pointer_width = "64")]

mod features;

use std::mem;
use syn::*;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_token_trees.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

#[macro_use]
mod macros;

Expand Down
2 changes: 0 additions & 2 deletions tests/test_visibility.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod features;

use proc_macro2::TokenStream;
use syn::parse::{Parse, ParseStream};
use syn::{Result, Visibility};
Expand Down