Skip to content

Commit

Permalink
Use the test-log crate to enable logging from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Oct 27, 2024
1 parent a9d1876 commit cf454b7
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 25 deletions.
144 changes: 141 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
1 change: 1 addition & 0 deletions ubi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ logging = ["dep:fern"]
fern.workspace = true
mockito.workspace = true
test-case.workspace = true
test-log.workspace = true
tokio.workspace = true
32 changes: 10 additions & 22 deletions ubi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl<'a> Ubi<'a> {
}
}

#[cfg(any(test, feature = "logging"))]
#[cfg(feature = "logging")]
use fern::{
colors::{Color, ColoredLevelConfig},
Dispatch,
Expand All @@ -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)
Expand Down Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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)>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ubi/src/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ mod test {
use super::*;
use platforms::PlatformReq;
use std::str::FromStr;
use test_log::test;
use url::Url;

#[test]
Expand Down

0 comments on commit cf454b7

Please sign in to comment.