Skip to content

Commit f4b1db0

Browse files
committed
fix(tests): windows builds
The reason is simple. The dirs crate uses windows apis to get the path, thus overriding it with temp_dir is impossible. std::env::home_dir was deprecated for a long long time. It was fixed in rust-lang/rust#132515, but was still deprecated, thus showing warnings in edition 2024. In rust-lang/rust#137327, it was undeprecated thus warnings won't show. Keep using the standard lib in this case. When next edition of rust releases, this will be solved.
1 parent ee6795f commit f4b1db0

6 files changed

Lines changed: 13 additions & 54 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ rand = "0.9"
2222
urlencoding = "2.1.3"
2323
scraper = "0.23.1"
2424
colored = "3.0.0"
25-
dirs = "6.0.0"
2625
html-escape = "0.2.13"
2726
logger = "0.4.0"
2827
env_logger = "0.11.8"

src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use dirs::home_dir;
21
use rusqlite::{Connection, Result};
2+
use std::env::home_dir;
33
use std::error::Error as StdError;
44
use std::fs::create_dir_all;
55
use std::path::PathBuf;

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use dirs::home_dir;
21
use log::info;
32
use serde::{Deserialize, Serialize};
3+
use std::env::home_dir;
44
use std::error::Error as StdError;
55
use std::fs::{File, create_dir_all, read_to_string, write};
66
use std::io::BufReader;

src/logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use dirs::home_dir;
1+
use std::env::home_dir;
22
use std::error::Error as StdError;
33
use std::fs::{OpenOptions, create_dir_all};
44
use std::io::{self, Write};

tests/common/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ use tempdir::TempDir;
33

44
pub fn setup_temp_home() -> Result<TempDir, Box<dyn Error + Send + Sync>> {
55
let temp_dir = TempDir::new("getquotes_test")?;
6-
unsafe { std::env::set_var("HOME", temp_dir.path().to_str().unwrap()) };
6+
7+
#[cfg(windows)]
8+
unsafe {
9+
std::env::set_var("USERPROFILE", temp_dir.path().to_str().unwrap());
10+
}
11+
12+
#[cfg(not(windows))]
13+
unsafe {
14+
std::env::set_var("HOME", temp_dir.path().to_str().unwrap());
15+
}
716
Ok(temp_dir)
817
}

0 commit comments

Comments
 (0)