Skip to content

Commit

Permalink
Tune up lints for 1.66 Rust
Browse files Browse the repository at this point in the history
- refactor some public APIs to satisfy Clippy lints
- add `Cucumber::with_default_cli()` method
- omit disabling test harness asap
  • Loading branch information
tyranron committed Dec 16, 2022
1 parent bcf6d2e commit 56456e6
Show file tree
Hide file tree
Showing 37 changed files with 296 additions and 183 deletions.
11 changes: 11 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ standard-macro-braces = [
{ name = "assert", brace = "(" },
{ name = "assert_eq", brace = "(" },
{ name = "assert_ne", brace = "(" },
{ name = "debug_assert", brace = "(" },
{ name = "debug_assert_eq", brace = "(" },
{ name = "debug_assert_ne", brace = "(" },
{ name = "format", brace = "(" },
{ name = "format_args", brace = "(" },
{ name = "format_ident", brace = "(" },
{ name = "matches", brace = "(" },
{ name = "panic", brace = "(" },
{ name = "parse_quote", brace = "{" },
{ name = "print", brace = "(" },
{ name = "println", brace = "(" },
{ name = "quote", brace = "{" },
{ name = "quote_spanned", brace = "{" },
{ name = "vec", brace = "[" },
{ name = "write", brace = "(" },
{ name = "writeln", brace = "(" },
]
25 changes: 6 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ jobs:
crate:
- cucumber-codegen
- cucumber
os:
- ubuntu
- macOS
- windows
os: ["ubuntu", "macOS", "windows"]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -135,14 +132,8 @@ jobs:
crate:
- cucumber-codegen
- cucumber
os:
- ubuntu
- macOS
- windows
toolchain:
- stable
- beta
- nightly
toolchain: ["stable", "beta", "nightly"]
os: ["ubuntu", "macOS", "windows"]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -164,10 +155,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- ubuntu
- macOS
- windows
os: ["ubuntu", "macOS", "windows"]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -202,6 +190,8 @@ jobs:
- run: make cargo.doc crate=${{ matrix.crate }}
private=yes docsrs=yes
open=no
env:
RUSTFLAGS: -D warnings



Expand All @@ -225,9 +215,6 @@ jobs:
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATESIO_TOKEN }}

- name: Wait crates.io index is updated
run: sleep 120

- run: cargo publish -p cucumber
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATESIO_TOKEN }}
Expand Down
21 changes: 17 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,28 @@ All user visible changes to `cucumber` crate will be documented in this file. Th



## [0.18.1] · 2022-??-??
[0.18.1]: /../../tree/v0.18.1
## [0.19.0] · 2022-??-??
[0.19.0]: /../../tree/v0.19.0

[Diff](/../../compare/v0.18.0...v0.18.1) | [Milestone](/../../milestone/22)
[Diff](/../../compare/v0.18.0...v0.19.0) | [Milestone](/../../milestone/22)

### BC Breaks

- Replaced `writer::FailOnSkipped::writer` field with `writer::FailOnSkipped::inner_writer()` method. ([commit])
- Replaced `writer::Normalized::writer` field with `writer::Normalized::inner_writer()` method. ([commit])
- Replaced `writer::Or::left`/`writer::Or::right` fields with `writer::Or::left_writer()`/`writer::Or::right_writer()` methods. ([commit])
- Replaced `writer::Repeat::writer` field with `writer::Repeat::inner_writer()` method. ([commit])
- Replaced `writer::Summarize::writer` field with `writer::Summarize::inner_writer()` method. ([commit])
- Replaced `writer::Summarize::scenarios`/`writer::Summarize::steps` fields with `writer::Summarize::scenarios_stats()`/`writer::Summarize::steps_stats()` methods. ([commit])
- Made `writer::Summarize::features`/`writer::Summarize::rules` fields private. ([commit])
- Made `writer::Summarize::parsing_errors`/`writer::Summarize::failed_hooks` fields private in favour of `writer::Stats::parsing_errors()`/`writer::Stats::failed_hooks()` methods. ([commit])

### Added

