-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: (Refactoring) Implemented the future boilerplate in the rendering stage. Just render and test (missing the parse stage). * WIP: removed `ReplaceFutureAttribute` hack in `fixture` and moved the parsing code in `extend_with_function_attrs` trait impl * Move test in the right module and simplfied it * Add check also for no future args * Refactored and removed useless tests that're already tested in future module * Use Arguments also in tests and removed the old impl. Also recoverd tests for errors but implemented them in future module * WIP: Implementing await policy * WIP: implemented the render part. * WIP: implemented tests for is_future_await logic * WIP: Implemented future options parsing. Missed the global one * WIP implemented all global parser, pass arguments info down to the renderers and impleneted all tests in render code to check that the parsed info will used correctly. * Changed impl: we should await in the original method because we want the future in the signature. Now E2E tests for fixture are enabled and work. * Integration tests * Add documentation and changelog info
- Loading branch information
Showing
27 changed files
with
1,524 additions
and
218 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,38 @@ | ||
use rstest::*; | ||
fn valid_user(name: &str, age: u8) -> bool { | ||
true | ||
|
||
#[fixture] | ||
#[awt] | ||
async fn two_args_mix_fixture( | ||
#[future] | ||
#[default(async { 4 })] | ||
four: u32, | ||
#[default(2)] two: u32, | ||
) -> u32 { | ||
four * 10 + two | ||
} | ||
|
||
// #[rstest] | ||
// #[awt] | ||
// async fn use_two_args_mix_fixture(#[future] two_args_mix_fixture: u32) { | ||
// assert_eq!(42, two_args_mix_fixture); | ||
// } | ||
|
||
// #[rstest] | ||
// #[awt] | ||
// async fn use_two_args_mix_fixture_inject_first( | ||
// #[future] | ||
// #[with(async { 5 })] | ||
// two_args_mix_fixture: u32, | ||
// ) { | ||
// assert_eq!(52, two_args_mix_fixture); | ||
// } | ||
|
||
#[rstest] | ||
fn should_accept_all_corner_cases( | ||
#[values("J", "A", "A________________________________________21")] name: &str, | ||
#[values(14, 100)] age: u8, | ||
#[awt] | ||
async fn use_two_args_mix_fixture_inject_both( | ||
#[future] | ||
#[with(async { 3 }, 1)] | ||
two_args_mix_fixture: u32, | ||
) { | ||
assert!(valid_user(name, age)) | ||
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
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
105 changes: 105 additions & 0 deletions
105
rstest/tests/resources/fixture/await_complete_fixture.rs
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,105 @@ | ||
use std::io::prelude::*; | ||
|
||
use rstest::*; | ||
|
||
#[fixture] | ||
async fn async_u32() -> u32 { | ||
42 | ||
} | ||
|
||
#[fixture] | ||
#[awt] | ||
async fn nest_fixture(#[future] async_u32: u32) -> u32 { | ||
async_u32 | ||
} | ||
|
||
#[fixture] | ||
#[awt] | ||
async fn nest_fixture_with_default( | ||
#[future] | ||
#[default(async { 42 })] | ||
fortytwo: u32, | ||
) -> u32 { | ||
fortytwo | ||
} | ||
|
||
#[rstest] | ||
async fn default_is_async() { | ||
assert_eq!(42, async_u32::default().await); | ||
} | ||
|
||
#[rstest] | ||
#[awt] | ||
async fn use_async_nest_fixture_default(#[future] nest_fixture: u32) { | ||
assert_eq!(42, nest_fixture); | ||
} | ||
|
||
#[rstest] | ||
#[awt] | ||
async fn use_async_nest_fixture_injected( | ||
#[future] | ||
#[with(async { 24 })] | ||
nest_fixture: u32, | ||
) { | ||
assert_eq!(24, nest_fixture); | ||
} | ||
|
||
#[rstest] | ||
#[awt] | ||
async fn use_async_nest_fixture_with_default(#[future] nest_fixture_with_default: u32) { | ||
assert_eq!(42, nest_fixture_with_default); | ||
} | ||
|
||
#[rstest] | ||
#[awt] | ||
async fn use_async_fixture(#[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] | ||
#[awt] | ||
async fn use_async_impl_output<T: Read>(#[future] async_impl_output: T) { | ||
let reader = async_impl_output; | ||
} | ||
|
||
#[fixture] | ||
#[awt] | ||
async fn two_args_mix_fixture( | ||
#[future] | ||
#[default(async { 4 })] | ||
four: u32, | ||
#[default(2)] two: u32, | ||
) -> u32 { | ||
four * 10 + two | ||
} | ||
|
||
#[rstest] | ||
#[awt] | ||
async fn use_two_args_mix_fixture(#[future] two_args_mix_fixture: u32) { | ||
assert_eq!(42, two_args_mix_fixture); | ||
} | ||
|
||
#[rstest] | ||
#[awt] | ||
async fn use_two_args_mix_fixture_inject_first( | ||
#[future] | ||
#[with(async { 5 })] | ||
two_args_mix_fixture: u32, | ||
) { | ||
assert_eq!(52, two_args_mix_fixture); | ||
} | ||
|
||
#[rstest] | ||
#[awt] | ||
async fn use_two_args_mix_fixture_inject_both( | ||
#[future] | ||
#[with(async { 3 }, 1)] | ||
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,94 @@ | ||
use std::io::prelude::*; | ||
|
||
use rstest::*; | ||
|
||
#[fixture] | ||
async fn async_u32() -> u32 { | ||
42 | ||
} | ||
|
||
#[fixture] | ||
async fn nest_fixture(#[future(awt)] async_u32: u32) -> u32 { | ||
async_u32 | ||
} | ||
|
||
#[fixture] | ||
async fn nest_fixture_with_default( | ||
#[future(awt)] | ||
#[default(async { 42 })] | ||
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(#[future(awt)] nest_fixture: u32) { | ||
assert_eq!(42, nest_fixture); | ||
} | ||
|
||
#[rstest] | ||
async fn use_async_nest_fixture_injected( | ||
#[future(awt)] | ||
#[with(async { 24 })] | ||
nest_fixture: u32, | ||
) { | ||
assert_eq!(24, nest_fixture); | ||
} | ||
|
||
#[rstest] | ||
async fn use_async_nest_fixture_with_default(#[future(awt)] nest_fixture_with_default: u32) { | ||
assert_eq!(42, nest_fixture_with_default); | ||
} | ||
|
||
#[rstest] | ||
async fn use_async_fixture(#[future(awt)] 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>(#[future(awt)] async_impl_output: T) { | ||
let reader = async_impl_output; | ||
} | ||
|
||
#[fixture] | ||
async fn two_args_mix_fixture( | ||
#[future(awt)] | ||
#[default(async { 4 })] | ||
four: u32, | ||
#[default(2)] two: u32, | ||
) -> u32 { | ||
four * 10 + two | ||
} | ||
|
||
#[rstest] | ||
async fn use_two_args_mix_fixture(#[future(awt)] two_args_mix_fixture: u32) { | ||
assert_eq!(42, two_args_mix_fixture); | ||
} | ||
|
||
#[rstest] | ||
async fn use_two_args_mix_fixture_inject_first( | ||
#[future(awt)] | ||
#[with(async { 5 })] | ||
two_args_mix_fixture: u32, | ||
) { | ||
assert_eq!(52, two_args_mix_fixture); | ||
} | ||
|
||
#[rstest] | ||
async fn use_two_args_mix_fixture_inject_both( | ||
#[future(awt)] | ||
#[with(async { 3 }, 1)] | ||
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 |
---|---|---|
@@ -1,10 +1,17 @@ | ||
use rstest::*; | ||
|
||
#[fixture] | ||
fn val() -> i32 { 21 } | ||
fn val() -> i32 { | ||
21 | ||
} | ||
|
||
#[fixture] | ||
fn fortytwo(mut val: i32) -> i32 { val *= 2; val } | ||
fn fortytwo(mut val: i32) -> i32 { | ||
val *= 2; | ||
val | ||
} | ||
|
||
#[rstest] | ||
fn the_test(fortytwo: i32) { assert_eq!(fortytwo, 42); } | ||
fn the_test(fortytwo: i32) { | ||
assert_eq!(fortytwo, 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
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] | ||
#[future(awt)] | ||
value: u32, | ||
) { | ||
assert_eq!(expected, value); | ||
} | ||
|
||
#[rstest] | ||
#[case::pass(42, async { 42 })] | ||
async fn my_async_test_revert( | ||
#[case] expected: u32, | ||
#[future(awt)] | ||
#[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,30 @@ | ||
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 })] | ||
#[awt] | ||
async fn my_async_test( | ||
#[case] expected: u32, | ||
#[case] | ||
#[future] | ||
value: u32, | ||
) { | ||
assert_eq!(expected, value); | ||
} | ||
|
||
#[rstest] | ||
#[case::pass(42, async { 42 })] | ||
#[awt] | ||
async fn my_async_test_revert( | ||
#[case] expected: u32, | ||
#[future] | ||
#[case] | ||
value: u32, | ||
) { | ||
assert_eq!(expected, value); | ||
} |
Oops, something went wrong.