Auto merge of #21824 - sfackler:should_panic, r=alexcrichton

This commit is contained in:
bors 2015-03-09 18:32:16 +00:00
commit 638832e64c
42 changed files with 136 additions and 128 deletions

View File

@ -332,7 +332,7 @@ pub fn make_test<F>(config: &Config, testfile: &Path, f: F) -> test::TestDescAnd
desc: test::TestDesc {
name: make_test_name(config, testfile),
ignore: header::is_test_ignored(config, testfile),
should_fail: test::ShouldFail::No,
should_panic: test::ShouldPanic::No,
},
testfn: f(),
}

View File

@ -323,7 +323,7 @@ fn test_arena_destructors() {
}
#[test]
#[should_fail]
#[should_panic]
fn test_arena_destructors_fail() {
let arena = Arena::new();
// Put some stuff in the arena.

View File

@ -490,7 +490,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn test_overflow() {
#[allow(dead_code)]
#[derive(Copy)]

View File

@ -1647,14 +1647,14 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_tail_empty() {
let a = Vec::<i32>::new();
a.tail();
}
#[test]
#[should_fail]
#[should_panic]
fn test_tail_mut_empty() {
let mut a = Vec::<i32>::new();
a.tail_mut();
@ -1681,14 +1681,14 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_init_empty() {
let a = Vec::<i32>::new();
a.init();
}
#[test]
#[should_fail]
#[should_panic]
fn test_init_mut_empty() {
let mut a = Vec::<i32>::new();
a.init_mut();
@ -1790,7 +1790,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_swap_remove_fail() {
let mut v = vec![1];
let _ = v.swap_remove(0);
@ -2205,7 +2205,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_insert_oob() {
let mut a = vec![1, 2, 3];
a.insert(4, 5);
@ -2229,7 +2229,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_remove_fail() {
let mut a = vec![1];
let _ = a.remove(0);
@ -2253,7 +2253,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_permute_fail() {
let v: [(Box<_>, Rc<_>); 4] =
[(box 0, Rc::new(0)), (box 0, Rc::new(0)),
@ -2528,7 +2528,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_windowsator_0() {
let v = &[1,2,3,4];
let _it = v.windows(0);
@ -2564,7 +2564,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_chunksator_0() {
let v = &[1,2,3,4];
let _it = v.chunks(0);
@ -2647,7 +2647,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_overflow_does_not_cause_segfault() {
let mut v = vec![];
v.reserve_exact(-1);
@ -2656,7 +2656,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_overflow_does_not_cause_segfault_managed() {
let mut v = vec![Rc::new(1)];
v.reserve_exact(-1);
@ -2833,7 +2833,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_mut_chunks_0() {
let mut v = [1, 2, 3, 4];
let _it = v.chunks_mut(0);

View File

@ -1877,7 +1877,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_slice_fail() {
"中华Việt Nam".slice(0, 2);
}
@ -2095,7 +2095,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_as_bytes_fail() {
// Don't double free. (I'm not sure if this exercises the
// original problem code path anymore.)
@ -2132,7 +2132,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_subslice_offset_2() {
let a = "alchemiter";
let b = "cruxtruder";

View File

@ -1232,14 +1232,14 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_str_truncate_invalid_len() {
let mut s = String::from_str("12345");
s.truncate(6);
}
#[test]
#[should_fail]
#[should_panic]
fn test_str_truncate_split_codepoint() {
let mut s = String::from_str("\u{FC}"); // ü
s.truncate(1);
@ -1272,7 +1272,7 @@ mod tests {
assert_eq!(s, "ไทย中华Vit Nam; foobar");
}
#[test] #[should_fail]
#[test] #[should_panic]
fn remove_bad() {
"".to_string().remove(1);
}
@ -1286,8 +1286,8 @@ mod tests {
assert_eq!(s, "ệfooยbar");
}
#[test] #[should_fail] fn insert_bad1() { "".to_string().insert(1, 't'); }
#[test] #[should_fail] fn insert_bad2() { "".to_string().insert(1, 't'); }
#[test] #[should_panic] fn insert_bad1() { "".to_string().insert(1, 't'); }
#[test] #[should_panic] fn insert_bad2() { "".to_string().insert(1, 't'); }
#[test]
fn test_slicing() {

View File

@ -2242,7 +2242,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_vec_truncate_fail() {
struct BadElem(i32);
impl Drop for BadElem {
@ -2265,49 +2265,49 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_index_out_of_bounds() {
let vec = vec![1, 2, 3];
let _ = vec[3];
}
#[test]
#[should_fail]
#[should_panic]
fn test_slice_out_of_bounds_1() {
let x = vec![1, 2, 3, 4, 5];
&x[-1..];
}
#[test]
#[should_fail]
#[should_panic]
fn test_slice_out_of_bounds_2() {
let x = vec![1, 2, 3, 4, 5];
&x[..6];
}
#[test]
#[should_fail]
#[should_panic]
fn test_slice_out_of_bounds_3() {
let x = vec![1, 2, 3, 4, 5];
&x[-1..4];
}
#[test]
#[should_fail]
#[should_panic]
fn test_slice_out_of_bounds_4() {
let x = vec![1, 2, 3, 4, 5];
&x[1..6];
}
#[test]
#[should_fail]
#[should_panic]
fn test_slice_out_of_bounds_5() {
let x = vec![1, 2, 3, 4, 5];
&x[3..2];
}
#[test]
#[should_fail]
#[should_panic]
fn test_swap_remove_empty() {
let mut vec= Vec::<i32>::new();
vec.swap_remove(0);
@ -2326,7 +2326,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_map_in_place_incompatible_types_fail() {
let v = vec![0, 1, 2];
v.map_in_place(|_| ());

View File

@ -1884,7 +1884,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_index_out_of_bounds() {
let mut deq = VecDeque::new();
for i in 1..4 {

View File

@ -1432,7 +1432,7 @@ mod test_map {
}
#[test]
#[should_fail]
#[should_panic]
fn test_index_nonexistent() {
let mut map = VecMap::new();

View File

@ -109,7 +109,7 @@ fn double_borrow_single_release_no_borrow_mut() {
}
#[test]
#[should_fail]
#[should_panic]
fn discard_doesnt_unborrow() {
let x = RefCell::new(0);
let _b = x.borrow();

View File

@ -30,7 +30,7 @@ fn test_success() {
}
#[test]
#[should_fail]
#[should_panic]
fn test_fail() {
let mut i = 0;
try_finally(

View File

@ -161,7 +161,7 @@ fn test_format_radix() {
}
#[test]
#[should_fail]
#[should_panic]
fn test_radix_base_too_large() {
let _ = radix(55, 37);
}

View File

@ -581,7 +581,7 @@ fn test_rposition() {
}
#[test]
#[should_fail]
#[should_panic]
fn test_rposition_panic() {
let v: [(Box<_>, Box<_>); 4] =
[(box 0, box 0), (box 0, box 0),

View File

@ -80,7 +80,7 @@ fn test_option_dance() {
assert!(y.is_none());
}
#[test] #[should_fail]
#[test] #[should_panic]
fn test_option_too_much_dance() {
let mut y = Some(marker::NoCopy);
let _y2 = y.take().unwrap();
@ -139,14 +139,14 @@ fn test_unwrap() {
}
#[test]
#[should_fail]
#[should_panic]
fn test_unwrap_panic1() {
let x: Option<int> = None;
x.unwrap();
}
#[test]
#[should_fail]
#[should_panic]
fn test_unwrap_panic2() {
let x: Option<String> = None;
x.unwrap();

View File

@ -126,7 +126,7 @@ pub fn test_unwrap_or_else() {
}
#[test]
#[should_fail]
#[should_panic]
pub fn test_unwrap_or_else_panic() {
fn handler(msg: &'static str) -> int {
if msg == "I got this." {

View File

@ -109,12 +109,12 @@ mod test {
}
}
#[test]
#[should_fail]
#[should_panic]
fn test_exp_invalid_lambda_zero() {
Exp::new(0.0);
}
#[test]
#[should_fail]
#[should_panic]
fn test_exp_invalid_lambda_neg() {
Exp::new(-10.0);
}

View File

@ -356,7 +356,7 @@ mod test {
}
}
#[test]
#[should_fail]
#[should_panic]
fn test_chi_squared_invalid_dof() {
ChiSquared::new(-1.0);
}

View File

@ -351,16 +351,16 @@ mod tests {
[50, 51, 52, 53, 54, 55, 56]);
}
#[test] #[should_fail]
#[test] #[should_panic]
fn test_weighted_choice_no_items() {
WeightedChoice::<int>::new(&mut []);
}
#[test] #[should_fail]
#[test] #[should_panic]
fn test_weighted_choice_zero_weight() {
WeightedChoice::new(&mut [Weighted { weight: 0, item: 0},
Weighted { weight: 0, item: 1}]);
}
#[test] #[should_fail]
#[test] #[should_panic]
fn test_weighted_choice_weight_overflows() {
let x = (-1) as uint / 2; // x + x + 2 is the overflow
WeightedChoice::new(&mut [Weighted { weight: x, item: 0 },

View File

@ -175,7 +175,7 @@ mod tests {
}
}
#[test]
#[should_fail]
#[should_panic]
fn test_normal_invalid_sd() {
Normal::new(10.0, -1.0);
}
@ -191,7 +191,7 @@ mod tests {
}
}
#[test]
#[should_fail]
#[should_panic]
fn test_log_normal_invalid_sd() {
LogNormal::new(10.0, -1.0);
}

View File

@ -169,12 +169,12 @@ mod tests {
use distributions::{Sample, IndependentSample};
use super::Range as Range;
#[should_fail]
#[should_panic]
#[test]
fn test_range_bad_limits_equal() {
Range::new(10, 10);
}
#[should_fail]
#[should_panic]
#[test]
fn test_range_bad_limits_flipped() {
Range::new(10, 5);

View File

@ -548,7 +548,7 @@ mod tests {
// A simple failure case - adding 1 to the max value
#[test]
#[should_fail]
#[should_panic]
fn test_add_bytes_to_bits_overflow() {
super::add_bytes_to_bits::<u64>(Int::max_value(), 1);
}

View File

@ -114,7 +114,7 @@ pub fn run(input: &str,
#[allow(deprecated)]
fn runtest(test: &str, cratename: &str, libs: SearchPaths,
externs: core::Externs,
should_fail: bool, no_run: bool, as_test_harness: bool) {
should_panic: bool, no_run: bool, as_test_harness: bool) {
// the test harness wants its own `main` & top level functions, so
// never wrap the test in `fn main() { ... }`
let test = maketest(test, Some(cratename), true, as_test_harness);
@ -210,9 +210,9 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths,
" - maybe your tempdir is mounted with noexec?"
} else { "" }),
Ok(out) => {
if should_fail && out.status.success() {
if should_panic && out.status.success() {
panic!("test executable succeeded when it should have failed");
} else if !should_fail && !out.status.success() {
} else if !should_panic && !out.status.success() {
panic!("test executable failed:\n{:?}",
str::from_utf8(&out.stdout));
}
@ -279,7 +279,7 @@ impl Collector {
}
pub fn add_test(&mut self, test: String,
should_fail: bool, no_run: bool, should_ignore: bool, as_test_harness: bool) {
should_panic: bool, no_run: bool, should_ignore: bool, as_test_harness: bool) {
let name = if self.use_headers {
let s = self.current_header.as_ref().map(|s| &**s).unwrap_or("");
format!("{}_{}", s, self.cnt)
@ -295,14 +295,14 @@ impl Collector {
desc: testing::TestDesc {
name: testing::DynTestName(name),
ignore: should_ignore,
should_fail: testing::ShouldFail::No, // compiler failures are test failures
should_panic: testing::ShouldPanic::No, // compiler failures are test failures
},
testfn: testing::DynTestFn(Thunk::new(move|| {
runtest(&test,
&cratename,
libs,
externs,
should_fail,
should_panic,
no_run,
as_test_harness);
}))

View File

@ -2197,7 +2197,7 @@ mod test_map {
}
#[test]
#[should_fail]
#[should_panic]
fn test_index_nonexistent() {
let mut map = HashMap::new();

View File

@ -658,7 +658,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn dont_panic_in_drop_on_panicked_flush() {
struct FailFlushWriter;

View File

@ -396,7 +396,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn read_to_end_error() {
let mut reader = ThreeChunkReader {
count: 0,

View File

@ -333,7 +333,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn oneshot_fail() {
let mut timer = Timer::new().unwrap();
let _rx = timer.oneshot(Duration::milliseconds(1));
@ -341,7 +341,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn period_fail() {
let mut timer = Timer::new().unwrap();
let _rx = timer.periodic(Duration::milliseconds(1));
@ -349,7 +349,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn normal_fail() {
let _timer = Timer::new().unwrap();
panic!();

View File

@ -1324,7 +1324,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn test_not_utf8_panics() {
Path::new(b"hello\x80.txt");
}

View File

@ -500,14 +500,14 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn test_gen_range_panic_int() {
let mut r = thread_rng();
r.gen_range(5, -2);
}
#[test]
#[should_fail]
#[should_panic]
fn test_gen_range_panic_uint() {
let mut r = thread_rng();
r.gen_range(5, 2);

View File

@ -114,7 +114,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn test_reader_rng_insufficient_bytes() {
let mut rng = ReaderRng::new(MemReader::new(vec!()));
let mut v = [0; 3];

View File

@ -479,7 +479,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn two_mutexes() {
static M1: StaticMutex = MUTEX_INIT;
static M2: StaticMutex = MUTEX_INIT;

View File

@ -204,7 +204,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn test_future_panic() {
let mut f = Future::spawn(move|| panic!());
let _x: String = f.get();

View File

@ -164,7 +164,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn test_zero_tasks_panic() {
TaskPool::new(0);
}

View File

@ -1030,14 +1030,14 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn wtf8buf_truncate_fail_code_point_boundary() {
let mut string = Wtf8Buf::from_str("");
string.truncate(2);
}
#[test]
#[should_fail]
#[should_panic]
fn wtf8buf_truncate_fail_longer() {
let mut string = Wtf8Buf::from_str("");
string.truncate(4);
@ -1133,7 +1133,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn wtf8_slice_not_code_point_boundary() {
&Wtf8::from_str("aé 💩")[2.. 4];
}
@ -1144,7 +1144,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn wtf8_slice_from_not_code_point_boundary() {
&Wtf8::from_str("aé 💩")[2..];
}
@ -1155,7 +1155,7 @@ mod tests {
}
#[test]
#[should_fail]
#[should_panic]
fn wtf8_slice_to_not_code_point_boundary() {
&Wtf8::from_str("aé 💩")[5..];
}

View File

@ -922,7 +922,7 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn t2 () {
let cm = CodeMap::new();
let fm = cm.new_filemap("blork.rs".to_string(),

View File

@ -1656,7 +1656,7 @@ mod test {
}
// make sure that macros can't escape fns
#[should_fail]
#[should_panic]
#[test] fn macros_cant_escape_fns_test () {
let src = "fn bogus() {macro_rules! z (() => (3+4));}\
fn inty() -> i32 { z!() }".to_string();
@ -1670,7 +1670,7 @@ mod test {
}
// make sure that macros can't escape modules
#[should_fail]
#[should_panic]
#[test] fn macros_cant_escape_mods_test () {
let src = "mod foo {macro_rules! z (() => (3+4));}\
fn inty() -> i32 { z!() }".to_string();

View File

@ -813,7 +813,7 @@ mod test {
}))
}
#[should_fail]
#[should_panic]
#[test] fn bad_path_expr_1() {
string_to_expr("::abc::def::return".to_string());
}

View File

@ -37,7 +37,7 @@ use {ast, ast_util};
use ptr::P;
use util::small_vector::SmallVector;
enum ShouldFail {
enum ShouldPanic {
No,
Yes(Option<InternedString>),
}
@ -47,7 +47,7 @@ struct Test {
path: Vec<ast::Ident> ,
bench: bool,
ignore: bool,
should_fail: ShouldFail
should_panic: ShouldPanic
}
struct TestCtxt<'a> {
@ -136,7 +136,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
path: self.cx.path.clone(),
bench: is_bench_fn(&self.cx, &*i),
ignore: is_ignored(&*i),
should_fail: should_fail(&*i)
should_panic: should_panic(&*i, self.cx.span_diagnostic)
};
self.cx.testfns.push(test);
self.tests.push(i.ident);
@ -378,15 +378,23 @@ fn is_ignored(i: &ast::Item) -> bool {
i.attrs.iter().any(|attr| attr.check_name("ignore"))
}
fn should_fail(i: &ast::Item) -> ShouldFail {
match i.attrs.iter().find(|attr| attr.check_name("should_fail")) {
fn should_panic(i: &ast::Item, diag: &diagnostic::SpanHandler) -> ShouldPanic {
match i.attrs.iter().find(|attr| {
if attr.check_name("should_panic") { return true; }
if attr.check_name("should_fail") {
diag.span_warn(attr.span, "`#[should_fail]` is deprecated. Use `#[should_panic]` \
instead");
return true;
}
false
}) {
Some(attr) => {
let msg = attr.meta_item_list()
.and_then(|list| list.iter().find(|mi| mi.check_name("expected")))
.and_then(|mi| mi.value_str());
ShouldFail::Yes(msg)
ShouldPanic::Yes(msg)
}
None => ShouldFail::No,
None => ShouldPanic::No,
}
}
@ -617,13 +625,13 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
vec![name_expr]);
let ignore_expr = ecx.expr_bool(span, test.ignore);
let should_fail_path = |name| {
ecx.path(span, vec![self_id, test_id, ecx.ident_of("ShouldFail"), ecx.ident_of(name)])
let should_panic_path = |name| {
ecx.path(span, vec![self_id, test_id, ecx.ident_of("ShouldPanic"), ecx.ident_of(name)])
};
let fail_expr = match test.should_fail {
ShouldFail::No => ecx.expr_path(should_fail_path("No")),
ShouldFail::Yes(ref msg) => {
let path = should_fail_path("Yes");
let fail_expr = match test.should_panic {
ShouldPanic::No => ecx.expr_path(should_panic_path("No")),
ShouldPanic::Yes(ref msg) => {
let path = should_panic_path("Yes");
let arg = match *msg {
Some(ref msg) => ecx.expr_some(span, ecx.expr_str(span, msg.clone())),
None => ecx.expr_none(span),
@ -638,7 +646,7 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P<ast::Expr> {
test_path("TestDesc"),
vec![field("name", name_expr),
field("ignore", ignore_expr),
field("should_fail", fail_expr)]);
field("should_panic", fail_expr)]);
let mut visible_path = match cx.toplevel_reexport {

View File

@ -234,7 +234,7 @@ mod tests {
use ast::Name;
#[test]
#[should_fail]
#[should_panic]
fn i1 () {
let i : Interner<RcStr> = Interner::new();
i.get(Name(13));

View File

@ -236,13 +236,13 @@ mod test {
}
#[test]
#[should_fail]
#[should_panic]
fn test_expect_one_zero() {
let _: isize = SmallVector::zero().expect_one("");
}
#[test]
#[should_fail]
#[should_panic]
fn test_expect_one_many() {
SmallVector::many(vec!(1, 2)).expect_one("");
}

View File

@ -90,7 +90,7 @@ pub mod test {
Metric, MetricMap,
StaticTestFn, StaticTestName, DynTestName, DynTestFn,
run_test, test_main, test_main_static, filter_tests,
parse_opts, StaticBenchFn, ShouldFail};
parse_opts, StaticBenchFn, ShouldPanic};
}
pub mod stats;
@ -202,7 +202,7 @@ pub struct Bencher {
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum ShouldFail {
pub enum ShouldPanic {
No,
Yes(Option<&'static str>)
}
@ -213,7 +213,7 @@ pub enum ShouldFail {
pub struct TestDesc {
pub name: TestName,
pub ignore: bool,
pub should_fail: ShouldFail,
pub should_panic: ShouldPanic,
}
unsafe impl Send for TestDesc {}
@ -351,10 +351,10 @@ Test Attributes:
takes no arguments.
#[bench] - Indicates a function is a benchmark to be run. This
function takes one argument (test::Bencher).
#[should_fail] - This function (also labeled with #[test]) will only pass if
the code causes a failure (an assertion failure or panic!)
#[should_panic] - This function (also labeled with #[test]) will only pass if
the code causes a panic (an assertion failure or panic!)
A message may be provided, which the failure string must
contain: #[should_fail(expected = "foo")].
contain: #[should_panic(expected = "foo")].
#[ignore] - When applied to a function which is already attributed as a
test, then the test runner will ignore these tests during
normal test runs. Running with --ignored will run these
@ -717,13 +717,13 @@ fn should_sort_failures_before_printing_them() {
let test_a = TestDesc {
name: StaticTestName("a"),
ignore: false,
should_fail: ShouldFail::No
should_panic: ShouldPanic::No
};
let test_b = TestDesc {
name: StaticTestName("b"),
ignore: false,
should_fail: ShouldFail::No
should_panic: ShouldPanic::No
};
let mut st = ConsoleTestState {
@ -953,10 +953,10 @@ pub fn run_test(opts: &TestOpts,
}
fn calc_result(desc: &TestDesc, task_result: Result<(), Box<Any+Send>>) -> TestResult {
match (&desc.should_fail, task_result) {
(&ShouldFail::No, Ok(())) |
(&ShouldFail::Yes(None), Err(_)) => TrOk,
(&ShouldFail::Yes(Some(msg)), Err(ref err))
match (&desc.should_panic, task_result) {
(&ShouldPanic::No, Ok(())) |
(&ShouldPanic::Yes(None), Err(_)) => TrOk,
(&ShouldPanic::Yes(Some(msg)), Err(ref err))
if err.downcast_ref::<String>()
.map(|e| &**e)
.or_else(|| err.downcast_ref::<&'static str>().map(|e| *e))
@ -1151,7 +1151,7 @@ mod tests {
use test::{TrFailed, TrIgnored, TrOk, filter_tests, parse_opts,
TestDesc, TestDescAndFn, TestOpts, run_test,
MetricMap,
StaticTestName, DynTestName, DynTestFn, ShouldFail};
StaticTestName, DynTestName, DynTestFn, ShouldPanic};
use std::thunk::Thunk;
use std::sync::mpsc::channel;
@ -1162,7 +1162,7 @@ mod tests {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: true,
should_fail: ShouldFail::No,
should_panic: ShouldPanic::No,
},
testfn: DynTestFn(Thunk::new(move|| f())),
};
@ -1179,7 +1179,7 @@ mod tests {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: true,
should_fail: ShouldFail::No,
should_panic: ShouldPanic::No,
},
testfn: DynTestFn(Thunk::new(move|| f())),
};
@ -1190,13 +1190,13 @@ mod tests {
}
#[test]
fn test_should_fail() {
fn test_should_panic() {
fn f() { panic!(); }
let desc = TestDescAndFn {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
should_fail: ShouldFail::Yes(None)
should_panic: ShouldPanic::Yes(None)
},
testfn: DynTestFn(Thunk::new(move|| f())),
};
@ -1207,13 +1207,13 @@ mod tests {
}
#[test]
fn test_should_fail_good_message() {
fn test_should_panic_good_message() {
fn f() { panic!("an error message"); }
let desc = TestDescAndFn {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
should_fail: ShouldFail::Yes(Some("error message"))
should_panic: ShouldPanic::Yes(Some("error message"))
},
testfn: DynTestFn(Thunk::new(move|| f())),
};
@ -1224,13 +1224,13 @@ mod tests {
}
#[test]
fn test_should_fail_bad_message() {
fn test_should_panic_bad_message() {
fn f() { panic!("an error message"); }
let desc = TestDescAndFn {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
should_fail: ShouldFail::Yes(Some("foobar"))
should_panic: ShouldPanic::Yes(Some("foobar"))
},
testfn: DynTestFn(Thunk::new(move|| f())),
};
@ -1241,13 +1241,13 @@ mod tests {
}
#[test]
fn test_should_fail_but_succeeds() {
fn test_should_panic_but_succeeds() {
fn f() { }
let desc = TestDescAndFn {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
should_fail: ShouldFail::Yes(None)
should_panic: ShouldPanic::Yes(None)
},
testfn: DynTestFn(Thunk::new(move|| f())),
};
@ -1283,7 +1283,7 @@ mod tests {
desc: TestDesc {
name: StaticTestName("1"),
ignore: true,
should_fail: ShouldFail::No,
should_panic: ShouldPanic::No,
},
testfn: DynTestFn(Thunk::new(move|| {})),
},
@ -1291,7 +1291,7 @@ mod tests {
desc: TestDesc {
name: StaticTestName("2"),
ignore: false,
should_fail: ShouldFail::No,
should_panic: ShouldPanic::No,
},
testfn: DynTestFn(Thunk::new(move|| {})),
});
@ -1327,7 +1327,7 @@ mod tests {
desc: TestDesc {
name: DynTestName((*name).clone()),
ignore: false,
should_fail: ShouldFail::No,
should_panic: ShouldPanic::No,
},
testfn: DynTestFn(Thunk::new(testfn)),
};

View File

@ -14,7 +14,7 @@
// ignore-pretty: does not work well with `--test`
#[test]
#[should_fail(expected = "foobar")]
#[should_panic(expected = "foobar")]
fn test_foo() {
panic!("blah")
}

View File

@ -12,13 +12,13 @@
// ignore-pretty: does not work well with `--test`
#[test]
#[should_fail(expected = "foo")]
#[should_panic(expected = "foo")]
fn test_foo() {
panic!("foo bar")
}
#[test]
#[should_fail(expected = "foo")]
#[should_panic(expected = "foo")]
fn test_foo_dynamic() {
panic!("{} bar", "foo")
}