Skip to content

Commit

Permalink
#119: Implement the defined type for once
Browse files Browse the repository at this point in the history
  • Loading branch information
la10736 committed Nov 27, 2021
1 parent d9523f0 commit 11cdaba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/render/fixture.rs
Expand Up @@ -102,11 +102,15 @@ fn render_partial_impl(
resolver: &impl Resolver,
info: &FixtureInfo,
) -> TokenStream {
let output = info
let mut output = info
.attributes
.extract_partial_type(n)
.unwrap_or_else(|| fixture.sig.output.clone());

if info.attributes.is_once() {
output = wrap_return_type_as_static_ref(output);
}

let generics = generics_clean_up(&fixture.sig.generics, fn_args(fixture).take(n), &output);
let where_clause = &generics.where_clause;
let asyncness = &fixture.sig.asyncness;
Expand Down
1 change: 1 addition & 0 deletions tests/fixture/mod.rs
Expand Up @@ -201,6 +201,7 @@ mod should {
#[rstest]
#[case("once.rs")]
#[case::no_return("once_no_return.rs")]
#[case::no_return("once_defined_type.rs")]
fn accept_once_attribute_and_call_fixture_just_once(#[case] fname: &str) {
let project = prj(fname).with_nocapture();

Expand Down
33 changes: 33 additions & 0 deletions tests/resources/fixture/once_defined_type.rs
@@ -0,0 +1,33 @@
use rstest::{fixture, rstest};

#[fixture]
#[default(u32)]
#[partial_1(u32)]
#[once]
fn once_fixture(#[default(())] a: (), #[default(())] b: ()) -> u32 {
eprintln!("Exec fixture() just once");
42
}

#[rstest]
fn base(once_fixture: &u32) {
assert_eq!(&42, once_fixture);
}

#[rstest]
fn base_partial(#[with(())] once_fixture: &u32) {
assert_eq!(&42, once_fixture);
}

#[rstest]
fn base_complete(#[with((), ())] once_fixture: &u32) {
assert_eq!(&42, once_fixture);
}

#[rstest]
#[case(2)]
#[case(3)]
#[case(7)]
fn cases(once_fixture: &u32, #[case] divisor: u32) {
assert_eq!(0, *once_fixture % divisor);
}

0 comments on commit 11cdaba

Please sign in to comment.