@@ -747,9 +747,10 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
747
747
visible_path. extend ( path) ;
748
748
749
749
// Rather than directly give the test function to the test
750
- // harness, we create a wrapper like this :
750
+ // harness, we create a wrapper like one of the following :
751
751
//
752
- // || test::assert_test_result(real_function())
752
+ // || test::assert_test_result(real_function()) // for test
753
+ // |b| test::assert_test_result(real_function(b)) // for bench
753
754
//
754
755
// this will coerce into a fn pointer that is specialized to the
755
756
// actual return type of `real_function` (Typically `()`, but not always).
@@ -758,24 +759,47 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
758
759
let real_function_expr = ecx. expr_path ( ecx. path_global ( span, visible_path) ) ;
759
760
// construct path `test::assert_test_result`
760
761
let assert_test_result = test_path ( "assert_test_result" ) ;
761
- // construct `|| {..}`
762
- ecx. lambda (
763
- span,
764
- vec ! [ ] ,
765
- // construct `assert_test_result(..)`
766
- ecx. expr_call (
762
+ if test. bench {
763
+ // construct `|b| {..}`
764
+ let b_ident = Ident :: with_empty_ctxt ( Symbol :: gensym ( "b" ) ) ;
765
+ let b_expr = ecx. expr_ident ( span, b_ident) ;
766
+ ecx. lambda (
767
767
span,
768
- ecx. expr_path ( assert_test_result) ,
769
- vec ! [
770
- // construct `real_function()`
771
- ecx. expr_call(
772
- span,
773
- real_function_expr,
774
- vec![ ] ,
775
- )
776
- ] ,
777
- ) ,
778
- )
768
+ vec ! [ b_ident] ,
769
+ // construct `assert_test_result(..)`
770
+ ecx. expr_call (
771
+ span,
772
+ ecx. expr_path ( assert_test_result) ,
773
+ vec ! [
774
+ // construct `real_function(b)`
775
+ ecx. expr_call(
776
+ span,
777
+ real_function_expr,
778
+ vec![ b_expr] ,
779
+ )
780
+ ] ,
781
+ ) ,
782
+ )
783
+ } else {
784
+ // construct `|| {..}`
785
+ ecx. lambda (
786
+ span,
787
+ vec ! [ ] ,
788
+ // construct `assert_test_result(..)`
789
+ ecx. expr_call (
790
+ span,
791
+ ecx. expr_path ( assert_test_result) ,
792
+ vec ! [
793
+ // construct `real_function()`
794
+ ecx. expr_call(
795
+ span,
796
+ real_function_expr,
797
+ vec![ ] ,
798
+ )
799
+ ] ,
800
+ ) ,
801
+ )
802
+ }
779
803
} ;
780
804
781
805
let variant_name = if test. bench { "StaticBenchFn" } else { "StaticTestFn" } ;
0 commit comments