From aa85c734eac9f4897a1cdf8af9c3ac92e0722d30 Mon Sep 17 00:00:00 2001 From: adamanteye Date: Mon, 14 Oct 2024 23:36:07 +0800 Subject: [PATCH] test: use coverage helper to ignore test codes see https://github.com/taiki-e/coverage-helper see https://github.com/taiki-e/cargo-llvm-cov/issues/123 --- Cargo.lock | 4 ++-- Cargo.toml | 5 ++++- src/config.rs | 1 + src/error.rs | 1 + src/main.rs | 1 + src/utility.rs | 1 + src/view/user_profile.rs | 4 +++- src/view/user_register.rs | 2 ++ 8 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e8e4cfc..a8ba8b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -504,9 +504,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "coverage-helper" -version = "0.1.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fd441a9eb45a44e9dfa9ed405d4ab521f1b447ed62ef5d67ddc5a334a21b5ca" +checksum = "8174551717bb3d1e75935e38d33f5f8ee8f680dd8dd42c90851e6c644faad14e" [[package]] name = "cpufeatures" diff --git a/Cargo.toml b/Cargo.toml index ef38f2a..77e8a94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ rand = "0.8.5" regex = "1.11.0" uuid = "1.10.0" # With llvm-cov -coverage-helper = "0.1" +coverage-helper = "0.2" [package] name = "veloquent-core" @@ -52,6 +52,9 @@ license.workspace = true publish.workspace = true authors.workspace = true +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] } + [dependencies] axum = { workspace = true } sea-orm = { workspace = true, features = [ diff --git a/src/config.rs b/src/config.rs index 3c371fb..fa36c56 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,6 +51,7 @@ pub struct Config { #[cfg(test)] mod test { use super::*; + use coverage_helper::test; #[test] fn test_config_file() { diff --git a/src/error.rs b/src/error.rs index 8308e0d..1f71ac5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -64,6 +64,7 @@ impl IntoResponse for AppError { #[cfg(test)] mod test { use super::*; + use coverage_helper::test; #[test] fn test_std_error_to_response() { diff --git a/src/main.rs b/src/main.rs index f261a90..45581a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ #![warn(missing_docs)] +#![cfg_attr(all(coverage_nightly, test), feature(coverage_attribute))] //! Veloquent 后端服务 //! diff --git a/src/utility.rs b/src/utility.rs index 5fec4ed..d6ae592 100644 --- a/src/utility.rs +++ b/src/utility.rs @@ -93,6 +93,7 @@ where #[cfg(test)] mod test { use super::*; + use coverage_helper::test; #[test] fn test_hash_and_salt() { diff --git a/src/view/user_profile.rs b/src/view/user_profile.rs index 330ec2e..eb2d9b1 100644 --- a/src/view/user_profile.rs +++ b/src/view/user_profile.rs @@ -52,6 +52,8 @@ impl From for UserProfile { #[cfg(test)] mod test { use super::*; + use coverage_helper::test; + #[test] fn test_profile_from_entity() { let created_at = chrono::Utc::now().naive_utc(); @@ -78,8 +80,8 @@ mod test { phone: String::default(), created_at, gender: 0, + avatar: uuid::Uuid::default().to_string(), alias: String::default(), - avatar: String::default(), bio: String::default(), link: String::default(), } diff --git a/src/view/user_register.rs b/src/view/user_register.rs index 235ad64..63e0e0f 100644 --- a/src/view/user_register.rs +++ b/src/view/user_register.rs @@ -98,6 +98,8 @@ pub async fn register_handler( #[cfg(test)] mod test { use super::*; + use coverage_helper::test; + #[test] fn test_empty_user_or_password() { let p = r#"{"name":"","password":""}"#;