diff --git a/Cargo.lock b/Cargo.lock index 4f00fec..2d16993 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -429,6 +429,27 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -947,6 +968,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.7.4" @@ -1021,6 +1051,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "object" version = "0.36.5" @@ -1090,6 +1130,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking_lot" version = "0.12.3" @@ -1275,8 +1321,17 @@ checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", - "regex-automata", - "regex-syntax", + "regex-automata 0.4.8", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] [[package]] @@ -1287,9 +1342,15 @@ checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.8.5", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.8.5" @@ -1542,6 +1603,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "shlex" version = "1.3.0" @@ -1701,6 +1771,28 @@ dependencies = [ "test-case-core", ] +[[package]] +name = "test-log" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dffced63c2b5c7be278154d76b479f9f9920ed34e7574201407f0b14e2bbb93" +dependencies = [ + "env_logger", + "test-log-macros", + "tracing-subscriber", +] + +[[package]] +name = "test-log-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thiserror" version = "1.0.64" @@ -1721,6 +1813,16 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -1821,6 +1923,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", ] [[package]] @@ -1856,6 +1987,7 @@ dependencies = [ "strum", "tempfile", "test-case", + "test-log", "thiserror", "tokio", "url", @@ -1922,6 +2054,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 2dbb92e..ff04702 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ serde = { version = "1.0.210", features = ["derive"] } strum = { version = "0.26.3", features = ["derive"] } tempfile = "3.13.0" test-case = "3.3.1" +test-log = "0.2.16" thiserror = "1.0.64" tokio = { version = "1.40.0", default-features = false, features = ["macros", "rt"] } url = { version = "2.5.2", features = ["serde"] } diff --git a/ubi/Cargo.toml b/ubi/Cargo.toml index 525b01d..3853478 100644 --- a/ubi/Cargo.toml +++ b/ubi/Cargo.toml @@ -46,4 +46,5 @@ logging = ["dep:fern"] fern.workspace = true mockito.workspace = true test-case.workspace = true +test-log.workspace = true tokio.workspace = true diff --git a/ubi/src/lib.rs b/ubi/src/lib.rs index ba8af36..9aeb757 100644 --- a/ubi/src/lib.rs +++ b/ubi/src/lib.rs @@ -429,7 +429,7 @@ impl<'a> Ubi<'a> { } } -#[cfg(any(test, feature = "logging"))] +#[cfg(feature = "logging")] use fern::{ colors::{Color, ColoredLevelConfig}, Dispatch, @@ -441,7 +441,7 @@ use fern::{ /// # Errors /// /// This can return a `log::SetLoggerError` error. -#[cfg(any(test, feature = "logging"))] +#[cfg(feature = "logging")] pub fn init_logger(level: log::LevelFilter) -> Result<(), log::SetLoggerError> { let line_colors = ColoredLevelConfig::new() .error(Color::Red) @@ -479,6 +479,7 @@ mod test { use platforms::PlatformReq; use reqwest::header::ACCEPT; use std::str::FromStr; + use test_log::test; #[test] fn parse_project_name() -> Result<()> { @@ -560,11 +561,9 @@ mod test { Ok(()) } - #[tokio::test] + #[test(tokio::test)] #[allow(clippy::too_many_lines)] async fn asset_picking() -> Result<()> { - //init_logger(log::LevelFilter::Debug)?; - struct Test { platforms: &'static [&'static str], expect_ubi: Option<(u32, &'static str)>, @@ -1030,12 +1029,10 @@ mod test { } "#; - #[tokio::test] + #[test(tokio::test)] // The protobuf repo has some odd release naming. This tests that the // matcher handles it. async fn matching_unusual_names() -> Result<()> { - //init_logger(log::LevelFilter::Debug)?; - struct Test { platforms: &'static [&'static str], expect: &'static str, @@ -1185,10 +1182,8 @@ mod test { "#; // Reported in https://github.com/houseabsolute/ubi/issues/34 - #[tokio::test] + #[test(tokio::test)] async fn mkcert_matching() -> Result<()> { - //init_logger(log::LevelFilter::Debug)?; - struct Test { platforms: &'static [&'static str], expect: &'static str, @@ -1296,10 +1291,8 @@ mod test { }"#; // Reported in https://github.com/houseabsolute/ubi/issues/34 - #[tokio::test] + #[test(tokio::test)] async fn jq_matching() -> Result<()> { - //init_logger(log::LevelFilter::Debug)?; - struct Test { platforms: &'static [&'static str], expect: &'static str, @@ -1398,10 +1391,8 @@ mod test { ] }"#; - #[tokio::test] + #[test(tokio::test)] async fn multiple_matches() -> Result<()> { - //init_logger(log::LevelFilter::Debug)?; - let platforms = ["x86_64-pc-windows-gnu", "i686-pc-windows-gnu"]; let mut server = Server::new_async().await; @@ -1454,9 +1445,8 @@ mod test { ] }"#; - #[tokio::test] + #[test(tokio::test)] async fn macos_arm() -> Result<()> { - //init_logger(log::LevelFilter::Debug)?; let mut server = Server::new_async().await; let m1 = server .mock("GET", "/repos/test/macos/releases/latest") @@ -1550,10 +1540,8 @@ mod test { ] }"#; - #[tokio::test] + #[test(tokio::test)] async fn os_without_arch() -> Result<()> { - //init_logger(log::LevelFilter::Debug)?; - { let mut server = Server::new_async().await; let m1 = server diff --git a/ubi/src/picker.rs b/ubi/src/picker.rs index c43b8cd..20f6840 100644 --- a/ubi/src/picker.rs +++ b/ubi/src/picker.rs @@ -411,6 +411,7 @@ mod test { use super::*; use platforms::PlatformReq; use std::str::FromStr; + use test_log::test; use url::Url; #[test]