@@ -61,7 +61,7 @@ struct TestCtxt<'a> {
6161 ext_cx : ExtCtxt < ' a > ,
6262 testfns : Vec < Test > ,
6363 reexport_test_harness_main : Option < Symbol > ,
64- is_test_crate : bool ,
64+ is_libtest : bool ,
6565 ctxt : SyntaxContext ,
6666
6767 // top-level re-export submodule, filled out after folding is finished
@@ -271,13 +271,15 @@ fn generate_test_harness(sess: &ParseSess,
271271 let krate = cleaner. fold_crate ( krate) ;
272272
273273 let mark = Mark :: fresh ( Mark :: root ( ) ) ;
274+
274275 let mut cx: TestCtxt = TestCtxt {
275276 span_diagnostic : sd,
276277 ext_cx : ExtCtxt :: new ( sess, ExpansionConfig :: default ( "test" . to_string ( ) ) , resolver) ,
277278 path : Vec :: new ( ) ,
278279 testfns : Vec :: new ( ) ,
279280 reexport_test_harness_main,
280- is_test_crate : is_test_crate ( & krate) ,
281+ // NB: doesn't consider the value of `--crate-name` passed on the command line.
282+ is_libtest : attr:: find_crate_name ( & krate. attrs ) . map ( |s| s == "test" ) . unwrap_or ( false ) ,
281283 toplevel_reexport : None ,
282284 ctxt : SyntaxContext :: empty ( ) . apply_mark ( mark) ,
283285 } ;
@@ -452,7 +454,7 @@ mod __test {
452454fn mk_std ( cx : & TestCtxt ) -> P < ast:: Item > {
453455 let id_test = Ident :: from_str ( "test" ) ;
454456 let sp = ignored_span ( cx, DUMMY_SP ) ;
455- let ( vi, vis, ident) = if cx. is_test_crate {
457+ let ( vi, vis, ident) = if cx. is_libtest {
456458 ( ast:: ItemKind :: Use (
457459 P ( nospan ( ast:: ViewPathSimple ( id_test,
458460 path_node ( vec ! [ id_test] ) ) ) ) ) ,
@@ -606,13 +608,6 @@ fn mk_tests(cx: &TestCtxt) -> P<ast::Item> {
606608 test_descs)
607609}
608610
609- fn is_test_crate ( krate : & ast:: Crate ) -> bool {
610- match attr:: find_crate_name ( & krate. attrs ) {
611- Some ( s) if "test" == s. as_str ( ) => true ,
612- _ => false
613- }
614- }
615-
616611fn mk_test_descs ( cx : & TestCtxt ) -> P < ast:: Expr > {
617612 debug ! ( "building test vector from {} tests" , cx. testfns. len( ) ) ;
618613
0 commit comments