12d8ae3abSopenharmony_ci#[cfg(not(lib_build))] 22d8ae3abSopenharmony_ci#[macro_use] 32d8ae3abSopenharmony_ciextern crate log; 42d8ae3abSopenharmony_ci 52d8ae3abSopenharmony_cimacro_rules! all_log_macros { 62d8ae3abSopenharmony_ci ($($arg:tt)*) => ({ 72d8ae3abSopenharmony_ci trace!($($arg)*); 82d8ae3abSopenharmony_ci debug!($($arg)*); 92d8ae3abSopenharmony_ci info!($($arg)*); 102d8ae3abSopenharmony_ci warn!($($arg)*); 112d8ae3abSopenharmony_ci error!($($arg)*); 122d8ae3abSopenharmony_ci }); 132d8ae3abSopenharmony_ci} 142d8ae3abSopenharmony_ci 152d8ae3abSopenharmony_ci#[test] 162d8ae3abSopenharmony_cifn no_args() { 172d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 182d8ae3abSopenharmony_ci log!(lvl, "hello"); 192d8ae3abSopenharmony_ci log!(lvl, "hello",); 202d8ae3abSopenharmony_ci 212d8ae3abSopenharmony_ci log!(target: "my_target", lvl, "hello"); 222d8ae3abSopenharmony_ci log!(target: "my_target", lvl, "hello",); 232d8ae3abSopenharmony_ci 242d8ae3abSopenharmony_ci log!(lvl, "hello"); 252d8ae3abSopenharmony_ci log!(lvl, "hello",); 262d8ae3abSopenharmony_ci } 272d8ae3abSopenharmony_ci 282d8ae3abSopenharmony_ci all_log_macros!("hello"); 292d8ae3abSopenharmony_ci all_log_macros!("hello",); 302d8ae3abSopenharmony_ci 312d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", "hello"); 322d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", "hello",); 332d8ae3abSopenharmony_ci} 342d8ae3abSopenharmony_ci 352d8ae3abSopenharmony_ci#[test] 362d8ae3abSopenharmony_cifn anonymous_args() { 372d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 382d8ae3abSopenharmony_ci log!(lvl, "hello {}", "world"); 392d8ae3abSopenharmony_ci log!(lvl, "hello {}", "world",); 402d8ae3abSopenharmony_ci 412d8ae3abSopenharmony_ci log!(target: "my_target", lvl, "hello {}", "world"); 422d8ae3abSopenharmony_ci log!(target: "my_target", lvl, "hello {}", "world",); 432d8ae3abSopenharmony_ci 442d8ae3abSopenharmony_ci log!(lvl, "hello {}", "world"); 452d8ae3abSopenharmony_ci log!(lvl, "hello {}", "world",); 462d8ae3abSopenharmony_ci } 472d8ae3abSopenharmony_ci 482d8ae3abSopenharmony_ci all_log_macros!("hello {}", "world"); 492d8ae3abSopenharmony_ci all_log_macros!("hello {}", "world",); 502d8ae3abSopenharmony_ci 512d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", "hello {}", "world"); 522d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", "hello {}", "world",); 532d8ae3abSopenharmony_ci} 542d8ae3abSopenharmony_ci 552d8ae3abSopenharmony_ci#[test] 562d8ae3abSopenharmony_cifn named_args() { 572d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 582d8ae3abSopenharmony_ci log!(lvl, "hello {world}", world = "world"); 592d8ae3abSopenharmony_ci log!(lvl, "hello {world}", world = "world",); 602d8ae3abSopenharmony_ci 612d8ae3abSopenharmony_ci log!(target: "my_target", lvl, "hello {world}", world = "world"); 622d8ae3abSopenharmony_ci log!(target: "my_target", lvl, "hello {world}", world = "world",); 632d8ae3abSopenharmony_ci 642d8ae3abSopenharmony_ci log!(lvl, "hello {world}", world = "world"); 652d8ae3abSopenharmony_ci log!(lvl, "hello {world}", world = "world",); 662d8ae3abSopenharmony_ci } 672d8ae3abSopenharmony_ci 682d8ae3abSopenharmony_ci all_log_macros!("hello {world}", world = "world"); 692d8ae3abSopenharmony_ci all_log_macros!("hello {world}", world = "world",); 702d8ae3abSopenharmony_ci 712d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", "hello {world}", world = "world"); 722d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", "hello {world}", world = "world",); 732d8ae3abSopenharmony_ci} 742d8ae3abSopenharmony_ci 752d8ae3abSopenharmony_ci#[test] 762d8ae3abSopenharmony_cifn enabled() { 772d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 782d8ae3abSopenharmony_ci let _enabled = if log_enabled!(target: "my_target", lvl) { 792d8ae3abSopenharmony_ci true 802d8ae3abSopenharmony_ci } else { 812d8ae3abSopenharmony_ci false 822d8ae3abSopenharmony_ci }; 832d8ae3abSopenharmony_ci } 842d8ae3abSopenharmony_ci} 852d8ae3abSopenharmony_ci 862d8ae3abSopenharmony_ci#[test] 872d8ae3abSopenharmony_cifn expr() { 882d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 892d8ae3abSopenharmony_ci let _ = log!(lvl, "hello"); 902d8ae3abSopenharmony_ci } 912d8ae3abSopenharmony_ci} 922d8ae3abSopenharmony_ci 932d8ae3abSopenharmony_ci#[test] 942d8ae3abSopenharmony_ci#[cfg(feature = "kv_unstable")] 952d8ae3abSopenharmony_cifn kv_no_args() { 962d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 972d8ae3abSopenharmony_ci log!(target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello"); 982d8ae3abSopenharmony_ci 992d8ae3abSopenharmony_ci log!(lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello"); 1002d8ae3abSopenharmony_ci } 1012d8ae3abSopenharmony_ci 1022d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello"); 1032d8ae3abSopenharmony_ci all_log_macros!(target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello"); 1042d8ae3abSopenharmony_ci all_log_macros!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello"); 1052d8ae3abSopenharmony_ci} 1062d8ae3abSopenharmony_ci 1072d8ae3abSopenharmony_ci#[test] 1082d8ae3abSopenharmony_ci#[cfg(feature = "kv_unstable")] 1092d8ae3abSopenharmony_cifn kv_expr_args() { 1102d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 1112d8ae3abSopenharmony_ci log!(target: "my_target", lvl, cat_math = { let mut x = 0; x += 1; x + 1 }; "hello"); 1122d8ae3abSopenharmony_ci 1132d8ae3abSopenharmony_ci log!(lvl, target = "my_target", cat_math = { let mut x = 0; x += 1; x + 1 }; "hello"); 1142d8ae3abSopenharmony_ci log!(lvl, cat_math = { let mut x = 0; x += 1; x + 1 }; "hello"); 1152d8ae3abSopenharmony_ci } 1162d8ae3abSopenharmony_ci 1172d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", cat_math = { let mut x = 0; x += 1; x + 1 }; "hello"); 1182d8ae3abSopenharmony_ci all_log_macros!(target = "my_target", cat_math = { let mut x = 0; x += 1; x + 1 }; "hello"); 1192d8ae3abSopenharmony_ci all_log_macros!(cat_math = { let mut x = 0; x += 1; x + 1 }; "hello"); 1202d8ae3abSopenharmony_ci} 1212d8ae3abSopenharmony_ci 1222d8ae3abSopenharmony_ci#[test] 1232d8ae3abSopenharmony_ci#[cfg(feature = "kv_unstable")] 1242d8ae3abSopenharmony_cifn kv_anonymous_args() { 1252d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 1262d8ae3abSopenharmony_ci log!(target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world"); 1272d8ae3abSopenharmony_ci log!(lvl, target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world"); 1282d8ae3abSopenharmony_ci 1292d8ae3abSopenharmony_ci log!(lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world"); 1302d8ae3abSopenharmony_ci } 1312d8ae3abSopenharmony_ci 1322d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world"); 1332d8ae3abSopenharmony_ci all_log_macros!(target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world"); 1342d8ae3abSopenharmony_ci all_log_macros!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {}", "world"); 1352d8ae3abSopenharmony_ci} 1362d8ae3abSopenharmony_ci 1372d8ae3abSopenharmony_ci#[test] 1382d8ae3abSopenharmony_ci#[cfg(feature = "kv_unstable")] 1392d8ae3abSopenharmony_cifn kv_named_args() { 1402d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 1412d8ae3abSopenharmony_ci log!(target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world"); 1422d8ae3abSopenharmony_ci log!(lvl, target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world"); 1432d8ae3abSopenharmony_ci 1442d8ae3abSopenharmony_ci log!(lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world"); 1452d8ae3abSopenharmony_ci } 1462d8ae3abSopenharmony_ci 1472d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world"); 1482d8ae3abSopenharmony_ci all_log_macros!(target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world"); 1492d8ae3abSopenharmony_ci all_log_macros!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}", world = "world"); 1502d8ae3abSopenharmony_ci} 1512d8ae3abSopenharmony_ci 1522d8ae3abSopenharmony_ci#[test] 1532d8ae3abSopenharmony_ci#[cfg(feature = "kv_unstable")] 1542d8ae3abSopenharmony_cifn kv_expr_context() { 1552d8ae3abSopenharmony_ci match "chashu" { 1562d8ae3abSopenharmony_ci cat_1 => { 1572d8ae3abSopenharmony_ci info!(target: "target", cat_1 = cat_1, cat_2 = "nori"; "hello {}", "cats") 1582d8ae3abSopenharmony_ci } 1592d8ae3abSopenharmony_ci }; 1602d8ae3abSopenharmony_ci} 1612d8ae3abSopenharmony_ci 1622d8ae3abSopenharmony_ci#[test] 1632d8ae3abSopenharmony_cifn implicit_named_args() { 1642d8ae3abSopenharmony_ci #[rustversion::since(1.58)] 1652d8ae3abSopenharmony_ci fn _check() { 1662d8ae3abSopenharmony_ci let world = "world"; 1672d8ae3abSopenharmony_ci 1682d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 1692d8ae3abSopenharmony_ci log!(lvl, "hello {world}"); 1702d8ae3abSopenharmony_ci log!(lvl, "hello {world}",); 1712d8ae3abSopenharmony_ci 1722d8ae3abSopenharmony_ci log!(target: "my_target", lvl, "hello {world}"); 1732d8ae3abSopenharmony_ci log!(target: "my_target", lvl, "hello {world}",); 1742d8ae3abSopenharmony_ci 1752d8ae3abSopenharmony_ci log!(lvl, "hello {world}"); 1762d8ae3abSopenharmony_ci log!(lvl, "hello {world}",); 1772d8ae3abSopenharmony_ci } 1782d8ae3abSopenharmony_ci 1792d8ae3abSopenharmony_ci all_log_macros!("hello {world}"); 1802d8ae3abSopenharmony_ci all_log_macros!("hello {world}",); 1812d8ae3abSopenharmony_ci 1822d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", "hello {world}"); 1832d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", "hello {world}",); 1842d8ae3abSopenharmony_ci 1852d8ae3abSopenharmony_ci all_log_macros!(target = "my_target"; "hello {world}"); 1862d8ae3abSopenharmony_ci all_log_macros!(target = "my_target"; "hello {world}",); 1872d8ae3abSopenharmony_ci } 1882d8ae3abSopenharmony_ci} 1892d8ae3abSopenharmony_ci 1902d8ae3abSopenharmony_ci#[test] 1912d8ae3abSopenharmony_ci#[cfg(feature = "kv_unstable")] 1922d8ae3abSopenharmony_cifn kv_implicit_named_args() { 1932d8ae3abSopenharmony_ci #[rustversion::since(1.58)] 1942d8ae3abSopenharmony_ci fn _check() { 1952d8ae3abSopenharmony_ci let world = "world"; 1962d8ae3abSopenharmony_ci 1972d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 1982d8ae3abSopenharmony_ci log!(target: "my_target", lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}"); 1992d8ae3abSopenharmony_ci 2002d8ae3abSopenharmony_ci log!(lvl, cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}"); 2012d8ae3abSopenharmony_ci } 2022d8ae3abSopenharmony_ci 2032d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}"); 2042d8ae3abSopenharmony_ci all_log_macros!(target = "my_target", cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}"); 2052d8ae3abSopenharmony_ci all_log_macros!(cat_1 = "chashu", cat_2 = "nori", cat_count = 2; "hello {world}"); 2062d8ae3abSopenharmony_ci } 2072d8ae3abSopenharmony_ci} 2082d8ae3abSopenharmony_ci 2092d8ae3abSopenharmony_ci#[test] 2102d8ae3abSopenharmony_ci#[cfg(feature = "kv_unstable")] 2112d8ae3abSopenharmony_cifn kv_string_keys() { 2122d8ae3abSopenharmony_ci for lvl in log::Level::iter() { 2132d8ae3abSopenharmony_ci log!(target: "my_target", lvl, "also dogs" = "Fílos", "key/that-can't/be/an/ident" = "hi"; "hello {world}", world = "world"); 2142d8ae3abSopenharmony_ci } 2152d8ae3abSopenharmony_ci 2162d8ae3abSopenharmony_ci all_log_macros!(target: "my_target", "also dogs" = "Fílos", "key/that-can't/be/an/ident" = "hi"; "hello {world}", world = "world"); 2172d8ae3abSopenharmony_ci} 2182d8ae3abSopenharmony_ci 2192d8ae3abSopenharmony_ci#[test] 2202d8ae3abSopenharmony_ci#[cfg(feature = "kv_unstable")] 2212d8ae3abSopenharmony_cifn kv_common_value_types() { 2222d8ae3abSopenharmony_ci all_log_macros!( 2232d8ae3abSopenharmony_ci u8 = 42u8, 2242d8ae3abSopenharmony_ci u16 = 42u16, 2252d8ae3abSopenharmony_ci u32 = 42u32, 2262d8ae3abSopenharmony_ci u64 = 42u64, 2272d8ae3abSopenharmony_ci u128 = 42u128, 2282d8ae3abSopenharmony_ci i8 = -42i8, 2292d8ae3abSopenharmony_ci i16 = -42i16, 2302d8ae3abSopenharmony_ci i32 = -42i32, 2312d8ae3abSopenharmony_ci i64 = -42i64, 2322d8ae3abSopenharmony_ci i128 = -42i128, 2332d8ae3abSopenharmony_ci f32 = 4.2f32, 2342d8ae3abSopenharmony_ci f64 = -4.2f64, 2352d8ae3abSopenharmony_ci bool = true, 2362d8ae3abSopenharmony_ci str = "string"; 2372d8ae3abSopenharmony_ci "hello world" 2382d8ae3abSopenharmony_ci ); 2392d8ae3abSopenharmony_ci} 2402d8ae3abSopenharmony_ci 2412d8ae3abSopenharmony_ci/// Some and None (from Option) are used in the macros. 2422d8ae3abSopenharmony_ci#[derive(Debug)] 2432d8ae3abSopenharmony_cienum Type { 2442d8ae3abSopenharmony_ci Some, 2452d8ae3abSopenharmony_ci None, 2462d8ae3abSopenharmony_ci} 2472d8ae3abSopenharmony_ci 2482d8ae3abSopenharmony_ci#[test] 2492d8ae3abSopenharmony_cifn regression_issue_494() { 2502d8ae3abSopenharmony_ci use self::Type::*; 2512d8ae3abSopenharmony_ci all_log_macros!("some message: {:?}, {:?}", None, Some); 2522d8ae3abSopenharmony_ci} 253