Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_builtin_macros/src/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,12 @@ fn add_main(cx: &mut TestCtxt<'_>, c: &mut ast::Crate) {
});

// Integrate the new item into existing module structures.
let items = AstFragment::Items(smallvec![test_extern_stmt, main]);
// `extern crate test;` is only needed with the default runner.
let items = AstFragment::Items(if cx.test_runner.is_none() {
smallvec![test_extern_stmt, main]
} else {
smallvec![main]
});
c.items.extend(cx.ext_cx.monotonic_expander().fully_expand_fragment(items).make_items());
}

Expand Down
32 changes: 32 additions & 0 deletions tests/pretty/custom-test-runner.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#![feature(prelude_import)]
#![no_std]
//@ compile-flags: --crate-type=lib --test --remap-path-prefix={{src-base}}/=/the/src/ --remap-path-prefix={{src-base}}\=/the/src/
//@ pretty-compare-only
//@ pretty-mode:expanded
//@ pp-exact:custom-test-runner.pp

// Example taken from the unstable book.

#![feature(custom_test_frameworks)]
#![test_runner(my_runner)]
extern crate std;
#[prelude_import]
use ::std::prelude::rust_2015::*;

fn my_runner(tests: &[&i32]) {
for t in tests {
if **t == 0 {


{ ::std::io::_print(format_args!("PASSED\n")); };
} else { { ::std::io::_print(format_args!("FAILED\n")); }; }
}
}
#[rustc_test_marker = "WILL_PASS"]
pub const WILL_PASS: i32 = 0;
#[rustc_test_marker = "WILL_FAIL"]
pub const WILL_FAIL: i32 = 4;
#[rustc_main]
#[coverage(off)]
#[doc(hidden)]
pub fn main() -> () { my_runner(&[&WILL_FAIL, &WILL_PASS]) }
25 changes: 25 additions & 0 deletions tests/pretty/custom-test-runner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//@ compile-flags: --crate-type=lib --test --remap-path-prefix={{src-base}}/=/the/src/ --remap-path-prefix={{src-base}}\=/the/src/
//@ pretty-compare-only
//@ pretty-mode:expanded
//@ pp-exact:custom-test-runner.pp

// Example taken from the unstable book.

#![feature(custom_test_frameworks)]
#![test_runner(my_runner)]

fn my_runner(tests: &[&i32]) {
for t in tests {
if **t == 0 {
println!("PASSED");
} else {
println!("FAILED");
}
}
}

#[test_case]
const WILL_PASS: i32 = 0;

#[test_case]
const WILL_FAIL: i32 = 4;
Loading