Skip to content

Commit

Permalink
Merge #30
Browse files Browse the repository at this point in the history
30: Add more ui tests r=taiki-e a=taiki-e



Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e committed Jun 26, 2019
2 parents 12fdcb4 + 2d5c69d commit 3362945
Show file tree
Hide file tree
Showing 27 changed files with 409 additions and 211 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -22,19 +22,19 @@ matrix:
script:
- cargo test --all --no-default-features
- cargo test --all
- cargo test --all --all-features --exclude auto_enums_ui_tests
- cargo test --all --all-features

- rust: nightly
name: cargo test (ui tests)
script:
- cargo clean
- cargo test -p auto_enums_ui_tests --all-features
- RUSTFLAGS='--cfg ui_tests' cargo test -p auto_enums_test_suite --all-features --test compile-test

- rust: nightly
name: cargo check (minimal versions)
script:
- cargo update -Zminimal-versions
- cargo check --all --all-features --exclude auto_enums_ui_tests
- cargo check --all --all-features

- rust: nightly
name: cargo tree
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -18,7 +18,6 @@ members = [
"core",
"derive",
"test_suite",
"test_suite/compile-test",
"test_suite/unstable",
]

Expand Down
29 changes: 15 additions & 14 deletions core/src/auto_enum/args.rs
Expand Up @@ -66,9 +66,6 @@ impl Eq for Arg {}
// Parse

macro_rules! error {
($msg:expr) => {
syn::Error::new($msg.span(), $msg)
};
($span:expr, $msg:expr) => {
return Err(syn::Error::new($span.span(), $msg))
};
Expand All @@ -78,7 +75,7 @@ macro_rules! error {
}

pub(super) fn parse_group(group: TokenStream) -> Result<(Vec<Arg>, Option<String>, bool)> {
syn::parse2::<Group>(group).map_err(|e| error!(e)).and_then(|group| parse_args(group.stream()))
syn::parse2::<Group>(group).and_then(|group| parse_args(group.stream()))
}

pub(super) fn parse_args(args: TokenStream) -> Result<(Vec<Arg>, Option<String>, bool)> {
Expand Down Expand Up @@ -129,7 +126,7 @@ fn parse_path(mut path: Vec<TokenTree>, iter: &mut IntoIter) -> Result<Arg> {
}
}

syn::parse2(path.into_iter().collect()).map_err(|e| error!(e)).map(Arg::Path)
syn::parse2(path.into_iter().collect()).map(Arg::Path)
}

