Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight regex capture groups in terminal output (#42) #136

Merged
merged 41 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
06dae5d
Add Features book chapter [skip ci]
ilslv Sep 28, 2021
00b861f
Fill Test Modules Organization book chapter
ilslv Sep 28, 2021
ca1a596
Revert README.md to link instead of trying to embed script
ilslv Sep 28, 2021
1d9114d
Corrections
ilslv Sep 29, 2021
4a901b6
Implement writer::Repeat
ilslv Sep 29, 2021
20a0afa
Update asciinema recordings
ilslv Sep 29, 2021
11f4712
Mention writer::Repeat in the book
ilslv Sep 29, 2021
37d1235
Merge branch 'main' into output-only-skipped-or-failed
ilslv Sep 30, 2021
675e4be
Propagate errors encountered during Scenario Outline expansion
ilslv Sep 30, 2021
9b77f4a
Update asciinema in docs
ilslv Sep 30, 2021
d318077
Corrections
ilslv Sep 30, 2021
a25cca2
Output tables in writer::Basic
ilslv Oct 1, 2021
aadcd85
Corrections
ilslv Oct 1, 2021
7c12f0d
Revert "Output tables in writer::Basic"
ilslv Oct 1, 2021
8c85eab
Expand Scenario Outline Examples in tables too
ilslv Oct 1, 2021
f3c2db2
Fix CHANGELOG
ilslv Oct 1, 2021
6e37a99
Mention Scenario Outline Examples expansion in Step Table in feature:…
ilslv Oct 1, 2021
47a6393
WIP [skip ci]
ilslv Oct 1, 2021
ad183fb
Comment out panic hook replacement [skip ci]
ilslv Oct 1, 2021
2456d6d
Fix panic on nested groups [skip ci]
ilslv Oct 1, 2021
fb8f26b
Return hooks [skip ci]
ilslv Oct 1, 2021
2e201f2
Start updating asciinema [skip ci]
ilslv Oct 1, 2021
8c937c6
Some corrections
tyranron Oct 1, 2021
6082dcf
Return old CLI options for backwards compatibility
ilslv Oct 4, 2021
e591a58
Merge branch 'return-old-cli' into highlight-step-captues
ilslv Oct 4, 2021
d4d9e9b
Merge branch 'output-only-skipped-or-failed' into highlight-step-captues
ilslv Oct 4, 2021
7e7d56e
Re-record asciinema demonstrations with captured groups highlighting
ilslv Oct 4, 2021
740a36f
Merge branch 'main' into output-table-in-basic-writer
ilslv Oct 4, 2021
d8ac943
Fix CHANGELOG error
ilslv Oct 4, 2021
7eabf1d
Some corrections [skip ci]
tyranron Oct 5, 2021
de57a3d
Corrections
ilslv Oct 12, 2021
8427dcf
Merge branch 'output-table-in-basic-writer' into return-old-cli
ilslv Oct 12, 2021
84ce319
Corrections
ilslv Oct 12, 2021
09daa46
Corrections
ilslv Oct 12, 2021
411a1f8
Merge branch 'return-old-cli' into highlight-step-captues
ilslv Oct 12, 2021
6034f20
Corrections
ilslv Oct 14, 2021
c649031
Merge branch 'main' into highlight-step-captues
ilslv Oct 14, 2021
1e997a3
Merge branch 'main' into highlight-step-captues
ilslv Oct 14, 2021
cb4b3b7
Corrections
ilslv Oct 14, 2021
b5fc9cf
Corrections
tyranron Oct 14, 2021
af22d50
Mention in CHANGELOG
tyranron Oct 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ All user visible changes to `cucumber` crate will be documented in this file. Th
### Added

- Ability to run `Scenario`s concurrently. ([#128])
- Highlighting of regex capture groups in terminal output with __bold__ style. ([#136])

[#128]: /../../pull/128
[#136]: /../../pull/136
[#137]: /../../pull/137


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ name = "readme"
harness = false # allows Cucumber to print output instead of libtest
```

[![asciicast](https://asciinema.org/a/YP24WIM1PGr2I9znFYKfmbkyo.svg)](https://asciinema.org/a/YP24WIM1PGr2I9znFYKfmbkyo)
[![asciicast](https://asciinema.org/a/6wN3uv8p98SgVznPUh9h50bFo.svg)](https://asciinema.org/a/6wN3uv8p98SgVznPUh9h50bFo)

For more examples check out the Book ([current][1] | [edge][2]).

Expand Down
10 changes: 5 additions & 5 deletions book/src/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Feature: Animal feature
Then the cat is not hungry
```

<script id="asciicast-9wOF9rEgGUgWN9e49TWiS5Nh3" src="https://asciinema.org/a/9wOF9rEgGUgWN9e49TWiS5Nh3.js" async data-autoplay="true" data-rows="18"></script>
<script id="asciicast-c8XFsr52VB8tuIJfIaofWAfyh" src="https://asciinema.org/a/c8XFsr52VB8tuIJfIaofWAfyh.js" async data-autoplay="true" data-rows="18"></script>



Expand Down Expand Up @@ -63,7 +63,7 @@ Feature: Animal feature
Then the cat is not hungry
```

<script id="asciicast-Q8OmAVWU116ZzxYg6VjBDxjlt" src="https://asciinema.org/a/Q8OmAVWU116ZzxYg6VjBDxjlt.js" async data-autoplay="true" data-rows="18"></script>
<script id="asciicast-ZQyfL8gVHD932rskDDESqlsD9" src="https://asciinema.org/a/ZQyfL8gVHD932rskDDESqlsD9.js" async data-autoplay="true" data-rows="18"></script>

`Background` `Step`s indicated by `>` sign in the output by default.

Expand Down Expand Up @@ -168,7 +168,7 @@ async fn cat_is_fed(world: &mut AnimalWorld) {
# }
```

<script id="asciicast-15ZcRGFBUXubvcle34ZOLiLtO" src="https://asciinema.org/a/15ZcRGFBUXubvcle34ZOLiLtO.js" async data-autoplay="true" data-rows="18"></script>
<script id="asciicast-o1s4mSMYkkVBy4WAsG8lhYtT8" src="https://asciinema.org/a/o1s4mSMYkkVBy4WAsG8lhYtT8.js" async data-autoplay="true" data-rows="18"></script>


### Combining `regex` and `FromStr`
Expand Down Expand Up @@ -273,7 +273,7 @@ async fn cat_is_fed(world: &mut AnimalWorld) {
# }
```

<script id="asciicast-joMErjGUVegtXPJgL8fc5x6pt" src="https://asciinema.org/a/joMErjGUVegtXPJgL8fc5x6pt.js" async data-autoplay="true" data-rows="18"></script>
<script id="asciicast-GeKTIuSZ61Q9Nzv5X4TyrNVVp" src="https://asciinema.org/a/GeKTIuSZ61Q9Nzv5X4TyrNVVp.js" async data-autoplay="true" data-rows="18"></script>



Expand All @@ -297,7 +297,7 @@ Egenskap: Animal feature
Så the cat is not hungry
```

<script id="asciicast-sDt8aoo9ZVPZRgiTuy8pSNro2" src="https://asciinema.org/a/sDt8aoo9ZVPZRgiTuy8pSNro2.js" async data-autoplay="true" data-rows="18"></script>
<script id="asciicast-DFtCqnpcnXpKbGxtxfedkW0Ga" src="https://asciinema.org/a/DFtCqnpcnXpKbGxtxfedkW0Ga.js" async data-autoplay="true" data-rows="18"></script>

In case most of your `.feature` files aren't written in English and you want to avoid endless `# language:` comments, use [`Cucumber::language()`](https://docs.rs/cucumber/*/cucumber/struct.Cucumber.html#method.language) method to override the default language.

Expand Down
12 changes: 7 additions & 5 deletions book/src/Getting_Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn cat_is_fed(world: &mut AnimalWorld) {

If you run the test now, you'll see that all steps are accounted for and the test succeeds:

<script id="asciicast-HaEZXiqUn0U1T8c5TaiMGX50i" src="https://asciinema.org/a/HaEZXiqUn0U1T8c5TaiMGX50i.js" async data-autoplay="true" data-rows="16"></script>
<script id="asciicast-fHuIXkWrIk1AOFFqF0MYmY0m0" src="https://asciinema.org/a/fHuIXkWrIk1AOFFqF0MYmY0m0.js" async data-autoplay="true" data-rows="16"></script>

If you want to be assured that your validation is indeed happening, you can change the assertion for the cat being hungry from `true` to `false` temporarily:
```rust,should_panic
Expand Down Expand Up @@ -274,7 +274,7 @@ fn cat_is_fed(world: &mut AnimalWorld) {

And you should see the test failing:

<script id="asciicast-KFNrNihA5ib9G7O22jwTSw0Lg" src="https://asciinema.org/a/KFNrNihA5ib9G7O22jwTSw0Lg.js" async data-autoplay="true" data-rows="24"></script>
<script id="asciicast-XTikmqirO7mAFZ97MNfKvnD5p" src="https://asciinema.org/a/XTikmqirO7mAFZ97MNfKvnD5p.js" async data-autoplay="true" data-rows="24"></script>

What if we also wanted to validate that even if the cat was never hungry to begin with, it wouldn't end up hungry after it was fed? We can add another scenario that looks quite similar:
```gherkin
Expand Down Expand Up @@ -354,7 +354,9 @@ We surround regex with `^..$` to ensure the __exact__ match. This is much more u

[Cucumber] will reuse these steps:

<script id="asciicast-RAteqk9p0zkvWrslK6kiOU5lc" src="https://asciinema.org/a/RAteqk9p0zkvWrslK6kiOU5lc.js" async data-autoplay="true" data-rows="18"></script>
<script id="asciicast-ao6LdWsrtdsgg8tOi9cQgPfyz" src="https://asciinema.org/a/ao6LdWsrtdsgg8tOi9cQgPfyz.js" async data-autoplay="true" data-rows="18"></script>

Captured groups are __bold__ to indicate which part of step could be dynamically changed.

A contrived example, but this demonstrates that steps can be reused as long as they are sufficiently precise in both their description and implementation. If, for example, the wording for our `Then` step was `The cat is no longer hungry`, it'd imply something about the expected initial state, when that is not the purpose of a `Then` step, but rather of the `Given` step.

Expand Down Expand Up @@ -506,7 +508,7 @@ async fn main() {
}
```

<script id="asciicast-vufDjDlrdm5TtH20WVpIGpEz6" src="https://asciinema.org/a/vufDjDlrdm5TtH20WVpIGpEz6.js" async data-autoplay="true" data-rows="18"></script>
<script id="asciicast-tz9ApYZgsET9k8jjIa9HpnQ8p" src="https://asciinema.org/a/tz9ApYZgsET9k8jjIa9HpnQ8p.js" async data-autoplay="true" data-rows="18"></script>

Hm, it looks like the executor waited only for the first `Feature` 🤔, what's going on?

Expand All @@ -530,7 +532,7 @@ Feature: Animal feature
Then the cat is not hungry
```

<script id="asciicast-KztYots1Jm6WijCmxZM1GZT1K" src="https://asciinema.org/a/KztYots1Jm6WijCmxZM1GZT1K.js" async data-autoplay="true" data-rows="18"></script>
<script id="asciicast-MDXpZf8vcOTssmlU4rgSSfR0E" src="https://asciinema.org/a/MDXpZf8vcOTssmlU4rgSSfR0E.js" async data-autoplay="true" data-rows="18"></script>



Expand Down
49 changes: 24 additions & 25 deletions src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ where
///
/// Output with a regular [`Cucumber::run()`]:
/// <script
/// id="asciicast-hMyH3IYbHRFXT1yf84tXDNl2r"
/// src="https://asciinema.org/a/hMyH3IYbHRFXT1yf84tXDNl2r.js"
/// id="asciicast-0d92qlT8Mbc4WXyvRbHJmjsqN"
/// src="https://asciinema.org/a/0d92qlT8Mbc4WXyvRbHJmjsqN.js"
/// async data-autoplay="true" data-rows="17">
/// </script>
///
Expand Down Expand Up @@ -178,8 +178,8 @@ where
/// # futures::executor::block_on(fut);
/// ```
/// <script
/// id="asciicast-UsaG9kMnn40nW8y4vcmXOE2tT"
/// src="https://asciinema.org/a/UsaG9kMnn40nW8y4vcmXOE2tT.js"
/// id="asciicast-IHLxMEgku9BtBVkR4k2DtOjMd"
/// src="https://asciinema.org/a/IHLxMEgku9BtBVkR4k2DtOjMd.js"
/// async data-autoplay="true" data-rows="21">
/// </script>
///
Expand Down Expand Up @@ -223,8 +223,8 @@ where
///
/// Output with a regular [`Cucumber::run()`]:
/// <script
/// id="asciicast-hMyH3IYbHRFXT1yf84tXDNl2r"
/// src="https://asciinema.org/a/hMyH3IYbHRFXT1yf84tXDNl2r.js"
/// id="asciicast-0d92qlT8Mbc4WXyvRbHJmjsqN"
/// src="https://asciinema.org/a/0d92qlT8Mbc4WXyvRbHJmjsqN.js"
/// async data-autoplay="true" data-rows="17">
/// </script>
///
Expand All @@ -234,7 +234,6 @@ where
/// # use std::convert::Infallible;
/// #
/// # use async_trait::async_trait;
/// # use futures::FutureExt as _;
/// # use cucumber::WorldInit;
/// #
/// # #[derive(Debug, WorldInit)]
Expand Down Expand Up @@ -272,8 +271,8 @@ where
/// Then the dog is not hungry
/// ```
/// <script
/// id="asciicast-UsaG9kMnn40nW8y4vcmXOE2tT"
/// src="https://asciinema.org/a/UsaG9kMnn40nW8y4vcmXOE2tT.js"
/// id="asciicast-IHLxMEgku9BtBVkR4k2DtOjMd"
/// src="https://asciinema.org/a/IHLxMEgku9BtBVkR4k2DtOjMd.js"
/// async data-autoplay="true" data-rows="21">
/// </script>
///
Expand Down Expand Up @@ -323,8 +322,8 @@ where
///
/// Output with a regular [`Cucumber::run()`]:
/// <script
/// id="asciicast-hMyH3IYbHRFXT1yf84tXDNl2r"
/// src="https://asciinema.org/a/hMyH3IYbHRFXT1yf84tXDNl2r.js"
/// id="asciicast-0d92qlT8Mbc4WXyvRbHJmjsqN"
/// src="https://asciinema.org/a/0d92qlT8Mbc4WXyvRbHJmjsqN.js"
/// async data-autoplay="true" data-rows="17">
/// </script>
///
Expand Down Expand Up @@ -358,8 +357,8 @@ where
/// # futures::executor::block_on(fut);
/// ```
/// <script
/// id="asciicast-BD1mPjYGELD6oWNKW8lTlyvDR"
/// src="https://asciinema.org/a/BD1mPjYGELD6oWNKW8lTlyvDR.js"
/// id="asciicast-ox14HynkBIw8atpfhyfvKrsO3"
/// src="https://asciinema.org/a/ox14HynkBIw8atpfhyfvKrsO3.js"
/// async data-autoplay="true" data-rows="19">
/// </script>
///
Expand Down Expand Up @@ -410,8 +409,8 @@ where
/// # futures::executor::block_on(fut);
/// ```
/// <script
/// id="asciicast-mDDqxWHzUaK19P0L2R2g4XRp2"
/// src="https://asciinema.org/a/mDDqxWHzUaK19P0L2R2g4XRp2.js"
/// id="asciicast-UcipuopO6IFEsIDty6vaJlCH9"
/// src="https://asciinema.org/a/UcipuopO6IFEsIDty6vaJlCH9.js"
/// async data-autoplay="true" data-rows="21">
/// </script>
///
Expand Down Expand Up @@ -446,8 +445,8 @@ where
/// # futures::executor::block_on(fut);
/// ```
/// <script
/// id="asciicast-qKp8Hevrb6732mMUT7VduvxJc"
/// src="https://asciinema.org/a/qKp8Hevrb6732mMUT7VduvxJc.js"
/// id="asciicast-ofOljvyEMb41OTLhE081QKv68"
/// src="https://asciinema.org/a/ofOljvyEMb41OTLhE081QKv68.js"
/// async data-autoplay="true" data-rows="24">
/// </script>
///
Expand Down Expand Up @@ -506,8 +505,8 @@ where
/// # futures::executor::block_on(fut);
/// ```
/// <script
/// id="asciicast-mDDqxWHzUaK19P0L2R2g4XRp2"
/// src="https://asciinema.org/a/mDDqxWHzUaK19P0L2R2g4XRp2.js"
/// id="asciicast-UcipuopO6IFEsIDty6vaJlCH9"
/// src="https://asciinema.org/a/UcipuopO6IFEsIDty6vaJlCH9.js"
/// async data-autoplay="true" data-rows="21">
/// </script>
///
Expand Down Expand Up @@ -564,8 +563,8 @@ where
/// # futures::executor::block_on(fut);
/// ```
/// <script
/// id="asciicast-qKp8Hevrb6732mMUT7VduvxJc"
/// src="https://asciinema.org/a/qKp8Hevrb6732mMUT7VduvxJc.js"
/// id="asciicast-ofOljvyEMb41OTLhE081QKv68"
/// src="https://asciinema.org/a/ofOljvyEMb41OTLhE081QKv68.js"
/// async data-autoplay="true" data-rows="24">
/// </script>
///
Expand Down Expand Up @@ -666,8 +665,8 @@ where
/// Then the dog is not hungry
/// ```
/// <script
/// id="asciicast-WbP3PIQR5M7Iznd7uLnjg2ytr"
/// src="https://asciinema.org/a/WbP3PIQR5M7Iznd7uLnjg2ytr.js"
/// id="asciicast-0KvTxnfaMRjsvsIKsalS611Ta"
/// src="https://asciinema.org/a/0KvTxnfaMRjsvsIKsalS611Ta.js"
/// async data-autoplay="true" data-rows="14">
/// </script>
///
Expand Down Expand Up @@ -1008,8 +1007,8 @@ where
/// Then the dog is not hungry
/// ```
/// <script
/// id="asciicast-WbP3PIQR5M7Iznd7uLnjg2ytr"
/// src="https://asciinema.org/a/WbP3PIQR5M7Iznd7uLnjg2ytr.js"
/// id="asciicast-0KvTxnfaMRjsvsIKsalS611Ta"
/// src="https://asciinema.org/a/0KvTxnfaMRjsvsIKsalS611Ta.js"
/// async data-autoplay="true" data-rows="14">
/// </script>
///
Expand Down
30 changes: 20 additions & 10 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ pub enum Step<World> {
/// [`Step`] passed.
///
/// [`Step`]: gherkin::Step
Passed,
Passed(regex::CaptureLocations),

/// [`Step`] failed.
///
/// [`Step`]: gherkin::Step
Failed(Option<Arc<World>>, Info),
Failed(Option<regex::CaptureLocations>, Option<Arc<World>>, Info),
}

// Manual implementation is required to omit the redundant `World: Clone` trait
Expand All @@ -216,8 +216,10 @@ impl<World> Clone for Step<World> {
match self {
Self::Started => Self::Started,
Self::Skipped => Self::Skipped,
Self::Passed => Self::Passed,
Self::Failed(w, info) => Self::Failed(w.clone(), info.clone()),
Self::Passed(captures) => Self::Passed(captures.clone()),
Self::Failed(captures, w, info) => {
Self::Failed(captures.clone(), w.clone(), info.clone())
}
}
}
}
Expand Down Expand Up @@ -283,17 +285,23 @@ impl<World> Scenario<World> {
///
/// [`Step`]: gherkin::Step
#[must_use]
pub fn step_passed(step: Arc<gherkin::Step>) -> Self {
Self::Step(step, Step::Passed)
pub fn step_passed(
step: Arc<gherkin::Step>,
captures: regex::CaptureLocations,
) -> Self {
Self::Step(step, Step::Passed(captures))
}

/// Constructs an event of a passed [`Background`] [`Step`].
///
/// [`Background`]: gherkin::Background
/// [`Step`]: gherkin::Step
#[must_use]
pub fn background_step_passed(step: Arc<gherkin::Step>) -> Self {
Self::Background(step, Step::Passed)
pub fn background_step_passed(
step: Arc<gherkin::Step>,
captures: regex::CaptureLocations,
) -> Self {
Self::Background(step, Step::Passed(captures))
}

/// Constructs an event of a skipped [`Step`].
Expand All @@ -318,10 +326,11 @@ impl<World> Scenario<World> {
#[must_use]
pub fn step_failed(
step: Arc<gherkin::Step>,
captures: Option<regex::CaptureLocations>,
world: Option<Arc<World>>,
info: Info,
) -> Self {
Self::Step(step, Step::Failed(world, info))
Self::Step(step, Step::Failed(captures, world, info))
}

/// Constructs an event of a failed [`Background`] [`Step`].
Expand All @@ -331,9 +340,10 @@ impl<World> Scenario<World> {
#[must_use]
pub fn background_step_failed(
step: Arc<gherkin::Step>,
captures: Option<regex::CaptureLocations>,
world: Option<Arc<World>>,
info: Info,
) -> Self {
Self::Background(step, Step::Failed(world, info))
Self::Background(step, Step::Failed(captures, world, info))
}
}
Loading