Skip to content

Commit 1509492

Browse files
committed
Fix test failures
1 parent 4f2b1eb commit 1509492

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

src/libsyntax/test.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -328,23 +328,6 @@ enum BadTestSignature {
328328
ShouldPanicOnlyWithNoArgs,
329329
}
330330

331-
/// Will create a use or extern statement to expose the functions
332-
/// contained in the test crate. This function works even when
333-
/// compiling libtest.
334-
fn mk_use_test(cx: &TestCtxt) -> P<ast::Item> {
335-
let id_test = Ident::from_str("test");
336-
let sp = ignored_span(cx, DUMMY_SP);
337-
let ecx = &cx.ext_cx;
338-
339-
if cx.is_libtest {
340-
ecx.item_use_simple(sp,
341-
respan(sp, ast::VisibilityKind::Public),
342-
ecx.path(sp, vec![id_test]))
343-
} else {
344-
ecx.item_extern_crate(sp, id_test)
345-
}
346-
}
347-
348331
/// Creates a function item for use as the main function of a test build.
349332
/// This function will call the `test_runner` as specified by the crate attribute
350333
fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
@@ -355,11 +338,12 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
355338
// }
356339
let sp = ignored_span(cx, DUMMY_SP);
357340
let ecx = &cx.ext_cx;
341+
let test_id = ecx.ident_of("test").gensym();
358342

359343
// test::test_main_static(...)
360344
let mut test_runner = cx.test_runner.clone().unwrap_or(
361345
ecx.path(sp, vec![
362-
ecx.ident_of("test"), ecx.ident_of("test_main_static")
346+
test_id, ecx.ident_of("test_main_static")
363347
]));
364348

365349
test_runner.span = sp;
@@ -373,12 +357,16 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
373357
let main_meta = ecx.meta_word(sp, Symbol::intern("main"));
374358
let main_attr = ecx.attribute(sp, main_meta);
375359

376-
// extern test
377-
let use_test = ecx.stmt_item(sp, mk_use_test(cx));
360+
// extern crate test as test_gensym
361+
let test_extern_stmt = ecx.stmt_item(sp, ecx.item(sp,
362+
test_id,
363+
vec![],
364+
ast::ItemKind::ExternCrate(Some(Symbol::intern("test")))
365+
));
378366

379367
// pub fn main() { ... }
380368
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![]));
381-
let main_body = ecx.block(sp, vec![use_test, call_test_main]);
369+
let main_body = ecx.block(sp, vec![test_extern_stmt, call_test_main]);
382370
let main = ast::ItemKind::Fn(ecx.fn_decl(vec![], ast::FunctionRetTy::Ty(main_ret_ty)),
383371
ast::FnHeader::default(),
384372
ast::Generics::default(),

src/libtest/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#![feature(panic_unwind)]
4141
#![feature(staged_api)]
4242
#![feature(termination_trait_lib)]
43+
#![feature(test)]
4344

4445
extern crate getopts;
4546
#[cfg(any(unix, target_os = "cloudabi"))]

src/libtest/stats.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ mod tests {
907907

908908
#[cfg(test)]
909909
mod bench {
910-
use Bencher;
910+
extern crate test;
911+
use self::test::Bencher;
911912
use stats::Stats;
912913

913914
#[bench]

src/test/incremental/issue-49595/issue_49595.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
#![feature(rustc_attrs)]
1616
#![crate_type = "rlib"]
1717

18-
#![rustc_partition_codegened(module="issue_49595-__test", cfg="cfail2")]
18+
#![rustc_partition_codegened(module="issue_49595-tests", cfg="cfail2")]
1919
#![rustc_partition_codegened(module="issue_49595-lit_test", cfg="cfail3")]
2020

2121
mod tests {
22-
#[cfg_attr(not(cfail1), ignore)]
23-
#[test]
22+
#[cfg_attr(not(cfail1), test)]
2423
fn test() {
2524
}
2625
}

0 commit comments

Comments
 (0)