fn path_or_ident(ident: Ident, tt: Option<TokenTree>, iter: &mut IntoIter) -> Result<Arg> {
Expand All @@ -156,23 +153,27 @@ fn marker_opt(
Some(TokenTree::Group(ref g)) if g.delimiter() != Delimiter::Parenthesis => {
error!(g, "invalid delimiter")
}
Some(TokenTree::Group(ref g)) => {
let mut g = g.stream().into_iter();
match g.next() {
Some(TokenTree::Group(g)) => {
let mut tts = g.stream().into_iter();
let i = match tts.next() {
Some(TokenTree::Ident(ref i)) if marker.is_some() => {
error!(i, "multiple `marker` option")
}
Some(TokenTree::Ident(i)) => *marker = Some(i.to_string()),
Some(TokenTree::Ident(i)) => i,
Some(tt) => error!(tt, "expected an identifier, found `{}`", tt),
None => error!(ident, "empty `marker` option"),
}
match g.next() {
None => error!(g, "empty `marker` option"),
};
*marker = Some(i.to_string());
match tts.next() {
None => {}
Some(TokenTree::Punct(ref p)) if p.as_char() == ',' => {
if let Some(tt) = g.next() {
if let Some(tt) = tts.next() {
// TODO: https://docs.rs/proc-macro2/0.4/proc_macro2/struct.Span.html#method.join
// `i.span().join(tt.span()).unwrap_or_else(|| tt.span())`
error!(tt, "multiple identifier in `marker` option")
}
}
// TODO: https://docs.rs/proc-macro2/0.4/proc_macro2/struct.Span.html#method.join
Some(tt) => error!(tt, "multiple identifier in `marker` option"),
}
}
Expand All @@ -188,7 +189,7 @@ fn marker_opt(
match iter.next() {
None => {}
Some(TokenTree::Punct(ref p)) if p.as_char() == ',' => {}
Some(tt) => error!(tt, "multiple identifier in `marker` option"),
Some(tt) => error!(tt, "expected `,`, found `{}`", tt),
}
}
tt => args.push(path_or_ident(ident, tt, iter)?),
Expand Down
6 changes: 4 additions & 2 deletions core/src/auto_enum/expr.rs
Expand Up @@ -248,9 +248,11 @@ impl VisitLast<()> for ExprIf {
}
Some(Expr::If(expr)) => expr.visit_last(cx),

// TODO: https://docs.rs/proc-macro2/0.4/proc_macro2/struct.Span.html#method.join
// `self.span().join(self.then_branch.span()).unwrap_or_else(|| self.span())``
None => Err(error!(span => self.span(), "`if` expression missing an else clause")),
// FIXME: This may not be necessary.
Some(expr) => Err(error!(expr, "after of `else` required `{` or `if`")),

Some(_) => unreachable!("wrong_if"),
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions core/src/utils/mod.rs
Expand Up @@ -85,9 +85,6 @@ macro_rules! error {
(span => $span:expr, $msg:expr) => {
syn::Error::new($span, $msg)
};
($msg:expr) => {
syn::Error::new_spanned(span!($msg), $msg)
};
($span:expr, $msg:expr) => {
syn::Error::new_spanned(span!($span), $msg)
};
Expand Down
17 changes: 8 additions & 9 deletions derive/build.rs
@@ -1,4 +1,4 @@
use std::{env, process::Command, str};
use std::{env, process::Command};

fn main() {
println!("cargo:rerun-if-changed=build.rs");
Expand All @@ -16,13 +16,12 @@ fn main() {
fn rustc_minor_version() -> Option<u32> {
env::var_os("RUSTC")
.and_then(|rustc| Command::new(rustc).arg("--version").output().ok())
.and_then(|output| {
str::from_utf8(&output.stdout).ok().and_then(|version| {
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
pieces.next()?.parse().ok()
})
.and_then(|output| String::from_utf8(output.stdout).ok())
.and_then(|version| {
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
pieces.next()?.parse().ok()
})
}
3 changes: 0 additions & 3 deletions derive/src/utils.rs
Expand Up @@ -51,9 +51,6 @@ macro_rules! span {
}

macro_rules! error {
($msg:expr) => {
syn::Error::new_spanned(span!($msg), $msg)
};
($span:expr, $msg:expr) => {
syn::Error::new_spanned(span!($span), $msg)
};
Expand Down
16 changes: 11 additions & 5 deletions test_suite/Cargo.toml
Expand Up @@ -10,13 +10,10 @@ futures = { version = "0.1", optional = true }
quote = { version = "0.6", optional = true }
rayon = { version = "1.0", optional = true }
serde = { version = "1.0", optional = true }

[dependencies.auto_enums]
path = ".."
default-features = false
features = ["fmt", "transpose_methods"]
compiletest = { version = "0.3.21", package = "compiletest_rs", optional = true, features = ["stable", "tmp"] }

[dev-dependencies]
auto_enums = { path = "..", default-features = false, features = ["fmt", "transpose_methods"] }
rand = "0.6"

[features]
Expand All @@ -43,3 +40,12 @@ unstable = [
"auto_enums/exact_size_is_empty",
"auto_enums/try_trait",
]

ui_tests = [
"compiletest",
"std",
"unstable",
"auto_enums/type_analysis",
"auto_enums/transpose_methods",
"auto_enums/try_trait",
]
17 changes: 0 additions & 17 deletions test_suite/compile-test/Cargo.toml

This file was deleted.

39 changes: 0 additions & 39 deletions test_suite/compile-test/tests/ui/auto_enum/compile-fail.rs

This file was deleted.

46 changes: 0 additions & 46 deletions test_suite/compile-test/tests/ui/auto_enum/compile-fail.stderr

This file was deleted.

45 changes: 0 additions & 45 deletions test_suite/compile-test/tests/ui/enum_derive/variant.rs

This file was deleted.

@@ -1,3 +1,4 @@
#![cfg(ui_tests)]
#![cfg(feature = "unstable")]

use std::{env, path::PathBuf};
Expand Down
9 changes: 4 additions & 5 deletions test_suite/tests/test_auto_enum.rs
Expand Up @@ -18,7 +18,6 @@
#![cfg_attr(all(not(feature = "std"), feature = "unstable"), feature(alloc))]
#![warn(rust_2018_idioms)]
#![warn(clippy::all)]
#![allow(ellipsis_inclusive_range_patterns)] // syn generates both as `...`.
#![allow(clippy::cognitive_complexity, clippy::needless_return, clippy::never_loop)]

#[cfg(all(not(feature = "std"), feature = "unstable"))]
Expand All @@ -44,7 +43,7 @@ fn stable_1_30() {
}

// block + unsafe block + parentheses
#[cfg_attr(feature = "rustfmt", rustfmt_skip)]
#[rustfmt::skip]
#[allow(unused_unsafe)]
#[auto_enum(Iterator)]
fn block(x: usize) -> impl Iterator<Item = i32> {
Expand Down Expand Up @@ -402,7 +401,7 @@ fn stable_1_30() {
assert_eq!(rec_match_in_match(i).sum::<i32>(), *x);
}

#[cfg_attr(feature = "rustfmt", rustfmt_skip)]
#[rustfmt::skip]
#[allow(unused_unsafe)]
#[auto_enum(Iterator)]
fn rec_in_block(x: usize) -> impl Iterator<Item = i32> {
Expand Down Expand Up @@ -668,7 +667,7 @@ fn nightly() {

// never attr
for (i, x) in ANS.iter().enumerate() {
#[cfg_attr(feature = "rustfmt", rustfmt_skip)]
#[rustfmt::skip]
#[auto_enum(Iterator)]
let iter = match i {
0 => 1..8,
Expand All @@ -693,7 +692,7 @@ fn nightly() {
assert_eq!(iter.sum::<i32>(), *x);
}
for (i, x) in ANS.iter().enumerate() {
#[cfg_attr(feature = "rustfmt", rustfmt_skip)]
#[rustfmt::skip]
#[auto_enum(Iterator)]
let iter = match i {
0 => 1..8,
Expand Down

0 comments on commit 3362945

Please sign in to comment.