summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_builtin_macros/src/test.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--compiler/rustc_builtin_macros/src/test.rs48
1 files changed, 30 insertions, 18 deletions
diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs
index e20375689..fee5d04cd 100644
--- a/compiler/rustc_builtin_macros/src/test.rs
+++ b/compiler/rustc_builtin_macros/src/test.rs
@@ -1,7 +1,6 @@
/// The expansion from a test function to the appropriate test struct for libtest
/// Ideally, this code would be in libtest but for efficiency and error messages it lives here.
use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute};
-
use rustc_ast as ast;
use rustc_ast::attr;
use rustc_ast::ptr::P;
@@ -11,8 +10,8 @@ use rustc_expand::base::*;
use rustc_session::Session;
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::Span;
-
use std::iter;
+use thin_vec::thin_vec;
// #[test_case] is used by custom test authors to mark tests
// When building for test, it needs to make the item public and gensym the name
@@ -37,13 +36,22 @@ pub fn expand_test_case(
let sp = ecx.with_def_site_ctxt(attr_sp);
let mut item = anno_item.expect_item();
item = item.map(|mut item| {
+ let test_path_symbol = Symbol::intern(&item_path(
+ // skip the name of the root module
+ &ecx.current_expansion.module.mod_path[1..],
+ &item.ident,
+ ));
item.vis = ast::Visibility {
span: item.vis.span,
kind: ast::VisibilityKind::Public,
tokens: None,
};
item.ident.span = item.ident.span.with_ctxt(sp.ctxt());
- item.attrs.push(ecx.attribute(ecx.meta_word(sp, sym::rustc_test_marker)));
+ item.attrs.push(ecx.attribute(attr::mk_name_value_item_str(
+ Ident::new(sym::rustc_test_marker, sp),
+ test_path_symbol,
+ sp,
+ )));
item
});
@@ -116,7 +124,7 @@ pub fn expand_test_or_bench(
// reworked in the future to not need it, it'd be nice.
_ => diag.struct_span_err(attr_sp, msg).forget_guarantee(),
};
- err.span_label(attr_sp, "the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions")
+ err.span_label(attr_sp, "the `#[test]` macro causes a function to be run on a test and has no effect on non-functions")
.span_label(item.span, format!("expected a non-associated function, found {} {}", item.kind.article(), item.kind.descr()))
.span_suggestion(attr_sp, "replace with conditional compilation to make the item only exist when tests are being run", "#[cfg(test)]", Applicability::MaybeIncorrect)
.emit();
@@ -216,18 +224,29 @@ pub fn expand_test_or_bench(
)
};
+ let test_path_symbol = Symbol::intern(&item_path(
+ // skip the name of the root module
+ &cx.current_expansion.module.mod_path[1..],
+ &item.ident,
+ ));
+
let mut test_const = cx.item(
sp,
Ident::new(item.ident.name, sp),
- vec![
+ thin_vec![
// #[cfg(test)]
cx.attribute(attr::mk_list_item(
Ident::new(sym::cfg, attr_sp),
vec![attr::mk_nested_word_item(Ident::new(sym::test, attr_sp))],
)),
- // #[rustc_test_marker]
- cx.attribute(cx.meta_word(attr_sp, sym::rustc_test_marker)),
- ],
+ // #[rustc_test_marker = "test_case_sort_key"]
+ cx.attribute(attr::mk_name_value_item_str(
+ Ident::new(sym::rustc_test_marker, attr_sp),
+ test_path_symbol,
+ attr_sp,
+ )),
+ ]
+ .into(),
// const $ident: test::TestDescAndFn =
ast::ItemKind::Const(
ast::Defaultness::Final,
@@ -251,14 +270,7 @@ pub fn expand_test_or_bench(
cx.expr_call(
sp,
cx.expr_path(test_path("StaticTestName")),
- vec![cx.expr_str(
- sp,
- Symbol::intern(&item_path(
- // skip the name of the root module
- &cx.current_expansion.module.mod_path[1..],
- &item.ident,
- )),
- )],
+ vec![cx.expr_str(sp, test_path_symbol)],
),
),
// ignore: true | false
@@ -334,9 +346,9 @@ pub fn expand_test_or_bench(
});
// extern crate test
- let test_extern = cx.item(sp, test_id, vec![], ast::ItemKind::ExternCrate(None));
+ let test_extern = cx.item(sp, test_id, ast::AttrVec::new(), ast::ItemKind::ExternCrate(None));
- tracing::debug!("synthetic test item:\n{}\n", pprust::item_to_string(&test_const));
+ debug!("synthetic test item:\n{}\n", pprust::item_to_string(&test_const));
if is_stmt {
vec![