Skip to content

Commit

Permalink
Support for impl Trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Polak committed Oct 1, 2019
1 parent 312895e commit d121e29
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,21 @@ pub fn test_case(args: TokenStream, input: TokenStream) -> TokenStream {

fn render_test_cases(test_cases: &[TestCase], item: ItemFn) -> TokenStream {
let mut rendered_test_cases = vec![];

for test_case in test_cases {
rendered_test_cases.push(test_case.render(item.clone()));
}

let mod_name = item.sig.ident;
let mod_name = item.sig.ident.clone();

let output = quote! {
mod #mod_name {
#[allow(unused_imports)]
use super::*;

#[allow(unused_attributes)]
#item

#(#rendered_test_cases)*
}
};
Expand Down
9 changes: 2 additions & 7 deletions src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ impl TestCase {
}

pub fn render(&self, item: ItemFn) -> TokenStream2 {
let arg_keys = item.sig.inputs.iter();
let item_body = item.block;
let item_name = item.sig.ident.clone();
let arg_values = self.args.iter();
let test_case_name = self.test_case_name();
let inconclusive = self
Expand All @@ -97,11 +96,7 @@ impl TestCase {
#[test]
#(#attrs)*
fn #test_case_name() {
#(
let #arg_keys = #arg_values;
)*

let _result = { #item_body };
let _result = #item_name(#(#arg_values),*);//{ #item_body };
#expected
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/snapshots/acceptance__runs_all_tests.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ expression: lines

running 0 tests
running 0 tests
running 35 tests
running 36 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out
test result: ok. 34 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
test result: ok. 35 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
test test_cases::abs_tests::returns_0_for_0 ... ok
test test_cases::abs_tests::returns_given_number_for_positive_input ... ok
test test_cases::abs_tests::returns_opposite_number_for_non_positive_input ... ok
Expand All @@ -27,6 +27,7 @@ test test_cases::fancy_addition::_some_2_3_some_4_expects_2_3_4 ... ok
test test_cases::fancy_addition::_some_2_some_3_expects_5 ... ok
test test_cases::fancy_addition::treats_none_as_0 ... ok
test test_cases::foo::_expects_string_default ... ok
test test_cases::impl_trait::_foo ... ok
test test_cases::inconclusive_tests::should_not_take_into_account_keyword_on_argument_position ... ok
test test_cases::inconclusive_tests::this_test_is_inconclusive_and_will_always_be ... ignored
test test_cases::keyword_test::_true ... ok
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ mod test_cases {
assert_eq!(x, 1)
}

#[test_case("foo")]
fn impl_trait(x: impl AsRef<str>) {
assert_eq!("foo", x.as_ref());
}

#[test_case(2 => 4)]
#[test_case(4 => 8)]
fn result(x: u32) -> u32 {
Expand Down

0 comments on commit d121e29

Please sign in to comment.