Skip to content

Commit 56456e6

Browse files
committed
Tune up lints for 1.66 Rust
- refactor some public APIs to satisfy Clippy lints - add `Cucumber::with_default_cli()` method - omit disabling test harness asap
1 parent bcf6d2e commit 56456e6

37 files changed

+296
-183
lines changed

.clippy.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ standard-macro-braces = [
88
{ name = "assert", brace = "(" },
99
{ name = "assert_eq", brace = "(" },
1010
{ name = "assert_ne", brace = "(" },
11+
{ name = "debug_assert", brace = "(" },
12+
{ name = "debug_assert_eq", brace = "(" },
13+
{ name = "debug_assert_ne", brace = "(" },
1114
{ name = "format", brace = "(" },
15+
{ name = "format_args", brace = "(" },
1216
{ name = "format_ident", brace = "(" },
17+
{ name = "matches", brace = "(" },
1318
{ name = "panic", brace = "(" },
19+
{ name = "parse_quote", brace = "{" },
20+
{ name = "print", brace = "(" },
21+
{ name = "println", brace = "(" },
1422
{ name = "quote", brace = "{" },
23+
{ name = "quote_spanned", brace = "{" },
1524
{ name = "vec", brace = "[" },
25+
{ name = "write", brace = "(" },
26+
{ name = "writeln", brace = "(" },
1627
]

.github/workflows/ci.yml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ jobs:
109109
crate:
110110
- cucumber-codegen
111111
- cucumber
112-
os:
113-
- ubuntu
114-
- macOS
115-
- windows
112+
os: ["ubuntu", "macOS", "windows"]
116113
runs-on: ${{ matrix.os }}-latest
117114
steps:
118115
- uses: actions/checkout@v3
@@ -135,14 +132,8 @@ jobs:
135132
crate:
136133
- cucumber-codegen
137134
- cucumber
138-
os:
139-
- ubuntu
140-
- macOS
141-
- windows
142-
toolchain:
143-
- stable
144-
- beta
145-
- nightly
135+
toolchain: ["stable", "beta", "nightly"]
136+
os: ["ubuntu", "macOS", "windows"]
146137
runs-on: ${{ matrix.os }}-latest
147138
steps:
148139
- uses: actions/checkout@v3
@@ -164,10 +155,7 @@ jobs:
164155
strategy:
165156
fail-fast: false
166157
matrix:
167-
os:
168-
- ubuntu
169-
- macOS
170-
- windows
158+
os: ["ubuntu", "macOS", "windows"]
171159
runs-on: ${{ matrix.os }}-latest
172160
steps:
173161
- uses: actions/checkout@v3
@@ -202,6 +190,8 @@ jobs:
202190
- run: make cargo.doc crate=${{ matrix.crate }}
203191
private=yes docsrs=yes
204192
open=no
193+
env:
194+
RUSTFLAGS: -D warnings
205195

206196

207197

@@ -225,9 +215,6 @@ jobs:
225215
env:
226216
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATESIO_TOKEN }}
227217

228-
- name: Wait crates.io index is updated
229-
run: sleep 120
230-
231218
- run: cargo publish -p cucumber
232219
env:
233220
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATESIO_TOKEN }}

CHANGELOG.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,28 @@ All user visible changes to `cucumber` crate will be documented in this file. Th
66

77

88

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

12-
[Diff](/../../compare/v0.18.0...v0.18.1) | [Milestone](/../../milestone/22)
12+
[Diff](/../../compare/v0.18.0...v0.19.0) | [Milestone](/../../milestone/22)
13+
14+
### BC Breaks
15+
16+
- Replaced `writer::FailOnSkipped::writer` field with `writer::FailOnSkipped::inner_writer()` method. ([commit])
17+
- Replaced `writer::Normalized::writer` field with `writer::Normalized::inner_writer()` method. ([commit])
18+
- Replaced `writer::Or::left`/`writer::Or::right` fields with `writer::Or::left_writer()`/`writer::Or::right_writer()` methods. ([commit])
19+
- Replaced `writer::Repeat::writer` field with `writer::Repeat::inner_writer()` method. ([commit])
20+
- Replaced `writer::Summarize::writer` field with `writer::Summarize::inner_writer()` method. ([commit])
21+
- Replaced `writer::Summarize::scenarios`/`writer::Summarize::steps` fields with `writer::Summarize::scenarios_stats()`/`writer::Summarize::steps_stats()` methods. ([commit])
22+
- Made `writer::Summarize::features`/`writer::Summarize::rules` fields private. ([commit])
23+
- Made `writer::Summarize::parsing_errors`/`writer::Summarize::failed_hooks` fields private in favour of `writer::Stats::parsing_errors()`/`writer::Stats::failed_hooks()` methods. ([commit])
1324

