@@ -61,7 +61,7 @@ struct TestCtxt<'a> {
61
61
ext_cx : ExtCtxt < ' a > ,
62
62
testfns : Vec < Test > ,
63
63
reexport_test_harness_main : Option < Symbol > ,
64
- is_test_crate : bool ,
64
+ is_libtest : bool ,
65
65
ctxt : SyntaxContext ,
66
66
67
67
// top-level re-export submodule, filled out after folding is finished
@@ -271,13 +271,15 @@ fn generate_test_harness(sess: &ParseSess,
271
271
let krate = cleaner. fold_crate ( krate) ;
272
272
273
273
let mark = Mark :: fresh ( Mark :: root ( ) ) ;
274
+
274
275
let mut cx: TestCtxt = TestCtxt {
275
276
span_diagnostic : sd,
276
277
ext_cx : ExtCtxt :: new ( sess, ExpansionConfig :: default ( "test" . to_string ( ) ) , resolver) ,
277
278
path : Vec :: new ( ) ,
278
279
testfns : Vec :: new ( ) ,
279
280
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 ) ,
281
283
toplevel_reexport : None ,
282
284
ctxt : SyntaxContext :: empty ( ) . apply_mark ( mark) ,
283
285
} ;
@@ -452,7 +454,7 @@ mod __test {
452
454
fn mk_std ( cx : & TestCtxt ) -> P < ast:: Item > {
453
455
let id_test = Ident :: from_str ( "test" ) ;
454
456
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 {
456
458
( ast:: ItemKind :: Use (
457
459
P ( nospan ( ast:: ViewPathSimple ( id_test,
458
460
path_node ( vec ! [ id_test] ) ) ) ) ) ,
@@ -606,13 +608,6 @@ fn mk_tests(cx: &TestCtxt) -> P<ast::Item> {
606
608
test_descs)
607
609
}
608
610
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
-
616
611
fn mk_test_descs ( cx : & TestCtxt ) -> P < ast:: Expr > {
617
612
debug ! ( "building test vector from {} tests" , cx. testfns. len( ) ) ;
618
613
0 commit comments