mirror of
https://gitee.com/openharmony/third_party_rust_syn
synced 2024-11-26 17:31:44 +00:00
Make cargo test
fail more helpfully
This commit is contained in:
parent
242a3b413e
commit
9289ffcf38
@ -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
14
tests/features/Cargo.toml
Normal 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"]
|
@ -1 +0,0 @@
|
||||
"Hello! You want: cargo test --release --all-features"
|
1
tests/features/lib.rs
Normal file
1
tests/features/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
syn_test_suite_feature_check::check!();
|
15
tests/features/macro/Cargo.toml
Normal file
15
tests/features/macro/Cargo.toml
Normal 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 = []
|
43
tests/features/macro/lib.rs
Normal file
43
tests/features/macro/lib.rs
Normal 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()
|
||||
}
|
@ -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;
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
use proc_macro2::{Ident, Span, TokenStream};
|
||||
use std::str::FromStr;
|
||||
use syn::Result;
|
||||
|
@ -1,8 +1,6 @@
|
||||
use syn::punctuated::{Pair, Punctuated};
|
||||
use syn::Token;
|
||||
|
||||
mod features;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
use proc_macro2::{Span, TokenStream, TokenTree};
|
||||
use quote::ToTokens;
|
||||
use std::str::FromStr;
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
use quote::quote;
|
||||
use syn::Pat;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
use syn::{parse_quote, FnArg, Receiver, TraitItemMethod};
|
||||
|
||||
#[test]
|
||||
|
@ -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;
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
macro_rules! should_parse {
|
||||
($name:ident, { $($in:tt)* }) => {
|
||||
#[test]
|
||||
|
@ -1,7 +1,5 @@
|
||||
#![cfg(target_pointer_width = "64")]
|
||||
|
||||
mod features;
|
||||
|
||||
use std::mem;
|
||||
use syn::*;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
mod features;
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use syn::parse::{Parse, ParseStream};
|
||||
use syn::{Result, Visibility};
|
||||
|
Loading…
Reference in New Issue
Block a user