@@ -539,26 +539,8 @@ fn path_node(ids: Vec<ast::Ident> ) -> ast::Path {
539
539
fn mk_tests ( cx : & TestCtxt ) -> P < ast:: Item > {
540
540
// The vector of test_descs for this crate
541
541
let test_descs = mk_test_descs ( cx) ;
542
-
543
- // FIXME #15962: should be using quote_item, but that stringifies
544
- // __test_reexports, causing it to be reinterned, losing the
545
- // gensym information.
546
- let sp = DUMMY_SP ;
547
- let ecx = & cx. ext_cx ;
548
- let struct_type = ecx. ty_path ( ecx. path ( sp, vec ! [ ecx. ident_of( "self" ) ,
549
- ecx. ident_of( "test" ) ,
550
- ecx. ident_of( "TestDescAndFn" ) ] ) ) ;
551
- let static_lt = ecx. lifetime ( sp, token:: special_idents:: static_lifetime. name ) ;
552
- // &'static [self::test::TestDescAndFn]
553
- let static_type = ecx. ty_rptr ( sp,
554
- ecx. ty ( sp, ast:: TyVec ( struct_type) ) ,
555
- Some ( static_lt) ,
556
- ast:: MutImmutable ) ;
557
- // static TESTS: $static_type = &[...];
558
- ecx. item_const ( sp,
559
- ecx. ident_of ( "TESTS" ) ,
560
- static_type,
561
- test_descs)
542
+ quote_item ! ( & cx. ext_cx, const TESTS : & ' static [ self :: test:: TestDescAndFn ] = $test_descs; )
543
+ . unwrap ( )
562
544
}
563
545
564
546
fn is_test_crate ( krate : & ast:: Crate ) -> bool {
@@ -586,57 +568,31 @@ fn mk_test_descs(cx: &TestCtxt) -> P<ast::Expr> {
586
568
}
587
569
588
570
fn mk_test_desc_and_fn_rec ( cx : & TestCtxt , test : & Test ) -> P < ast:: Expr > {
589
- // FIXME #15962: should be using quote_expr, but that stringifies
590
- // __test_reexports, causing it to be reinterned, losing the
591
- // gensym information.
592
-
593
571
let span = ignored_span ( cx, test. span ) ;
594
572
let path = test. path . clone ( ) ;
595
573
let ecx = & cx. ext_cx ;
596
- let self_id = ecx. ident_of ( "self" ) ;
597
- let test_id = ecx. ident_of ( "test" ) ;
598
-
599
- // creates self::test::$name
600
- let test_path = |name| {
601
- ecx. path ( span, vec ! [ self_id, test_id, ecx. ident_of( name) ] )
602
- } ;
603
- // creates $name: $expr
604
- let field = |name, expr| ecx. field_imm ( span, ecx. ident_of ( name) , expr) ;
605
-
606
- debug ! ( "encoding {}" , ast_util:: path_name_i( & path[ ..] ) ) ;
607
574
608
575
// path to the #[test] function: "foo::bar::baz"
609
- let path_string = ast_util:: path_name_i ( & path[ ..] ) ;
610
- let name_expr = ecx. expr_str ( span, token:: intern_and_get_ident ( & path_string[ ..] ) ) ;
611
-
612
- // self::test::StaticTestName($name_expr)
613
- let name_expr = ecx. expr_call ( span,
614
- ecx. expr_path ( test_path ( "StaticTestName" ) ) ,
615
- vec ! [ name_expr] ) ;
576
+ let path_string = ast_util:: path_name_i ( & path) ;
577
+ debug ! ( "encoding {}" , path_string) ;
616
578
617
579
let ignore_expr = ecx. expr_bool ( span, test. ignore ) ;
618
- let should_fail_path = |name| {
619
- ecx. path ( span, vec ! [ self_id, test_id, ecx. ident_of( "ShouldFail" ) , ecx. ident_of( name) ] )
620
- } ;
621
580
let fail_expr = match test. should_fail {
622
- ShouldFail :: No => ecx . expr_path ( should_fail_path ( "No" ) ) ,
581
+ ShouldFail :: No => quote_expr ! ( ecx , self :: test :: ShouldFail :: No ) ,
623
582
ShouldFail :: Yes ( ref msg) => {
624
- let path = should_fail_path ( "Yes" ) ;
625
583
let arg = match * msg {
626
584
Some ( ref msg) => ecx. expr_some ( span, ecx. expr_str ( span, msg. clone ( ) ) ) ,
627
585
None => ecx. expr_none ( span) ,
628
586
} ;
629
- ecx . expr_call ( span , ecx. expr_path ( path ) , vec ! [ arg] )
587
+ quote_expr ! ( ecx, self :: test :: ShouldFail :: Yes ( $ arg) )
630
588
}
631
589
} ;
632
590
633
- // self::test::TestDesc { ... }
634
- let desc_expr = ecx. expr_struct (
635
- span,
636
- test_path ( "TestDesc" ) ,
637
- vec ! [ field( "name" , name_expr) ,
638
- field( "ignore" , ignore_expr) ,
639
- field( "should_fail" , fail_expr) ] ) ;
591
+ let desc_expr = quote_expr ! ( ecx, self :: test:: TestDesc {
592
+ name: self :: test:: StaticTestName ( $path_string) ,
593
+ ignore: $ignore_expr,
594
+ should_fail: $fail_expr,
595
+ } ) ;
640
596
641
597
642
598
let mut visible_path = match cx. toplevel_reexport {
@@ -650,13 +606,10 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
650
606
651
607
let fn_expr = ecx. expr_path ( ecx. path_global ( span, visible_path) ) ;
652
608
653
- let variant_name = if test. bench { "StaticBenchFn" } else { "StaticTestFn" } ;
654
- // self::test::$variant_name($fn_expr)
655
- let testfn_expr = ecx. expr_call ( span, ecx. expr_path ( test_path ( variant_name) ) , vec ! [ fn_expr] ) ;
609
+ let variant_name = ecx. ident_of ( if test. bench { "StaticBenchFn" } else { "StaticTestFn" } ) ;
656
610
657
- // self::test::TestDescAndFn { ... }
658
- ecx. expr_struct ( span,
659
- test_path ( "TestDescAndFn" ) ,
660
- vec ! [ field( "desc" , desc_expr) ,
661
- field( "testfn" , testfn_expr) ] )
611
+ quote_expr ! ( ecx, self :: test:: TestDescAndFn {
612
+ desc: $desc_expr,
613
+ testfn: self :: test:: $variant_name( $fn_expr) ,
614
+ } )
662
615
}
0 commit comments