Skip to content
Snippets Groups Projects

Fix expand tilde and invalid path chars on windows

Merged mjptree requested to merge mjptree/arti:fix-expand-tilde-on-windows into main
5 unresolved threads
@@ -194,7 +194,6 @@ mod test {
assert_eq!(p.path().unwrap().to_str(), Some("/usr/local/foo"));
}
// FIXME: Add test for windows
#[cfg(not(target_family = "windows"))]
#[test]
fn expand_home() {
@@ -209,7 +208,20 @@ mod test {
assert_eq!(p.path().unwrap().to_str(), expected.to_str());
}
// FIXME: Add test for windows
#[cfg(target_family = "windows")]
#[test]
fn expand_home() {
let p = CfgPath::new("~\\.arti\\config".to_string());
    • Were you aware of the Rust raw strings feature? I think you could write this like this, for example:

      Suggested change
      214 let p = CfgPath::new("~\\.arti\\config".to_string());
      214 let p = CfgPath::new(r"~\.arti\config".to_string());

      NB, untested. Whether to do that here is a matter of taste I think, and certainly use of the doubled toothpicks is no reason not to merge this.

Please register or sign in to reply
assert_eq!(p.to_string(), "~\\.arti\\config".to_string());
let expected = dirs::home_dir().unwrap().join(".arti\\config");
assert_eq!(p.path().unwrap().to_str(), expected.to_str());
let p = CfgPath::new("${USER_HOME}\\.arti\\config".to_string());
assert_eq!(p.to_string(), "${USER_HOME}\\.arti\\config".to_string());
assert_eq!(p.path().unwrap().to_str(), expected.to_str());
}
#[cfg(not(target_family = "windows"))]
#[test]
fn expand_cache() {
@@ -220,6 +232,16 @@ mod test {
assert_eq!(p.path().unwrap().to_str(), expected.to_str());
}
#[cfg(target_family = "windows")]
#[test]
fn expand_cache() {
let p = CfgPath::new("${ARTI_CACHE}\\example".to_string());
assert_eq!(p.to_string(), "${ARTI_CACHE}\\example".to_string());
let expected = project_dirs().unwrap().cache_dir().join("example");
assert_eq!(p.path().unwrap().to_str(), expected.to_str());
}
#[test]
fn expand_bogus() {
let p = CfgPath::new("${ARTI_WOMBAT}/example".to_string());
Loading