From e2605b42c7ce37717118fe240f7d0e8c4eae3598 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 31 Jan 2015 15:08:25 -0800 Subject: [PATCH] Rename #[should_fail] to #[should_panic] --- src/compiletest/compiletest.rs | 2 +- src/libarena/lib.rs | 2 +- src/libcollections/enum_set.rs | 2 +- src/libcollections/slice.rs | 26 +++++----- src/libcollections/str.rs | 6 +-- src/libcollections/string.rs | 10 ++-- src/libcollections/vec.rs | 18 +++---- src/libcollections/vec_deque.rs | 2 +- src/libcollections/vec_map.rs | 2 +- src/libcoretest/cell.rs | 2 +- src/libcoretest/finally.rs | 2 +- src/libcoretest/fmt/num.rs | 2 +- src/libcoretest/iter.rs | 2 +- src/libcoretest/option.rs | 6 +-- src/libcoretest/result.rs | 2 +- src/librand/distributions/exponential.rs | 4 +- src/librand/distributions/gamma.rs | 2 +- src/librand/distributions/mod.rs | 6 +-- src/librand/distributions/normal.rs | 4 +- src/librand/distributions/range.rs | 4 +- src/librustc_back/sha2.rs | 2 +- src/librustdoc/test.rs | 12 ++--- src/libstd/collections/hash/map.rs | 2 +- src/libstd/old_io/buffered.rs | 2 +- src/libstd/old_io/extensions.rs | 2 +- src/libstd/old_io/timer.rs | 6 +-- src/libstd/old_path/windows.rs | 2 +- src/libstd/rand/mod.rs | 4 +- src/libstd/rand/reader.rs | 2 +- src/libstd/sync/condvar.rs | 2 +- src/libstd/sync/future.rs | 2 +- src/libstd/sync/task_pool.rs | 2 +- src/libstd/sys/common/wtf8.rs | 10 ++-- src/libsyntax/codemap.rs | 2 +- src/libsyntax/ext/expand.rs | 4 +- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/test.rs | 36 ++++++++----- src/libsyntax/util/interner.rs | 2 +- src/libsyntax/util/small_vector.rs | 4 +- src/libtest/lib.rs | 52 +++++++++---------- .../run-fail/test-should-fail-bad-message.rs | 2 +- .../run-pass/test-should-fail-good-message.rs | 4 +- 42 files changed, 136 insertions(+), 128 deletions(-) diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 073f16e354d..2837c923b3d 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -332,7 +332,7 @@ pub fn make_test(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(), } diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 01fb8e35872..d08c9b3257a 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -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. diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 4c966c0d44b..68ff94cfbfb 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -490,7 +490,7 @@ mod test { } #[test] - #[should_fail] + #[should_panic] fn test_overflow() { #[allow(dead_code)] #[derive(Copy)] diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index abcb996e3ed..cffa4bbfbf4 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -1647,14 +1647,14 @@ mod tests { } #[test] - #[should_fail] + #[should_panic] fn test_tail_empty() { let a = Vec::::new(); a.tail(); } #[test] - #[should_fail] + #[should_panic] fn test_tail_mut_empty() { let mut a = Vec::::new(); a.tail_mut(); @@ -1681,14 +1681,14 @@ mod tests { } #[test] - #[should_fail] + #[should_panic] fn test_init_empty() { let a = Vec::::new(); a.init(); } #[test] - #[should_fail] + #[should_panic] fn test_init_mut_empty() { let mut a = Vec::::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); diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 99547b9c60a..49317a7f0ce 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -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"; diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index d6ec8f0d979..a34193a4d2c 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -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() { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 2e947ea2460..ca0092a6e66 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -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::::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(|_| ()); diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index 551d28b91b4..cab589d55be 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -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 { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 515de74e340..431c8d5df8c 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -1432,7 +1432,7 @@ mod test_map { } #[test] - #[should_fail] + #[should_panic] fn test_index_nonexistent() { let mut map = VecMap::new(); diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs index 317ef3a5701..3397cbb18fa 100644 --- a/src/libcoretest/cell.rs +++ b/src/libcoretest/cell.rs @@ -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(); diff --git a/src/libcoretest/finally.rs b/src/libcoretest/finally.rs index 55fcb849851..2a48395271d 100644 --- a/src/libcoretest/finally.rs +++ b/src/libcoretest/finally.rs @@ -30,7 +30,7 @@ fn test_success() { } #[test] -#[should_fail] +#[should_panic] fn test_fail() { let mut i = 0; try_finally( diff --git a/src/libcoretest/fmt/num.rs b/src/libcoretest/fmt/num.rs index bc3995439a0..7db8db444ff 100644 --- a/src/libcoretest/fmt/num.rs +++ b/src/libcoretest/fmt/num.rs @@ -161,7 +161,7 @@ fn test_format_radix() { } #[test] -#[should_fail] +#[should_panic] fn test_radix_base_too_large() { let _ = radix(55, 37); } diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index 91d1ea27476..0f4e7fcdda5 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -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), diff --git a/src/libcoretest/option.rs b/src/libcoretest/option.rs index 59116f23d44..fe0b10e9119 100644 --- a/src/libcoretest/option.rs +++ b/src/libcoretest/option.rs @@ -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 = None; x.unwrap(); } #[test] -#[should_fail] +#[should_panic] fn test_unwrap_panic2() { let x: Option = None; x.unwrap(); diff --git a/src/libcoretest/result.rs b/src/libcoretest/result.rs index 10cc3ad6424..1c175ba99f7 100644 --- a/src/libcoretest/result.rs +++ b/src/libcoretest/result.rs @@ -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." { diff --git a/src/librand/distributions/exponential.rs b/src/librand/distributions/exponential.rs index e4927902cb3..bf9d334e8a4 100644 --- a/src/librand/distributions/exponential.rs +++ b/src/librand/distributions/exponential.rs @@ -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); } diff --git a/src/librand/distributions/gamma.rs b/src/librand/distributions/gamma.rs index 38eba0cfc71..ae3724a2b43 100644 --- a/src/librand/distributions/gamma.rs +++ b/src/librand/distributions/gamma.rs @@ -356,7 +356,7 @@ mod test { } } #[test] - #[should_fail] + #[should_panic] fn test_chi_squared_invalid_dof() { ChiSquared::new(-1.0); } diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index 12794ed69be..9775507b3cd 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -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::::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 }, diff --git a/src/librand/distributions/normal.rs b/src/librand/distributions/normal.rs index 83f202742d3..ab5d03ad825 100644 --- a/src/librand/distributions/normal.rs +++ b/src/librand/distributions/normal.rs @@ -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); } diff --git a/src/librand/distributions/range.rs b/src/librand/distributions/range.rs index 4afc67d63c8..c5a260346e0 100644 --- a/src/librand/distributions/range.rs +++ b/src/librand/distributions/range.rs @@ -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); diff --git a/src/librustc_back/sha2.rs b/src/librustc_back/sha2.rs index 482c710149c..1a399519296 100644 --- a/src/librustc_back/sha2.rs +++ b/src/librustc_back/sha2.rs @@ -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::(Int::max_value(), 1); } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index c785d78dc93..e7312d6548e 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -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); })) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 8eb29a8327a..9502302aa53 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -2197,7 +2197,7 @@ mod test_map { } #[test] - #[should_fail] + #[should_panic] fn test_index_nonexistent() { let mut map = HashMap::new(); diff --git a/src/libstd/old_io/buffered.rs b/src/libstd/old_io/buffered.rs index fe2510b668f..cbb7bf04327 100644 --- a/src/libstd/old_io/buffered.rs +++ b/src/libstd/old_io/buffered.rs @@ -658,7 +658,7 @@ mod test { } #[test] - #[should_fail] + #[should_panic] fn dont_panic_in_drop_on_panicked_flush() { struct FailFlushWriter; diff --git a/src/libstd/old_io/extensions.rs b/src/libstd/old_io/extensions.rs index a2bc28962c3..ec30121d78d 100644 --- a/src/libstd/old_io/extensions.rs +++ b/src/libstd/old_io/extensions.rs @@ -396,7 +396,7 @@ mod test { } #[test] - #[should_fail] + #[should_panic] fn read_to_end_error() { let mut reader = ThreeChunkReader { count: 0, diff --git a/src/libstd/old_io/timer.rs b/src/libstd/old_io/timer.rs index de5f2141095..375fe6ce483 100644 --- a/src/libstd/old_io/timer.rs +++ b/src/libstd/old_io/timer.rs @@ -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!(); diff --git a/src/libstd/old_path/windows.rs b/src/libstd/old_path/windows.rs index 31a8cbe572a..5f2f1728be1 100644 --- a/src/libstd/old_path/windows.rs +++ b/src/libstd/old_path/windows.rs @@ -1324,7 +1324,7 @@ mod tests { } #[test] - #[should_fail] + #[should_panic] fn test_not_utf8_panics() { Path::new(b"hello\x80.txt"); } diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 4ed1520ed03..7382cc6e2eb 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -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); diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index ba1ebc2ab22..c56dc387b7f 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -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]; diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index e7ee9bd2066..3499675f542 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -479,7 +479,7 @@ mod tests { } #[test] - #[should_fail] + #[should_panic] fn two_mutexes() { static M1: StaticMutex = MUTEX_INIT; static M2: StaticMutex = MUTEX_INIT; diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index d60e2738808..ee9bcd3dd89 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -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(); diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index efb6689e785..e41bc6d8683 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -164,7 +164,7 @@ mod test { } #[test] - #[should_fail] + #[should_panic] fn test_zero_tasks_panic() { TaskPool::new(0); } diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 719c74179ac..7a02df23b19 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -1030,14 +1030,14 @@ mod tests { } #[test] - #[should_fail] + #[should_panic] fn wtf8buf_truncate_fail_code_point_boundary() { let mut string = Wtf8Buf::from_str("aé"); string.truncate(2); } #[test] - #[should_fail] + #[should_panic] fn wtf8buf_truncate_fail_longer() { let mut string = Wtf8Buf::from_str("aé"); 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..]; } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 44df8a6d3da..7d2d4e53fe9 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -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(), diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index db8819ef82c..98c7aefcd8a 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -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(); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 58d58551df3..fae305f9551 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -813,7 +813,7 @@ mod test { })) } - #[should_fail] + #[should_panic] #[test] fn bad_path_expr_1() { string_to_expr("::abc::def::return".to_string()); } diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index d889453a5f9..5e858d8a79f 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -37,7 +37,7 @@ use {ast, ast_util}; use ptr::P; use util::small_vector::SmallVector; -enum ShouldFail { +enum ShouldPanic { No, Yes(Option), } @@ -47,7 +47,7 @@ struct Test { path: Vec , 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 { 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 { 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 { diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 5be45a2698f..7ae9e4646e5 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -234,7 +234,7 @@ mod tests { use ast::Name; #[test] - #[should_fail] + #[should_panic] fn i1 () { let i : Interner = Interner::new(); i.get(Name(13)); diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index 90df23882a1..5bd6591cfb0 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -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(""); } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index e4e1845de63..1590291c88c 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -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>) -> 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::() .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)), }; diff --git a/src/test/run-fail/test-should-fail-bad-message.rs b/src/test/run-fail/test-should-fail-bad-message.rs index 5a5bb53a33a..e18c5d9631a 100644 --- a/src/test/run-fail/test-should-fail-bad-message.rs +++ b/src/test/run-fail/test-should-fail-bad-message.rs @@ -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") } diff --git a/src/test/run-pass/test-should-fail-good-message.rs b/src/test/run-pass/test-should-fail-good-message.rs index dcb2fe6dfc0..b8e05b4d35a 100644 --- a/src/test/run-pass/test-should-fail-good-message.rs +++ b/src/test/run-pass/test-should-fail-good-message.rs @@ -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") }