-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- describe Cargo aliases in Book Co-authored-by: Kai Ren <[email protected]>
- Loading branch information
1 parent
c3e8de4
commit 72eff59
Showing
10 changed files
with
273 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use std::{convert::Infallible, panic::AssertUnwindSafe}; | ||
|
||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use cucumber::{cli, given, WorldInit}; | ||
use futures::FutureExt as _; | ||
|
||
#[derive(cli::Args)] | ||
struct CustomCli { | ||
#[clap(subcommand)] | ||
command: Option<SubCommand>, | ||
} | ||
|
||
#[derive(clap::Subcommand)] | ||
enum SubCommand { | ||
Smoke(Smoke), | ||
} | ||
|
||
#[derive(cli::Args)] | ||
struct Smoke { | ||
#[clap(long)] | ||
report_name: String, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, WorldInit)] | ||
struct World; | ||
|
||
#[async_trait(?Send)] | ||
impl cucumber::World for World { | ||
type Error = Infallible; | ||
|
||
async fn new() -> Result<Self, Self::Error> { | ||
Ok(World) | ||
} | ||
} | ||
|
||
#[given("an invalid step")] | ||
fn invalid_step(_world: &mut World) { | ||
assert!(false); | ||
} | ||
|
||
// This test uses a subcommand with the global option `--tags` to filter on two | ||
// failing tests and verifies that the error output contains 2 failing steps. | ||
#[tokio::test] | ||
async fn tags_option_filters_all_scenarios_with_subcommand() { | ||
let cli = cli::Opts::<_, _, _, CustomCli>::try_parse_from(&[ | ||
"test", | ||
"smoke", | ||
r#"--report-name="smoke.report""#, | ||
"--tags=@all", | ||
]) | ||
.expect("Invalid command line"); | ||
|
||
let res = World::cucumber() | ||
.with_cli(cli) | ||
.run_and_exit("tests/features/cli"); | ||
|
||
let err = AssertUnwindSafe(res) | ||
.catch_unwind() | ||
.await | ||
.expect_err("should err"); | ||
let err = err.downcast_ref::<String>().unwrap(); | ||
|
||
assert_eq!(err, "2 steps failed"); | ||
} | ||
|
||
// This test uses a subcommand with the global option `--tags` to filter on one | ||
// failing test and verifies that the error output contains 1 failing step. | ||
#[tokio::test] | ||
async fn tags_option_filters_scenario1_with_subcommand() { | ||
let cli = cli::Opts::<_, _, _, CustomCli>::try_parse_from(&[ | ||
"test", | ||
"smoke", | ||
r#"--report-name="smoke.report""#, | ||
"--tags=@scenario-1", | ||
]) | ||
.expect("Invalid command line"); | ||
|
||
let res = World::cucumber() | ||
.with_cli(cli) | ||
.run_and_exit("tests/features/cli"); | ||
|
||
let err = AssertUnwindSafe(res) | ||
.catch_unwind() | ||
.await | ||
.expect_err("should err"); | ||
let err = err.downcast_ref::<String>().unwrap(); | ||
|
||
assert_eq!(err, "1 step failed"); | ||
} | ||
|
||
// This test verifies that the global option `--tags` is still available without | ||
// subcommands and that the error output contains 1 failing step. | ||
#[tokio::test] | ||
async fn tags_option_filters_scenario1_no_subcommand() { | ||
let cli = cli::Opts::<_, _, _, CustomCli>::try_parse_from(&[ | ||
"test", | ||
"--tags=@scenario-1", | ||
]) | ||
.expect("Invalid command line"); | ||
|
||
let res = World::cucumber() | ||
.with_cli(cli) | ||
.run_and_exit("tests/features/cli"); | ||
|
||
let err = AssertUnwindSafe(res) | ||
.catch_unwind() | ||
.await | ||
.expect_err("should err"); | ||
let err = err.downcast_ref::<String>().unwrap(); | ||
|
||
assert_eq!(err, "1 step failed"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Feature: Global option `--tags` with subcommands | ||
|
||
@scenario-1 @all | ||
Scenario: Two invalid steps | ||
Given an invalid step | ||
And an invalid step | ||
|
||
@scenario-2 @all | ||
Scenario: One invalid step | ||
Given an invalid step |