From 1b5ed766cb45dcfe83a583d0ae1347523fd4d192 Mon Sep 17 00:00:00 2001 From: s1rius Date: Wed, 27 Mar 2024 01:50:38 +0800 Subject: [PATCH] support dinghy --- Cargo.toml | 2 +- bump.sh | 4 ++++ examples/hello_world/Cargo.toml | 3 ++- examples/hello_world/src/main.rs | 3 +-- ezlog-core/Cargo.toml | 3 ++- ezlog-core/src/appender.rs | 9 +++------ ezlog-core/src/config.rs | 2 +- ezlog-core/src/decode.rs | 3 +-- ezlog-core/src/lib.rs | 2 +- ezlog-core/tests/integration_test.rs | 3 +-- test-compat/Cargo.toml | 9 +++++++++ test-compat/src/lib.rs | 9 +++++++++ 12 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 test-compat/Cargo.toml create mode 100644 test-compat/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index d5c7064..9f037e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] -members = ["ezlogcli", "ezlog-core", "examples/android_preview", "examples/nest_log", "examples/hello_world"] +members = ["ezlogcli", "ezlog-core", "examples/android_preview", "examples/nest_log", "examples/hello_world", "test-compat"] resolver = "2" # https://github.com/johnthagen/min-sized-rust diff --git a/bump.sh b/bump.sh index 6bc45f2..7b0f87f 100755 --- a/bump.sh +++ b/bump.sh @@ -11,6 +11,10 @@ find . -path "$EXCLUDE_DIR" -prune -o -type f \( -name "*.toml" -o -name "*.kt" # clippy check cargo clippy --all --all-features -- -D warnings +# dinghy test +cargo dinghy -vvv -d android test -p ezlog +cargo dinghy -vvv -d ios test -p ezlog + # build iOS pushd ios sh b_ios.sh diff --git a/examples/hello_world/Cargo.toml b/examples/hello_world/Cargo.toml index 220b321..f4cc371 100644 --- a/examples/hello_world/Cargo.toml +++ b/examples/hello_world/Cargo.toml @@ -11,4 +11,5 @@ log = "0.4" env_logger = "0" dirs = "5.0" time = { version = "0.3", default-features = false, features = ["macros"] } -rand = "0.8" \ No newline at end of file +rand = "0.8" +test-compat = { path = "../../test-compat" } \ No newline at end of file diff --git a/examples/hello_world/src/main.rs b/examples/hello_world/src/main.rs index 698d699..3f961cf 100644 --- a/examples/hello_world/src/main.rs +++ b/examples/hello_world/src/main.rs @@ -97,8 +97,7 @@ fn get_config() -> EZLogConfig { EZLogConfigBuilder::new() .level(Level::Trace) .dir_path( - dirs::cache_dir() - .unwrap() + test_compat::test_path() .into_os_string() .into_string() .expect("dir path error"), diff --git a/ezlog-core/Cargo.toml b/ezlog-core/Cargo.toml index 8450656..65cb8ac 100644 --- a/ezlog-core/Cargo.toml +++ b/ezlog-core/Cargo.toml @@ -50,4 +50,5 @@ windows-sys = { version = "0.45", features = ["Win32_System_Threading", "Win32_F [dev-dependencies] dirs = "5.0" -time = { version = "0.3", default-features = false, features = ["macros"] } \ No newline at end of file +time = { version = "0.3", default-features = false, features = ["macros"] } +test-compat = { path = "../test-compat" } \ No newline at end of file diff --git a/ezlog-core/src/appender.rs b/ezlog-core/src/appender.rs index d7d52b4..0116825 100644 --- a/ezlog-core/src/appender.rs +++ b/ezlog-core/src/appender.rs @@ -472,8 +472,7 @@ mod tests { let nonce = b"unique nonce"; EZLogConfigBuilder::new() .dir_path( - dirs::cache_dir() - .unwrap() + test_compat::test_path() .into_os_string() .into_string() .unwrap(), @@ -543,8 +542,7 @@ mod tests { let c = EZLogConfigBuilder::new() .dir_path( - dirs::cache_dir() - .unwrap() + test_compat::test_path() .into_os_string() .into_string() .unwrap(), @@ -576,8 +574,7 @@ mod tests { let c = EZLogConfigBuilder::new() .dir_path( - dirs::cache_dir() - .unwrap() + test_compat::test_path() .into_os_string() .into_string() .unwrap(), diff --git a/ezlog-core/src/config.rs b/ezlog-core/src/config.rs index 4782a93..80f2dc6 100644 --- a/ezlog-core/src/config.rs +++ b/ezlog-core/src/config.rs @@ -680,7 +680,7 @@ mod tests { #[test] fn test_query_log_files() { - let temp = dirs::cache_dir().unwrap().join("ezlog_test_config"); + let temp = test_compat::test_path().join("ezlog_test_config"); if temp.exists() { fs::remove_dir_all(&temp).unwrap(); } diff --git a/ezlog-core/src/decode.rs b/ezlog-core/src/decode.rs index 54e8073..5792c0d 100644 --- a/ezlog-core/src/decode.rs +++ b/ezlog-core/src/decode.rs @@ -311,8 +311,7 @@ mod tests { let nonce = b"unique nonce"; crate::EZLogConfigBuilder::new() .dir_path( - dirs::cache_dir() - .unwrap() + test_compat::test_path() .join(path) .into_os_string() .into_string() diff --git a/ezlog-core/src/lib.rs b/ezlog-core/src/lib.rs index 3412b62..a962bf5 100644 --- a/ezlog-core/src/lib.rs +++ b/ezlog-core/src/lib.rs @@ -903,7 +903,7 @@ mod tests { #[test] fn test_request_logs() { - let mut cache_dir = dirs::cache_dir().unwrap(); + let mut cache_dir = test_compat::test_path(); cache_dir.push("test"); std::fs::create_dir_all(&cache_dir).unwrap(); let dir_clone = cache_dir.clone(); diff --git a/ezlog-core/tests/integration_test.rs b/ezlog-core/tests/integration_test.rs index 2c75744..b40b45f 100644 --- a/ezlog-core/tests/integration_test.rs +++ b/ezlog-core/tests/integration_test.rs @@ -59,8 +59,7 @@ fn test_logger_create() { ezlog::InitBuilder::new().debug(true).init(); let config = EZLogConfigBuilder::new() .dir_path( - dirs::cache_dir() - .unwrap() + test_compat::test_path() .into_os_string() .into_string() .expect("dir path error"), diff --git a/test-compat/Cargo.toml b/test-compat/Cargo.toml new file mode 100644 index 0000000..c512c68 --- /dev/null +++ b/test-compat/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "test-compat" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dirs = "5.0" \ No newline at end of file diff --git a/test-compat/src/lib.rs b/test-compat/src/lib.rs new file mode 100644 index 0000000..af5f593 --- /dev/null +++ b/test-compat/src/lib.rs @@ -0,0 +1,9 @@ +use std::path::PathBuf; + +pub fn test_path() -> PathBuf { + if cfg!(target_os = "android") { + std::env::current_dir().unwrap() + } else { + dirs::cache_dir().unwrap() + } +}