Skip to content

Commit

Permalink
Syn update and 2021 (#188)
Browse files Browse the repository at this point in the history
* Update rstest_macros to syn 2.0

* switch macros, tests and base to 2021

* Syn 2.0.and edition 2021 for rstest_reuse

* Changelog
  • Loading branch information
la10736 committed Mar 20, 2023
1 parent 7ac624c commit 2f1ff25
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 30 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,12 @@
# Changelog

## Unreleased

### Changed

- Switch to `syn` 2.0 and edition 2021 : minimal Rust version now is 1.56.0
both for `rstest` and `rstest_reuse` (see #187)

## [0.17.0] 2023/3/19
### Add

Expand Down
2 changes: 1 addition & 1 deletion rstest/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ description = """
Rust fixture based test framework. It use procedural macro
to implement fixtures and table based tests.
"""
edition = "2018"
edition = "2021"
homepage = "https://github.com/la10736/rstest"
keywords = ["test", "fixture"]
license = "MIT/Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions rstest/tests/rstest/mod.rs
Expand Up @@ -1449,10 +1449,10 @@ mod should_show_correct_errors {
format!(
"
error: expected attribute arguments in parentheses: #[timeout(...)]
--> {}/src/lib.rs:97:1
--> {}/src/lib.rs:97:3
|
97 | #[timeout]
| ^^^^^^^^^^
| ^^^^^^^
",
name
)
Expand Down
4 changes: 2 additions & 2 deletions rstest_macros/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ description = """
Rust fixture based test framework. It use procedural macro
to implement fixtures and table based tests.
"""
edition = "2018"
edition = "2021"
homepage = "https://github.com/la10736/rstest"
keywords = ["test", "fixture"]
license = "MIT/Apache-2.0"
Expand All @@ -24,7 +24,7 @@ default = ["async-timeout"]
cfg-if = "1.0.0"
proc-macro2 = "1.0.39"
quote = "1.0.19"
syn = {version = "1.0.98", features = ["full", "parsing", "extra-traits", "visit", "visit-mut"]}
syn = {version = "2.0.2", features = ["full", "parsing", "extra-traits", "visit", "visit-mut"]}
unicode-ident = "1.0.5"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rstest_macros/src/parse/expressions.rs
Expand Up @@ -14,7 +14,7 @@ impl Expressions {
impl Parse for Expressions {
fn parse(input: ParseStream) -> Result<Self> {
let values = input
.parse_terminated::<_, Token![,]>(Parse::parse)?
.parse_terminated(Parse::parse, Token![,])?
.into_iter()
.collect();
Ok(Self(values))
Expand Down
2 changes: 1 addition & 1 deletion rstest_macros/src/parse/future.rs
Expand Up @@ -98,7 +98,7 @@ impl VisitMut for FutureFunctionExtractor {
node,
|a| attr_is(a, "future"),
|arg, name| {
let kind = if arg.tokens.is_empty() {
let kind = if matches!(arg.meta, syn::Meta::Path(_)) {
FutureArg::Define
} else {
match arg.parse_args::<Option<Ident>>()? {
Expand Down
8 changes: 4 additions & 4 deletions rstest_macros/src/parse/mod.rs
Expand Up @@ -322,7 +322,7 @@ impl VisitMut for PartialsTypeFunctionExtractor {
let (partials, remain): (Vec<_>, Vec<_>) =
attrs
.into_iter()
.partition(|attr| match attr.path.get_ident() {
.partition(|attr| match attr.path().get_ident() {
Some(name) => name
.to_string()
.starts_with(FixtureModifiers::PARTIAL_RET_ATTR),
Expand All @@ -335,7 +335,7 @@ impl VisitMut for PartialsTypeFunctionExtractor {
for attr in partials {
match attr.parse_args::<syn::Type>() {
Ok(t) => {
match attr.path.get_ident().unwrap().to_string()
match attr.path().get_ident().unwrap().to_string()
[FixtureModifiers::PARTIAL_RET_ATTR.len()..]
.parse()
{
Expand Down Expand Up @@ -383,7 +383,7 @@ impl VisitMut for IsOnceAttributeFunctionExtractor {

node.attrs = remain;
self.0 = match onces.len() {
1 => Ok(onces[0].path.get_ident().cloned()),
1 => Ok(onces[0].path().get_ident().cloned()),
0 => Ok(None),
_ => Err(onces
.into_iter()
Expand Down Expand Up @@ -439,7 +439,7 @@ impl VisitMut for CasesFunctionExtractor {
if attr_starts_with(&attr, &case) {
match attr.parse_args::<Expressions>() {
Ok(expressions) => {
let description = attr.path.segments.into_iter().nth(1).map(|p| p.ident);
let description = attr.path().segments.iter().nth(1).map(|p| p.ident.clone());
self.0.push(TestCase {
args: expressions.into(),
attrs: std::mem::take(&mut attrs_buffer),
Expand Down
2 changes: 1 addition & 1 deletion rstest_macros/src/parse/vlist.rs
Expand Up @@ -29,7 +29,7 @@ impl Parse for ValueList {
};
if ret.values.is_empty() {
Err(syn::Error::new(
paren.span,
paren.span.join(),
"Values list should not be empty",
))
} else {
Expand Down
2 changes: 1 addition & 1 deletion rstest_macros/src/refident.rs
Expand Up @@ -71,7 +71,7 @@ impl MaybeIdent for syn::GenericParam {
match self {
syn::GenericParam::Type(syn::TypeParam { ident, .. })
| syn::GenericParam::Const(syn::ConstParam { ident, .. }) => Some(ident),
syn::GenericParam::Lifetime(syn::LifetimeDef { lifetime, .. }) => Some(&lifetime.ident),
syn::GenericParam::Lifetime(syn::LifetimeParam { lifetime, .. }) => Some(&lifetime.ident),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions rstest_macros/src/render/fixture.rs
Expand Up @@ -193,12 +193,12 @@ mod should {
assert_eq!(item_fn.vis, out.orig.vis);
}

fn select_method<S: AsRef<str>>(impl_code: ItemImpl, name: S) -> Option<syn::ImplItemMethod> {
fn select_method<S: AsRef<str>>(impl_code: ItemImpl, name: S) -> Option<syn::ImplItemFn> {
impl_code
.items
.into_iter()
.filter_map(|ii| match ii {
syn::ImplItem::Method(f) => Some(f),
syn::ImplItem::Fn(f) => Some(f),
_ => None,
})
.find(|f| f.sig.ident == name.as_ref())
Expand Down Expand Up @@ -292,7 +292,7 @@ mod should {
let body = select_method(out.core_impl, method).unwrap().block;
let last_statment = body.stmts.last().unwrap();
let is_await = match last_statment {
syn::Stmt::Expr(syn::Expr::Await(_)) => true,
syn::Stmt::Expr(syn::Expr::Await(_), _) => true,
_ => false,
};

Expand Down
6 changes: 3 additions & 3 deletions rstest_macros/src/render/test.rs
Expand Up @@ -4,7 +4,7 @@ use syn::{
parse::{Parse, ParseStream, Result},
parse2, parse_str,
visit::Visit,
ItemFn, ItemMod,
ItemFn, ItemMod, LocalInit,
};

use super::*;
Expand Down Expand Up @@ -345,7 +345,7 @@ trait QueryAttrs {

impl QueryAttrs for ItemFn {
fn has_attr(&self, attr: &syn::Path) -> bool {
self.attrs.iter().find(|a| &a.path == attr).is_some()
self.attrs.iter().find(|a| a.path() == attr).is_some()
}

fn has_attr_that_ends_with(&self, name: &syn::PathSegment) -> bool {
Expand Down Expand Up @@ -477,7 +477,7 @@ impl<'ast> Visit<'ast> for Assignments {
match &assign {
syn::Local {
pat: syn::Pat::Ident(pat),
init: Some((_, expr)),
init: Some(LocalInit { expr, .. }),
..
} => {
self.0.insert(pat.ident.to_string(), expr.as_ref().clone());
Expand Down
2 changes: 1 addition & 1 deletion rstest_macros/src/test.rs
Expand Up @@ -289,7 +289,7 @@ pub(crate) trait IsAwait {
impl IsAwait for Stmt {
fn is_await(&self) -> bool {
match self {
Stmt::Expr(Expr::Await(_)) => true,
Stmt::Expr(Expr::Await(_), _) => true,
_ => false,
}
}
Expand Down
10 changes: 5 additions & 5 deletions rstest_macros/src/utils.rs
Expand Up @@ -25,21 +25,21 @@ pub(crate) fn fn_args(item_fn: &ItemFn) -> impl Iterator<Item = &FnArg> {
}

pub(crate) fn attr_ends_with(attr: &Attribute, segment: &syn::PathSegment) -> bool {
attr.path.segments.iter().last() == Some(segment)
attr.path().segments.iter().last() == Some(segment)
}

pub(crate) fn attr_starts_with(attr: &Attribute, segment: &syn::PathSegment) -> bool {
attr.path.segments.iter().next() == Some(segment)
attr.path().segments.iter().next() == Some(segment)
}

pub(crate) fn attr_is(attr: &Attribute, name: &str) -> bool {
attr.path.is_ident(&format_ident!("{}", name))
attr.path().is_ident(&format_ident!("{}", name))
}

pub(crate) fn attr_in(attr: &Attribute, names: &[&str]) -> bool {
names
.iter()
.any(|name| attr.path.is_ident(&format_ident!("{}", name)))
.any(|name| attr.path().is_ident(&format_ident!("{}", name)))
}

pub(crate) trait IsLiteralExpression {
Expand Down Expand Up @@ -97,7 +97,7 @@ impl MaybeIdent for syn::WherePredicate {
WherePredicate::Lifetime(syn::PredicateLifetime { lifetime, .. }) => {
Some(&lifetime.ident)
}
WherePredicate::Eq(_) => None,
_ => None,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions rstest_reuse/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ description = """
Reuse rstest attributes: create a set of tests and apply it
to every scenario you want to test.
"""
edition = "2018"
edition = "2021"
homepage = "https://github.com/la10736/rstest"
keywords = ["test", "fixture"]
license = "MIT/Apache-2.0"
Expand All @@ -22,7 +22,7 @@ proc-macro = true
[dependencies]
quote = "1.0.9"
rand = "0.8.5"
syn = {version = "1.0.72", features = ["full"]}
syn = {version = "2.0.2", features = ["full", "extra-traits"]}

[dev-dependencies]
lazy_static = "1.4.0"
Expand Down
4 changes: 2 additions & 2 deletions rstest_reuse/src/lib.rs
Expand Up @@ -307,7 +307,7 @@ pub fn merge_attrs(item: TokenStream) -> TokenStream {
fn get_export(attributes: &[Attribute]) -> Option<&Attribute> {
attributes
.iter()
.find(|&attr| attr.path.is_ident(&format_ident!("export")))
.find(|&attr| attr.path().is_ident(&format_ident!("export")))
}

/// Define a template where the name is given from the function name. This attribute register all
Expand All @@ -328,7 +328,7 @@ pub fn template(_args: proc_macro::TokenStream, input: proc_macro::TokenStream)
let rstest_index = template
.attrs
.iter()
.position(|attr| attr.path.is_ident(&format_ident!("rstest")));
.position(|attr| attr.path().is_ident(&format_ident!("rstest")));

let mut attributes = template.attrs;

Expand Down
2 changes: 1 addition & 1 deletion rstest_test/Cargo.toml
Expand Up @@ -4,7 +4,7 @@ categories = ["development-tools::testing"]
description = """
Provides some utilities used by to write rstest crate's tests.
"""
edition = "2018"
edition = "2021"
homepage = "https://github.com/la10736/rstest"
keywords = ["test"]
license = "MIT/Apache-2.0"
Expand Down

0 comments on commit 2f1ff25

Please sign in to comment.