- [Gherkin] syntax highlighting in the Book. ([#251])
- [Gherkin] syntax highlighting in the Book. ([#251])
- `runner::Basic::fail_fast()` method as `Cucumber::fail_fast()`. ([#252])
- `Cucumber::with_default_cli()` method. ([commit])
- `Default` implementation for CLI types. ([commit])

### Fixed

Expand Down
38 changes: 3 additions & 35 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repository = "https://github.com/cucumber-rs/cucumber"
readme = "README.md"
categories = ["asynchronous", "development-tools::testing"]
keywords = ["cucumber", "testing", "bdd", "atdd", "async"]
include = ["/src/", "/tests/after_hook.rs", "/tests/fail_fast.rs", "/tests/from_str_and_parameter.rs", "/tests/json.rs", "/tests/junit.rs", "/tests/libtest.rs", "/tests/result.rs", "/tests/retry.rs", "/tests/retry_fail_fast.rs", "/tests/retry_fail_on_skipped.rs", "/tests/wait.rs", "/LICENSE-*", "/README.md", "/CHANGELOG.md"]
include = ["/src/", "/tests/json.rs", "/tests/junit.rs", "/tests/libtest.rs", "/tests/wait.rs", "/LICENSE-*", "/README.md", "/CHANGELOG.md"]

[package.metadata.docs.rs]
all-features = true
Expand Down Expand Up @@ -52,9 +52,10 @@ globwalk = "0.8.1"
humantime = "2.1"
itertools = "0.10"
linked-hash-map = "0.5.3"
once_cell = "1.8"
once_cell = "1.13"
regex = "1.5.5"
sealed = "0.4"
smart-default = "0.6"

# "macros" feature dependencies.
anyhow = { version = "1.0.58", optional = true }
Expand All @@ -72,54 +73,21 @@ junit-report = { version = "0.8", optional = true }

[dev-dependencies]
derive_more = "0.99.17"
humantime = "2.1"
once_cell = "1.13"
rand = "0.8"
tempfile = "3.2"
tokio = { version = "1.12", features = ["macros", "rt-multi-thread", "sync", "time"] }

[[test]]
name = "after_hook"
harness = false

[[test]]
name = "fail_fast"
harness = false

[[test]]
name = "from_str_and_parameter"
harness = false

[[test]]
name = "json"
required-features = ["output-json"]
harness = false

[[test]]
name = "junit"
required-features = ["output-junit"]
harness = false

[[test]]
name = "libtest"
required-features = ["libtest"]
harness = false

[[test]]
name = "result"
harness = false

[[test]]
name = "retry"
harness = false

[[test]]
name = "retry_fail_fast"
harness = false

[[test]]
name = "retry_fail_on_skipped"
harness = false

[[test]]
name = "wait"
Expand Down
3 changes: 3 additions & 0 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#![forbid(non_ascii_idents, unsafe_code)]
#![warn(
clippy::as_conversions,
clippy::as_ptr_cast_mut,
clippy::assertions_on_result_states,
clippy::branches_sharing_code,
clippy::clone_on_ref_ptr,
Expand All @@ -33,6 +34,7 @@
clippy::debug_assert_with_mut_call,
clippy::decimal_literal_representation,
clippy::default_union_representation,
clippy::derive_partial_eq_without_eq,
clippy::else_if_without_else,
clippy::empty_drop,
clippy::empty_line_after_outer_attr,
Expand Down Expand Up @@ -65,6 +67,7 @@
clippy::nonstandard_macro_braces,
clippy::option_if_let_else,
clippy::panic_in_result_fn,
clippy::partial_pub_fields,
clippy::pedantic,
clippy::print_stderr,
clippy::print_stdout,
Expand Down
5 changes: 2 additions & 3 deletions codegen/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ impl Definition {
};

/// Generates code of implementing a `WorldInventory` trait.
#[allow(clippy::similar_names)] // because of `when_ty` vs `then_ty`
fn impl_world_inventory(&self) -> TokenStream {
let world = &self.ident;
let (impl_gens, ty_gens, where_clause) = self.generics.split_for_impl();

let (given_ty, when_ty, then_ty) = self
let (given_ty, when_step_ty, then_ty) = self
.step_types()
.collect_tuple()
.unwrap_or_else(|| unreachable!("{:?}", Self::EXACTLY_3_STEPS));
Expand All @@ -103,7 +102,7 @@ impl Definition {
#where_clause
{
type Given = #given_ty;
type When = #when_ty;
type When = #when_step_ty;
type Then = #then_ty;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub use clap::{Args, Parser};
/// [`Parser`]: crate::Parser
/// [`Runner`]: crate::Runner
/// [`Writer`]: crate::Writer
#[derive(Debug, Clone, clap::Parser)]
#[derive(clap::Parser, Clone, Debug, Default)]
#[command(
name = "cucumber",
about = "Run the tests, pet a dog!",
Expand Down Expand Up @@ -169,7 +169,7 @@ pub trait Colored {
}

/// Empty CLI options.
#[derive(Args, Clone, Copy, Debug)]
#[derive(Args, Clone, Copy, Debug, Default)]
#[group(skip)]
pub struct Empty;

Expand Down Expand Up @@ -269,7 +269,7 @@ impl Colored for Empty {}
/// ```
///
/// [`Writer`]: crate::Writer
#[derive(Args, Clone, Copy, Debug)]
#[derive(Args, Clone, Copy, Debug, Default)]
#[group(skip)]
pub struct Compose<L: Args, R: Args> {
/// Left [`clap::Args`] deriver.
Expand All @@ -291,6 +291,7 @@ impl<L: Args, R: Args> Compose<L, R> {
}
}

#[warn(clippy::missing_trait_methods)]
impl<L, R> Colored for Compose<L, R>
where
L: Args + Colored,
Expand Down
2 changes: 0 additions & 2 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ pub trait Parameter {
///
/// Validated during [`Parameter`](macro@crate::Parameter) derive macro
/// expansion.
///
/// [`Regex`]: regex::Regex
const REGEX: &'static str;

/// Name of this [`Parameter`] to be referenced by in
Expand Down
26 changes: 21 additions & 5 deletions src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ where
///
/// [`Feature`]: gherkin::Feature
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
#[must_use]
pub fn with_cli<CustomCli>(
self,
cli: cli::Opts<P::Cli, R::Cli, Wr::Cli, CustomCli>,
Expand All @@ -654,6 +655,19 @@ where
}
}

/// Initializes [`Default`] [`cli::Opts`].
///
/// This method allows to omit parsing real [`cli::Opts`], as eagerly
/// initializes [`Default`] ones instead.
#[must_use]
pub fn with_default_cli(mut self) -> Self
where
cli::Opts<P::Cli, R::Cli, Wr::Cli, Cli>: Default,
{
self.cli = Some(cli::Opts::default());
self
}

/// Runs [`Cucumber`] with [`Scenario`]s filter.
///
/// [`Feature`]s sourced from a [`Parser`] are fed to a [`Runner`], which
Expand Down Expand Up @@ -809,15 +823,19 @@ impl<W, P, I, R, Wr, Cli> Debug for Cucumber<W, P, I, R, Wr, Cli>
where
W: World,
P: Debug + Parser<I>,
<P as Parser<I>>::Cli: Debug,
R: Debug + Runner<W>,
<R as Runner<W>>::Cli: Debug,
Wr: Debug + Writer<W>,
Cli: clap::Args,
<Wr as Writer<W>>::Cli: Debug,
Cli: clap::Args + Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Cucumber")
.field("parser", &self.parser)
.field("runner", &self.runner)
.field("writer", &self.writer)
.field("cli", &self.cli)
.finish()
}
}
Expand Down Expand Up @@ -861,12 +879,10 @@ where
///
/// * [`Writer`] — [`Normalize`] and [`Summarize`] [`writer::Basic`].
///
/// [`Concurrent`]: runner::basic::ScenarioType::Concurrent
/// [`Concurrent`]: ScenarioType::Concurrent
/// [`Normalize`]: writer::Normalize
/// [`Parser`]: parser::Parser
/// [`Scenario`]: gherkin::Scenario
/// [`Serial`]: runner::basic::ScenarioType::Serial
/// [`ScenarioType`]: runner::basic::ScenarioType
/// [`Serial`]: ScenarioType::Serial
/// [`Summarize`]: writer::Summarize
///
/// [tag]: https://cucumber.io/docs/cucumber/api#tags
Expand Down
5 changes: 1 addition & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// TODO: Only because of `derive_more` macros, try to remove on next
// `derive_more` upgrade.
#![allow(clippy::use_self)]

//! Key occurrences in a lifecycle of [Cucumber] execution.
//!
//! The top-level enum here is [`Cucumber`].
Expand Down Expand Up @@ -443,6 +439,7 @@ pub enum HookType {
After,
}

#[allow(clippy::use_debug)] // `Debug` usage is intentional here
impl fmt::Display for HookType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
Expand Down
Loading

0 comments on commit 56456e6

Please sign in to comment.