Skip to content

Commit

Permalink
Upgrade to 1.61 Rust and bump up MSRV
Browse files Browse the repository at this point in the history
- simplify codegen due to better const evaluation
- tune up lints
  • Loading branch information
tyranron committed May 20, 2022
1 parent fbd08ec commit cf055ac
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
strategy:
fail-fast: false
matrix:
msrv: ["1.60.0"]
msrv: ["1.61.0"]
crate:
- cucumber-codegen
- cucumber
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ All user visible changes to `cucumber` crate will be documented in this file. Th

### BC Breaks

- Bump up [MSRV] to 1.60 for more clever support of [Cargo feature]s.
- Bump up [MSRV] to 1.61 for more clever support of [Cargo feature]s and simplified codegen.



Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "cucumber"
version = "0.14.0-dev"
edition = "2021"
rust-version = "1.60"
rust-version = "1.61"
description = """\
Cucumber testing framework for Rust, with async support. \
Fully native, no external test runners or dependencies.\
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Cucumber testing framework for Rust
[![Crates.io](https://img.shields.io/crates/v/cucumber.svg?maxAge=2592000)](https://crates.io/crates/cucumber)
[![Documentation](https://docs.rs/cucumber/badge.svg)](https://docs.rs/cucumber)
[![CI](https://github.com/cucumber-rs/cucumber/workflows/CI/badge.svg?branch=main "CI")](https://github.com/cucumber-rs/cucumber/actions?query=workflow%3ACI+branch%3Amain)
[![Rust 1.60+](https://img.shields.io/badge/rustc-1.60+-lightgray.svg "Rust 1.60+")](https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html)
[![Rust 1.61+](https://img.shields.io/badge/rustc-1.61+-lightgray.svg "Rust 1.61+")](https://blog.rust-lang.org/2022/05/19/Rust-1.61.0.html)
[![Unsafe Forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance)

An implementation of the [Cucumber] testing framework for Rust. Fully native, no external test runners or dependencies.
Expand Down
2 changes: 1 addition & 1 deletion codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ All user visible changes to `cucumber-codegen` crate will be documented in this

### BC Breaks

- Bump up [MSRV] to 1.60 for more clever support of [Cargo feature]s.
- Bump up [MSRV] to 1.61 for more clever support of [Cargo feature]s and simplified codegen.



Expand Down
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "cucumber-codegen"
version = "0.14.0-dev" # should be the same as main crate version
edition = "2021"
rust-version = "1.60"
rust-version = "1.61"
description = "Code generation for `cucumber` crate."
license = "MIT OR Apache-2.0"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Crates.io](https://img.shields.io/crates/v/cucumber-codegen.svg?maxAge=2592000)](https://crates.io/crates/cucumber-codegen)
[![Documentation](https://docs.rs/cucumber-codegen/badge.svg)](https://docs.rs/cucumber-codegen)
[![CI](https://github.com/cucumber-rs/cucumber/workflows/CI/badge.svg?branch=main "CI")](https://github.com/cucumber-rs/cucumber/actions?query=workflow%3ACI+branch%3Amain)
[![Rust 1.60+](https://img.shields.io/badge/rustc-1.60+-lightgray.svg "Rust 1.60+")](https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html)
[![Rust 1.61+](https://img.shields.io/badge/rustc-1.61+-lightgray.svg "Rust 1.61+")](https://blog.rust-lang.org/2022/05/19/Rust-1.61.0.html)
[![Unsafe Forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance)

- [Changelog](https://github.com/cucumber-rs/cucumber/blob/main/codegen/CHANGELOG.md)
Expand Down
54 changes: 13 additions & 41 deletions codegen/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,9 @@ impl Step {

let regex = self.gen_regex()?;

let caller_name =
format_ident!("__cucumber_{}_{func_name}", self.attr_name);
let awaiting = func.sig.asyncness.map(|_| quote! { .await });
let unwrapping = (!self.returns_unit())
.then(|| quote! { .unwrap_or_else(|e| panic!("{}", e)) });
let step_caller = quote! {
{
#[automatically_derived]
fn #caller_name<'w>(
__cucumber_world: &'w mut #world,
__cucumber_ctx: ::cucumber::step::Context,
) -> ::cucumber::codegen::LocalBoxFuture<'w, ()> {
let f = async move {
#addon_parsing
let _ = #func_name(__cucumber_world, #func_args)
#awaiting
#unwrapping;
};
::std::boxed::Box::pin(f)
}

let f: ::cucumber::Step<#world> = #caller_name;
f
}
};

Ok(quote! {
#func
Expand All @@ -156,26 +134,20 @@ impl Step {
line: ::std::line!(),
column: ::std::column!(),
},
regex: {
// This hack exists, as `fn item` to `fn pointer`
// coercion can be done inside `const`, but not
// `const fn`.
let lazy: ::cucumber::codegen::LazyRegex = || {
static LAZY: ::cucumber::codegen::Lazy<
::cucumber::codegen::Regex
> = ::cucumber::codegen::Lazy::new(|| {
#regex
});
LAZY.clone()
};
lazy
regex: || {
static LAZY: ::cucumber::codegen::Lazy<
::cucumber::codegen::Regex
> = ::cucumber::codegen::Lazy::new(|| { #regex });
LAZY.clone()
},
func: {
// This hack exists, as `fn item` to `fn pointer`
// coercion can be done inside `const`, but not
// `const fn`.
const F: ::cucumber::Step<#world> = #step_caller;
F
func: |__cucumber_world, __cucumber_ctx| {
let f = async move {
#addon_parsing
let _ = #func_name(__cucumber_world, #func_args)
#awaiting
#unwrapping;
};
::std::boxed::Box::pin(f)
},
}
});
Expand Down
3 changes: 3 additions & 0 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
clippy::if_then_some_else_none,
clippy::imprecise_flops,
clippy::index_refutable_slice,
clippy::iter_with_drain,
clippy::let_underscore_must_use,
clippy::lossy_float_literal,
clippy::map_err_ignore,
Expand All @@ -54,6 +55,7 @@
clippy::mutex_atomic,
clippy::mutex_integer,
clippy::nonstandard_macro_braces,
clippy::only_used_in_recursion,
clippy::option_if_let_else,
clippy::panic_in_result_fn,
clippy::pedantic,
Expand All @@ -75,6 +77,7 @@
clippy::trailing_empty_array,
clippy::transmute_undefined_repr,
clippy::trivial_regex,
clippy::try_err,
clippy::undocumented_unsafe_blocks,
clippy::unimplemented,
clippy::unnecessary_self_imports,
Expand Down
1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ pub struct Compose<L: Args, R: Args> {

impl<L: Args, R: Args> Compose<L, R> {
/// Unpacks this [`Compose`] into the underlying CLIs.
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
#[must_use]
pub fn into_inner(self) -> (L, R) {
let Compose { left, right } = self;
Expand Down
6 changes: 5 additions & 1 deletion src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
/// Creates a custom [`Cucumber`] executor with the provided [`Parser`],
/// [`Runner`] and [`Writer`].
#[must_use]
pub fn custom(parser: P, runner: R, writer: Wr) -> Self {
pub const fn custom(parser: P, runner: R, writer: Wr) -> Self {
Self {
parser,
runner,
Expand All @@ -104,6 +104,7 @@ where
}

/// Replaces [`Parser`].
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
#[must_use]
pub fn with_parser<NewP, NewI>(
self,
Expand All @@ -124,6 +125,7 @@ where
}

/// Replaces [`Runner`].
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
#[must_use]
pub fn with_runner<NewR>(
self,
Expand All @@ -144,6 +146,7 @@ where
}

/// Replaces [`Writer`].
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
#[must_use]
pub fn with_writer<NewWr>(
self,
Expand Down Expand Up @@ -716,6 +719,7 @@ where
/// Also, specifying `--help` flag will describe `--before-time` now.
///
/// [`Feature`]: gherkin::Feature
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
pub fn with_cli<CustomCli>(
self,
cli: cli::Opts<P::Cli, R::Cli, Wr::Cli, CustomCli>,
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
clippy::if_then_some_else_none,
clippy::imprecise_flops,
clippy::index_refutable_slice,
clippy::iter_with_drain,
clippy::let_underscore_must_use,
clippy::lossy_float_literal,
clippy::map_err_ignore,
Expand All @@ -56,6 +57,7 @@
clippy::mutex_atomic,
clippy::mutex_integer,
clippy::nonstandard_macro_braces,
clippy::only_used_in_recursion,
clippy::option_if_let_else,
clippy::panic_in_result_fn,
clippy::pedantic,
Expand All @@ -77,6 +79,7 @@
clippy::trailing_empty_array,
clippy::transmute_undefined_repr,
clippy::trivial_regex,
clippy::try_err,
clippy::undocumented_unsafe_blocks,
clippy::unimplemented,
clippy::unnecessary_self_imports,
Expand Down
5 changes: 4 additions & 1 deletion src/runner/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl<World, Which, Before, After> Basic<World, Which, Before, After> {
/// [`Concurrent`]: ScenarioType::Concurrent
/// [`Serial`]: ScenarioType::Serial
/// [`Scenario`]: gherkin::Scenario
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
#[must_use]
pub fn which_scenario<F>(self, func: F) -> Basic<World, F, Before, After>
where
Expand Down Expand Up @@ -275,6 +276,7 @@ impl<World, Which, Before, After> Basic<World, Which, Before, After> {
/// [`Background`]: gherkin::Background
/// [`Scenario`]: gherkin::Scenario
/// [`Step`]: gherkin::Step
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
#[must_use]
pub fn before<Func>(self, func: Func) -> Basic<World, Which, Func, After>
where
Expand Down Expand Up @@ -314,6 +316,7 @@ impl<World, Which, Before, After> Basic<World, Which, Before, After> {
/// [`Scenario`]: gherkin::Scenario
/// [`Skipped`]: event::Step::Skipped
/// [`Step`]: gherkin::Step
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
#[must_use]
pub fn after<Func>(self, func: Func) -> Basic<World, Which, Before, Func>
where
Expand Down Expand Up @@ -678,7 +681,7 @@ where
) -> LocalBoxFuture<'a, ()>,
{
/// Creates a new [`Executor`].
fn new(
const fn new(
collection: step::Collection<W>,
before_hook: Option<Before>,
after_hook: Option<After>,
Expand Down
3 changes: 2 additions & 1 deletion src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ impl<World> Collection<World> {
}
};

// All indices here are obtained from the source string.
// PANIC: Slicing is OK here, as all indices are obtained from the
// source string.
#[allow(clippy::string_slice)]
let matches = names
.map(|opt| opt.map(str::to_owned))
Expand Down
3 changes: 2 additions & 1 deletion src/writer/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,8 @@ where
D: for<'a> Fn(&'a str) -> Cow<'a, str>,
A: for<'a> Fn(&'a str) -> Cow<'a, str>,
{
// All indices here are obtained from the source string.
// PANIC: Slicing is OK here, as all indices are obtained from the source
// string.
#![allow(clippy::string_slice)]

let value = value.as_ref();
Expand Down
5 changes: 4 additions & 1 deletion src/writer/fail_on_skipped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ impl<Writer> FailOnSkipped<Writer> {
/// [`Skipped`]: event::Step::Skipped
/// [`Step`]: gherkin::Step
#[must_use]
pub fn with<P>(writer: Writer, predicate: P) -> FailOnSkipped<Writer, P>
pub const fn with<P>(
writer: Writer,
predicate: P,
) -> FailOnSkipped<Writer, P>
where
P: Fn(
&gherkin::Feature,
Expand Down
62 changes: 37 additions & 25 deletions src/writer/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<Out: io::Write> Json<Out> {
/// [1]: https://github.com/cucumber/cucumber-json-schema
/// [2]: crate::event::Cucumber
#[must_use]
pub fn raw(output: Out) -> Self {
pub const fn raw(output: Out) -> Self {
Self {
output,
features: Vec::new(),
Expand Down Expand Up @@ -371,30 +371,42 @@ pub struct Tag {
pub line: usize,
}

/// Possible statuses of running [`gherkin::Step`].
#[derive(Clone, Copy, Debug, Serialize)]
pub enum Status {
/// [`event::Step::Passed`].
Passed,

/// [`event::Step::Failed`] with an [`event::StepError::Panic`].
Failed,

/// [`event::Step::Skipped`].
Skipped,

/// [`event::Step::Failed`] with an [`event::StepError::AmbiguousMatch`].
Ambiguous,

/// Never constructed and is here only to fully describe [JSON schema][1].
///
/// [1]: https://github.com/cucumber/cucumber-json-schema
Undefined,

/// Never constructed and is here only to fully describe [JSON schema][1].
///
/// [1]: https://github.com/cucumber/cucumber-json-schema
Pending,
pub use self::status::Status;

/// TODO: Only because of [`Serialize`] deriving, try to remove on next
/// [`serde`] update.
#[allow(clippy::use_self, clippy::wildcard_imports)]
mod status {
use super::*;

/// Possible statuses of running [`gherkin::Step`].
#[derive(Clone, Copy, Debug, Serialize)]
pub enum Status {
/// [`event::Step::Passed`].
Passed,

/// [`event::Step::Failed`] with an [`event::StepError::Panic`].
Failed,

/// [`event::Step::Skipped`].
Skipped,

/// [`event::Step::Failed`] with an
/// [`event::StepError::AmbiguousMatch`].
Ambiguous,

/// Never constructed and is here only to fully describe
/// [JSON schema][1].
///
/// [1]: https://github.com/cucumber/cucumber-json-schema
Undefined,

/// Never constructed and is here only to fully describe
/// [JSON schema][1].
///
/// [1]: https://github.com/cucumber/cucumber-json-schema
Pending,
}
}

/// [`Serialize`]able result of running something.
Expand Down
2 changes: 1 addition & 1 deletion src/writer/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<K: Eq + Hash, V> Queue<K, V> {
/// Checks whether this [`Queue`] transited to [`FinishedAndEmitted`] state.
///
/// [`FinishedAndEmitted`]: FinishedState::FinishedAndEmitted
fn is_finished_and_emitted(&self) -> bool {
const fn is_finished_and_emitted(&self) -> bool {
matches!(self.state, FinishedState::FinishedAndEmitted)
}

Expand Down

0 comments on commit cf055ac

Please sign in to comment.