-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
465 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use std::io::prelude::*; | ||
|
||
use rstest::*; | ||
|
||
#[fixture] | ||
async fn async_u32() -> u32 { | ||
42 | ||
} | ||
|
||
#[fixture] | ||
async fn nest_fixture(#[await_future] async_u32: u32) -> u32 { | ||
async_u32 | ||
} | ||
|
||
#[fixture(fortytwo = async { 42 })] | ||
async fn nest_fixture_with_default(#[await_future] fortytwo: u32) -> u32 { | ||
fortytwo | ||
} | ||
|
||
#[rstest] | ||
async fn default_is_async() { | ||
assert_eq!(42, async_u32::default().await); | ||
} | ||
|
||
#[rstest] | ||
async fn use_async_nest_fixture_default(#[await_future] nest_fixture: u32) { | ||
assert_eq!(42, nest_fixture); | ||
} | ||
|
||
#[rstest(nest_fixture(async { 24 }))] | ||
async fn use_async_nest_fixture_injected(#[await_future] nest_fixture: u32) { | ||
assert_eq!(24, nest_fixture); | ||
} | ||
|
||
#[rstest] | ||
async fn use_async_nest_fixture_with_default(#[await_future] nest_fixture_with_default: u32) { | ||
assert_eq!(42, nest_fixture_with_default); | ||
} | ||
|
||
#[rstest] | ||
async fn use_async_fixture(#[await_future] async_u32: u32) { | ||
assert_eq!(42, async_u32); | ||
} | ||
|
||
#[fixture] | ||
async fn async_impl_output() -> impl Read { | ||
std::io::Cursor::new(vec![1, 2, 3, 4, 5]) | ||
} | ||
|
||
#[rstest] | ||
async fn use_async_impl_output<T: Read>(#[await_future] async_impl_output: T) { | ||
let reader = async_impl_output; | ||
} | ||
|
||
#[fixture(four = async { 4 }, two = 2)] | ||
async fn two_args_mix_fixture(#[await_future] four: u32, two: u32) -> u32 { | ||
four * 10 + two | ||
} | ||
|
||
#[rstest] | ||
async fn use_two_args_mix_fixture(#[await_future] two_args_mix_fixture: u32) { | ||
assert_eq!(42, two_args_mix_fixture); | ||
} | ||
|
||
#[rstest(two_args_mix_fixture(async { 5 }))] | ||
async fn use_two_args_mix_fixture_inject_first(#[await_future] two_args_mix_fixture: u32) { | ||
assert_eq!(52, two_args_mix_fixture); | ||
} | ||
|
||
#[rstest(two_args_mix_fixture(async { 3 }, 1))] | ||
async fn use_two_args_mix_fixture_inject_both(#[await_future] two_args_mix_fixture: u32) { | ||
assert_eq!(31, two_args_mix_fixture); | ||
} |
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,28 @@ | ||
use rstest::*; | ||
|
||
#[rstest] | ||
#[case::pass(42, async { 42 })] | ||
#[case::fail(42, async { 41 })] | ||
#[should_panic] | ||
#[case::pass_panic(42, async { 41 })] | ||
#[should_panic] | ||
#[case::fail_panic(42, async { 42 })] | ||
async fn my_async_test( | ||
#[case] expected: u32, | ||
#[case] | ||
#[await_future] | ||
value: u32, | ||
) { | ||
assert_eq!(expected, value); | ||
} | ||
|
||
#[rstest] | ||
#[case::pass(42, async { 42 })] | ||
async fn my_async_test_revert( | ||
#[case] expected: u32, | ||
#[await_future] | ||
#[case] | ||
value: u32, | ||
) { | ||
assert_eq!(expected, value); | ||
} |
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,11 @@ | ||
use rstest::*; | ||
|
||
#[rstest] | ||
async fn my_async_test( | ||
#[await_future] | ||
#[values(async { 1 }, async { 2 })] | ||
first: u32, | ||
#[values(42, 21)] second: u32, | ||
) { | ||
assert_eq!(42, first * second); | ||
} |
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,28 @@ | ||
use rstest::*; | ||
|
||
#[fixture] | ||
async fn fixture() -> u32 { | ||
42 | ||
} | ||
|
||
#[rstest] | ||
async fn should_pass(#[await_future] fixture: u32) { | ||
assert_eq!(fixture, 42); | ||
} | ||
|
||
#[rstest] | ||
async fn should_fail(#[await_future] fixture: u32) { | ||
assert_ne!(fixture, 42); | ||
} | ||
|
||
#[rstest] | ||
#[should_panic] | ||
async fn should_panic_pass(#[await_future] fixture: u32) { | ||
panic!(format!("My panic -> fixture = {}", fixture)); | ||
} | ||
|
||
#[rstest] | ||
#[should_panic] | ||
async fn should_panic_fail(#[await_future] fixture: u32) { | ||
assert_eq!(fixture, 42); | ||
} |
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
Oops, something went wrong.