1 //! 需要测试的时候可以在这里写测试代码, 2 //! 然后在当前目录执行 `cargo expand --bin unified-init-expand` 3 //! 就可以看到把proc macro展开后的代码了 4 #![no_std] 5 #![allow(internal_features)] 6 #![feature(lang_items)] 7 main()8fn main() { 9 todo!() 10 } 11 12 #[cfg(target_os = "none")] 13 #[panic_handler] 14 #[no_mangle] panic(_info: &core::panic::PanicInfo) -> !15pub fn panic(_info: &core::panic::PanicInfo) -> ! { 16 loop {} 17 } 18 19 #[cfg(target_os = "none")] 20 #[lang = "eh_personality"] eh_personality()21unsafe extern "C" fn eh_personality() {} 22 23 #[cfg(test)] 24 mod tests { 25 use system_error::SystemError; 26 use unified_init::define_unified_initializer_slice; 27 use unified_init_macros::unified_init; 28 29 use super::*; 30 31 #[test] no_element()32 fn no_element() { 33 define_unified_initializer_slice!(TEST_0); 34 35 assert_eq!(TEST_0.len(), 0); 36 } 37 38 #[test] no_element_ne()39 fn no_element_ne() { 40 define_unified_initializer_slice!(TEST_0_NE); 41 42 #[unified_init(TEST_0_NE)] 43 fn x() -> Result<(), SystemError> { 44 todo!() 45 } 46 47 assert_ne!(TEST_0_NE.len(), 0); 48 } 49 50 #[test] one_element()51 fn one_element() { 52 define_unified_initializer_slice!(TEST_1); 53 54 #[unified_init(TEST_1)] 55 fn x() -> Result<(), SystemError> { 56 todo!() 57 } 58 assert_eq!(TEST_1.len(), 1); 59 } 60 61 #[test] two_elements()62 fn two_elements() { 63 define_unified_initializer_slice!(TEST_2); 64 65 #[unified_init(TEST_2)] 66 fn x() -> Result<(), SystemError> { 67 todo!() 68 } 69 70 #[unified_init(TEST_2)] 71 fn y() -> Result<(), SystemError> { 72 todo!() 73 } 74 assert_eq!(TEST_2.len(), 2); 75 } 76 } 77