From 81e211095b0fbb21ca530b10780769399abb64ae Mon Sep 17 00:00:00 2001 From: Aisuko Date: Tue, 4 Oct 2022 14:18:16 +0800 Subject: [PATCH] Fix redundant clone issue and add testcases (#238) Signed-off-by: Aisuko --- src/config.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/config.rs b/src/config.rs index a7f2ed6..157246a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,3 +51,40 @@ pub fn get_backups_flder() -> PathBuf { pub fn get_boilr_links_path() -> PathBuf { get_config_folder().join("links") } + + +#[cfg(test)] +mod tests{ + use std::path::PathBuf; + + use super::get_config_folder; + + #[test] + + #[cfg(target_family = "unix")] + fn check_return_xdg_config_path(){ + + // Parameters for set environment 'XDG_CONFIG_HOME' + std::env::set_var("XDG_CONFIG_HOME", std::env::var("HOME").unwrap()+"/.config/boilr"); + + let xdg_config_home=std::env::var("XDG_CONFIG_HOME").unwrap(); + let config_path=get_config_folder(); + let test_path=PathBuf::from(xdg_config_home); + + assert_eq!(config_path,test_path); + } + + + #[test] + + #[cfg(target_family = "unix")] + fn check_return_config_path(){ + + std::env::set_var("XDG_CONFIG_HOME", std::env::var("HOME").unwrap()+"/.config/boilr"); + + let config_path=get_config_folder(); + let current_path=std::env::var("HOME").unwrap()+"/.config/boilr"; + + assert_eq!(config_path,PathBuf::from(current_path)); + } +} \ No newline at end of file