pub mod basic;
pub mod discard;
pub mod fail_on_skipped;
#[cfg(feature = "output-json")]
pub mod json;
#[cfg(feature = "output-junit")]
pub mod junit;
#[cfg(feature = "libtest")]
pub mod libtest;
pub mod normalize;
pub mod or;
pub mod out;
pub mod repeat;
pub mod summarize;
pub mod tee;
use sealed::sealed;
#[cfg(feature = "output-json")]
#[doc(inline)]
pub use self::json::Json;
#[cfg(feature = "output-junit")]
#[doc(inline)]
pub use self::junit::JUnit;
#[cfg(feature = "libtest")]
#[doc(inline)]
pub use self::libtest::Libtest;
#[doc(inline)]
pub use self::{
basic::{Basic, Coloring},
fail_on_skipped::FailOnSkipped,
normalize::{AssertNormalized, Normalize, Normalized},
or::Or,
repeat::Repeat,
summarize::{Summarizable, Summarize},
tee::Tee,
};
use crate::{Event, event, parser};
pub trait Writer<World> {
type Cli: clap::Args;
fn handle_event(
&mut self,
event: parser::Result<Event<event::Cucumber<World>>>,
cli: &Self::Cli,
) -> impl Future<Output = ()>;
}
pub trait Arbitrary<World, Value>: Writer<World> {
fn write(&mut self, val: Value) -> impl Future<Output = ()>;
}
pub trait Stats<World>: Writer<World> {
#[must_use]
fn passed_steps(&self) -> usize;
#[must_use]
fn skipped_steps(&self) -> usize;
#[must_use]
fn failed_steps(&self) -> usize;
#[must_use]
fn retried_steps(&self) -> usize;
#[must_use]
fn parsing_errors(&self) -> usize;
#[must_use]
fn hook_errors(&self) -> usize;
#[must_use]
fn execution_has_failed(&self) -> bool {
self.failed_steps() > 0
|| self.parsing_errors() > 0
|| self.hook_errors() > 0
}
}
#[sealed]
pub trait Ext: Sized {
#[must_use]
fn assert_normalized(self) -> AssertNormalized<Self>;
#[must_use]
fn normalized<W>(self) -> Normalize<W, Self>;
#[must_use]
fn summarized(self) -> Summarize<Self>;
#[must_use]
fn fail_on_skipped(self) -> FailOnSkipped<Self>;
#[must_use]
fn fail_on_skipped_with<F>(self, with: F) -> FailOnSkipped<Self, F>
where
F: Fn(
&gherkin::Feature,
Option<&gherkin::Rule>,
&gherkin::Scenario,
) -> bool;
#[must_use]
fn repeat_skipped<W>(self) -> Repeat<W, Self>;
#[must_use]
fn repeat_failed<W>(self) -> Repeat<W, Self>;
#[must_use]
fn repeat_if<W, F>(self, filter: F) -> Repeat<W, Self, F>
where
F: Fn(&parser::Result<Event<event::Cucumber<W>>>) -> bool;
#[must_use]
fn tee<W, Wr: Writer<W>>(self, other: Wr) -> Tee<Self, Wr>;
#[must_use]
fn discard_arbitrary_writes(self) -> discard::Arbitrary<Self>;
#[must_use]
fn discard_stats_writes(self) -> discard::Stats<Self>;
}
#[sealed]
impl<T> Ext for T {
fn assert_normalized(self) -> AssertNormalized<Self> {
AssertNormalized::new(self)
}
fn normalized<W>(self) -> Normalize<W, Self> {
Normalize::new(self)
}
fn summarized(self) -> Summarize<Self> {
Summarize::from(self)
}
fn fail_on_skipped(self) -> FailOnSkipped<Self> {
FailOnSkipped::from(self)
}
fn fail_on_skipped_with<F>(self, with: F) -> FailOnSkipped<Self, F>
where
F: Fn(
&gherkin::Feature,
Option<&gherkin::Rule>,
&gherkin::Scenario,
) -> bool,
{
FailOnSkipped::with(self, with)
}
fn repeat_skipped<W>(self) -> Repeat<W, Self> {
Repeat::skipped(self)
}
fn repeat_failed<W>(self) -> Repeat<W, Self> {
Repeat::failed(self)
}
fn repeat_if<W, F>(self, filter: F) -> Repeat<W, Self, F>
where
F: Fn(&parser::Result<Event<event::Cucumber<W>>>) -> bool,
{
Repeat::new(self, filter)
}
fn tee<W, Wr: Writer<W>>(self, other: Wr) -> Tee<Self, Wr> {
Tee::new(self, other)
}
fn discard_arbitrary_writes(self) -> discard::Arbitrary<Self> {
discard::Arbitrary::wrap(self)
}
fn discard_stats_writes(self) -> discard::Stats<Self> {
discard::Stats::wrap(self)
}
}
pub trait NonTransforming {}
#[derive(Clone, Copy, Debug, Default)]
#[repr(u8)]
pub enum Verbosity {
#[default]
Default = 0,
ShowWorld = 1,
ShowWorldAndDocString = 2,
}
impl From<u8> for Verbosity {
fn from(v: u8) -> Self {
match v {
0 => Self::Default,
1 => Self::ShowWorld,
_ => Self::ShowWorldAndDocString,
}
}
}
impl From<Verbosity> for u8 {
fn from(v: Verbosity) -> Self {
match v {
Verbosity::Default => 0,
Verbosity::ShowWorld => 1,
Verbosity::ShowWorldAndDocString => 2,
}
}
}
impl Verbosity {
#[must_use]
pub const fn shows_world(&self) -> bool {
matches!(self, Self::ShowWorld | Self::ShowWorldAndDocString)
}
#[must_use]
pub const fn shows_docstring(&self) -> bool {
matches!(self, Self::ShowWorldAndDocString)
}
}