1425
### Added
1526

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

1932
### Fixed
2033

Cargo.toml

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repository = "https://github.com/cucumber-rs/cucumber"
1919
readme = "README.md"
2020
categories = ["asynchronous", "development-tools::testing"]
2121
keywords = ["cucumber", "testing", "bdd", "atdd", "async"]
22-
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"]
22+
include = ["/src/", "/tests/json.rs", "/tests/junit.rs", "/tests/libtest.rs", "/tests/wait.rs", "/LICENSE-*", "/README.md", "/CHANGELOG.md"]
2323

2424
[package.metadata.docs.rs]
2525
all-features = true
@@ -52,9 +52,10 @@ globwalk = "0.8.1"
5252
humantime = "2.1"
5353
itertools = "0.10"
5454
linked-hash-map = "0.5.3"
55-
once_cell = "1.8"
55+
once_cell = "1.13"
5656
regex = "1.5.5"
5757
sealed = "0.4"
58+
smart-default = "0.6"
5859

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

7374
[dev-dependencies]
7475
derive_more = "0.99.17"
75-
humantime = "2.1"
76-
once_cell = "1.13"
7776
rand = "0.8"
7877
tempfile = "3.2"
7978
tokio = { version = "1.12", features = ["macros", "rt-multi-thread", "sync", "time"] }
8079

81-
[[test]]
82-
name = "after_hook"
83-
harness = false
84-
85-
[[test]]
86-
name = "fail_fast"
87-
harness = false
88-
89-
[[test]]
90-
name = "from_str_and_parameter"
91-
harness = false
92-
9380
[[test]]
9481
name = "json"
9582
required-features = ["output-json"]
96-
harness = false
9783

9884
[[test]]
9985
name = "junit"
10086
required-features = ["output-junit"]
101-
harness = false
10287

10388
[[test]]
10489
name = "libtest"
10590
required-features = ["libtest"]
106-
harness = false
107-
108-
[[test]]
109-
name = "result"
110-
harness = false
111-
112-
[[test]]
113-
name = "retry"
114-
harness = false
115-
116-
[[test]]
117-
name = "retry_fail_fast"
118-
harness = false
119-
120-
[[test]]
121-
name = "retry_fail_on_skipped"
122-
harness = false
12391

12492
[[test]]
12593
name = "wait"

codegen/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![forbid(non_ascii_idents, unsafe_code)]
2626
#![warn(
2727
clippy::as_conversions,
28+
clippy::as_ptr_cast_mut,
2829
clippy::assertions_on_result_states,
2930
clippy::branches_sharing_code,
3031
clippy::clone_on_ref_ptr,
@@ -33,6 +34,7 @@
3334
clippy::debug_assert_with_mut_call,
3435
clippy::decimal_literal_representation,
3536
clippy::default_union_representation,
37+
clippy::derive_partial_eq_without_eq,
3638
clippy::else_if_without_else,
3739
clippy::empty_drop,
3840
clippy::empty_line_after_outer_attr,
@@ -65,6 +67,7 @@
6567
clippy::nonstandard_macro_braces,
6668
clippy::option_if_let_else,
6769
clippy::panic_in_result_fn,
70+
clippy::partial_pub_fields,
6871
clippy::pedantic,
6972
clippy::print_stderr,
7073
clippy::print_stdout,

codegen/src/world.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ impl Definition {
8686
};
8787

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

94-
let (given_ty, when_ty, then_ty) = self
93+
let (given_ty, when_step_ty, then_ty) = self
9594
.step_types()
9695
.collect_tuple()
9796
.unwrap_or_else(|| unreachable!("{:?}", Self::EXACTLY_3_STEPS));
@@ -103,7 +102,7 @@ impl Definition {
103102
#where_clause
104103
{
105104
type Given = #given_ty;
106-
type When = #when_ty;
105+
type When = #when_step_ty;
107106
type Then = #then_ty;
108107
}
109108
}

src/cli.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub use clap::{Args, Parser};
7878
/// [`Parser`]: crate::Parser
7979
/// [`Runner`]: crate::Runner
8080
/// [`Writer`]: crate::Writer
81-
#[derive(Debug, Clone, clap::Parser)]
81+
#[derive(clap::Parser, Clone, Debug, Default)]
8282
#[command(
8383
name = "cucumber",
8484
about = "Run the tests, pet a dog!",
@@ -169,7 +169,7 @@ pub trait Colored {
169169
}
170170

