Skip to content

Commit

Permalink
Close #34 by where fixture::get use
Browse files Browse the repository at this point in the history
original function. Implemented test
and fixed regression introduced by
partials calls that raise warning about
unused mut. Shut up unsused mut
warning in both get() and partial_ impl.
  • Loading branch information
la10736 committed Jan 7, 2020
1 parent 18d608e commit 8a0ff08
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions resources/fixture/no_warning.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use rstest::*;

#[fixture]
fn val() -> i32 { 21 }

#[fixture]
fn fortytwo(mut val: i32) -> i32 { val *= 2; val }

#[rstest]
fn the_test(fortytwo: i32) { assert_eq!(fortytwo, 42); }
5 changes: 3 additions & 2 deletions src/render/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub(crate) fn render<'a>(fixture: ItemFn, info: FixtureInfo) -> TokenStream {
let default_generics =
generics_clean_up(&fixture.sig.generics, std::iter::empty(), &default_output);
let default_where_clause = &default_generics.where_clause;
let body = &fixture.block;
let where_clause = &fixture.sig.generics.where_clause;
let output = &fixture.sig.output;
let visibility = &fixture.vis;
Expand All @@ -36,8 +35,9 @@ pub(crate) fn render<'a>(fixture: ItemFn, info: FixtureInfo) -> TokenStream {

impl #name {
#(#orig_attrs)*
#[allow(unused_mut)]
pub fn get #generics (#orig_args) #output #where_clause {
#body
#name(#(#args),*)
}

pub fn default #default_generics () #default_output #default_where_clause {
Expand Down Expand Up @@ -74,6 +74,7 @@ fn render_partial_impl(
let name = Ident::new(&format!("partial_{}", n), Span::call_site());

quote! {
#[allow(unused_mut)]
pub fn #name #generics (#(#sign_args),*) #output #where_clause {
#inject
Self::get(#(#fixture_args),*)
Expand Down
7 changes: 7 additions & 0 deletions tests/fixture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ mod should {
TestResults::new().ok("struct_access").assert(output);
}

#[test]
fn not_show_any_warning() {
let (output, _) = run_test("no_warning.rs");

assert_not_in!(output.stderr.str(), "warning:");
}

mod accept_and_return {
use super::*;

Expand Down

0 comments on commit 8a0ff08

Please sign in to comment.