1 // http://rust-lang.org/COPYRIGHT.
4 // #[test_case] is used by custom test authors to mark tests
5 // When building for test, it needs to make the item public and gensym the name
6 // Otherwise, we'll omit the item. This behavior means that any item annotated
7 // with #[test_case] is never addressable.
9 // We mark item with an inert attribute "rustc_test_marker" which the test generation
10 // logic will pick up on.
13 use syntax::attr::check_builtin_macro_attribute;
14 use syntax::ext::base::*;
15 use syntax::ext::build::AstBuilder;
16 use syntax::ext::hygiene::SyntaxContext;
17 use syntax::source_map::respan;
18 use syntax::symbol::sym;
22 ecx: &mut ExtCtxt<'_>,
24 meta_item: &ast::MetaItem,
25 anno_item: Annotatable
26 ) -> Vec<Annotatable> {
27 check_builtin_macro_attribute(ecx, meta_item, sym::test_case);
29 if !ecx.ecfg.should_test { return vec![]; }
31 let sp = attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(ecx.current_expansion.id));
32 let mut item = anno_item.expect_item();
33 item = item.map(|mut item| {
34 item.vis = respan(item.vis.span, ast::VisibilityKind::Public);
35 item.ident = item.ident.gensym();
38 ecx.meta_word(sp, sym::rustc_test_marker))
43 return vec![Annotatable::Item(item)]