171171
/// Empty CLI options.
172-
#[derive(Args, Clone, Copy, Debug)]
172+
#[derive(Args, Clone, Copy, Debug, Default)]
173173
#[group(skip)]
174174
pub struct Empty;
175175

@@ -269,7 +269,7 @@ impl Colored for Empty {}
269269
/// ```
270270
///
271271
/// [`Writer`]: crate::Writer
272-
#[derive(Args, Clone, Copy, Debug)]
272+
#[derive(Args, Clone, Copy, Debug, Default)]
273273
#[group(skip)]
274274
pub struct Compose<L: Args, R: Args> {
275275
/// Left [`clap::Args`] deriver.
@@ -291,6 +291,7 @@ impl<L: Args, R: Args> Compose<L, R> {
291291
}
292292
}
293293

294+
#[warn(clippy::missing_trait_methods)]
294295
impl<L, R> Colored for Compose<L, R>
295296
where
296297
L: Args + Colored,

src/codegen.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ pub trait Parameter {
7171
///
7272
/// Validated during [`Parameter`](macro@crate::Parameter) derive macro
7373
/// expansion.
74-
///
75-
/// [`Regex`]: regex::Regex
7674
const REGEX: &'static str;
7775

7876
/// Name of this [`Parameter`] to be referenced by in

src/cucumber.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ where
631631
///
632632
/// [`Feature`]: gherkin::Feature
633633
#[allow(clippy::missing_const_for_fn)] // false positive: drop in const
634+
#[must_use]
634635
pub fn with_cli<CustomCli>(
635636
self,
636637
cli: cli::Opts<P::Cli, R::Cli, Wr::Cli, CustomCli>,
@@ -654,6 +655,19 @@ where
654655
}
655656
}
656657

658+
/// Initializes [`Default`] [`cli::Opts`].
659+
///
660+
/// This method allows to omit parsing real [`cli::Opts`], as eagerly
661+
/// initializes [`Default`] ones instead.
662+
#[must_use]
663+
pub fn with_default_cli(mut self) -> Self
664+
where
665+
cli::Opts<P::Cli, R::Cli, Wr::Cli, Cli>: Default,
666+
{
667+
self.cli = Some(cli::Opts::default());
668+
self
669+
}
670+
657671
/// Runs [`Cucumber`] with [`Scenario`]s filter.
658672
///
659673
/// [`Feature`]s sourced from a [`Parser`] are fed to a [`Runner`], which
@@ -809,15 +823,19 @@ impl<W, P, I, R, Wr, Cli> Debug for Cucumber<W, P, I, R, Wr, Cli>
809823
where
810824
W: World,
811825
P: Debug + Parser<I>,
826+
<P as Parser<I>>::Cli: Debug,
812827
R: Debug + Runner<W>,
828+
<R as Runner<W>>::Cli: Debug,
813829
Wr: Debug + Writer<W>,
814-
Cli: clap::Args,
830+
<Wr as Writer<W>>::Cli: Debug,
831+
Cli: clap::Args + Debug,
815832
{
816833
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
817834
f.debug_struct("Cucumber")
818835
.field("parser", &self.parser)
819836
.field("runner", &self.runner)
820837
.field("writer", &self.writer)
838+
.field("cli", &self.cli)
821839
.finish()
822840
}
823841
}
@@ -861,12 +879,10 @@ where
861879
///
862880
/// * [`Writer`] — [`Normalize`] and [`Summarize`] [`writer::Basic`].
863881
///
864-
/// [`Concurrent`]: runner::basic::ScenarioType::Concurrent
882+
/// [`Concurrent`]: ScenarioType::Concurrent
865883
/// [`Normalize`]: writer::Normalize
866-
/// [`Parser`]: parser::Parser
867884
/// [`Scenario`]: gherkin::Scenario
868-
/// [`Serial`]: runner::basic::ScenarioType::Serial
869-
/// [`ScenarioType`]: runner::basic::ScenarioType
885+
/// [`Serial`]: ScenarioType::Serial
870886
/// [`Summarize`]: writer::Summarize
871887
///
872888
/// [tag]: https://cucumber.io/docs/cucumber/api#tags

src/event.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// TODO: Only because of `derive_more` macros, try to remove on next
12-
// `derive_more` upgrade.
13-
#![allow(clippy::use_self)]
14-
1511
//! Key occurrences in a lifecycle of [Cucumber] execution.
1612
//!
1713
//! The top-level enum here is [`Cucumber`].
@@ -443,6 +439,7 @@ pub enum HookType {
443439
After,
444440
}
445441

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

0 commit comments

Comments
 (0)