1
Fork 0

Rename #[should_fail] to #[should_panic]

This commit is contained in:
Steven Fackler 2015-01-31 15:08:25 -08:00
parent 2574009af0
commit e2605b42c7
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 { desc: test::TestDesc {
name: make_test_name(config, testfile), name: make_test_name(config, testfile),
ignore: header::is_test_ignored(config, testfile), ignore: header::is_test_ignored(config, testfile),
should_fail: test::ShouldFail::No, should_panic: test::ShouldPanic::No,
}, },
testfn: f(), testfn: f(),
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -922,7 +922,7 @@ mod test {
} }
#[test] #[test]
#[should_fail] #[should_panic]
fn t2 () { fn t2 () {
let cm = CodeMap::new(); let cm = CodeMap::new();
let fm = cm.new_filemap("blork.rs".to_string(), 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 // make sure that macros can't escape fns
#[should_fail] #[should_panic]
#[test] fn macros_cant_escape_fns_test () { #[test] fn macros_cant_escape_fns_test () {
let src = "fn bogus() {macro_rules! z (() => (3+4));}\ let src = "fn bogus() {macro_rules! z (() => (3+4));}\
fn inty() -> i32 { z!() }".to_string(); fn inty() -> i32 { z!() }".to_string();
@ -1670,7 +1670,7 @@ mod test {
} }
// make sure that macros can't escape modules // make sure that macros can't escape modules
#[should_fail] #[should_panic]
#[test] fn macros_cant_escape_mods_test () { #[test] fn macros_cant_escape_mods_test () {
let src = "mod foo {macro_rules! z (() => (3+4));}\ let src = "mod foo {macro_rules! z (() => (3+4));}\
fn inty() -> i32 { z!() }".to_string(); fn inty() -> i32 { z!() }".to_string();

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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