Skip to content

Commit 0463566

Browse files
committed
syntax: clarify field name
The value of this field is meant to indicate whether or not the crate is rustc's libtest itself - not whether or not it is a test crate generally.
1 parent f2fb457 commit 0463566

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/libsyntax/test.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -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 {
452454
fn 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-
616611
fn mk_test_descs(cx: &TestCtxt) -> P<ast::Expr> {
617612
debug!("building test vector from {} tests", cx.testfns.len());
618613

0 commit comments

Comments
 (0)