1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#[cfg(test)] mod tests { use super::*; #[test] #[ignore] fn it_work() {} #[test] fn test_panic() { panic!("test panic here..."); } #[test] fn test_assert__ok() { assert!(1 == 1); } #[test] fn test_assert__failed() { assert!(1 == 2, "1不等于2"); } #[test] fn test_assert_eq__ok() { assert_eq!(1, 1); } #[test] fn test_assert_eq__failed() { assert_eq!(1, 2); } #[test] fn test_assert_ne__ok() { assert_ne!(1, 2); } #[test] fn test_assert_ne__failed() { assert_ne!(1, 1); } #[test] #[should_panic(expected = "panic something!")] fn test_assert_should_panic__ok() { println!("★★★test_assert_should_panic__ok: it will panic something!\n"); panic!("panic something!"); } #[test] #[should_panic(expected = "panic something!")] fn test_assert_should_panic__failed() { println!("★★★test_assert_should_panic__failed: it will panic otherthing!\n"); panic!("panic otherthing!"); } #[test] #[should_panic(expected = "panic something!")] fn test_assert_should_panic__failed_no_panic() { println!("★★★test_assert_should_panic__failed_no_panic: it won't panic anything!\n"); } } pub fn run(){ println!("\n--------------- call the function of \"run()\" write in lib.rs.\n"); }