Add note and test regarding paths being physical

This commit is contained in:
Matan Kushner 2019-04-09 00:04:50 -04:00
parent 969840a157
commit 67ab2121c5
No known key found for this signature in database
GPG Key ID: 4B98C3A8949CA8A4
1 changed files with 15 additions and 3 deletions

View File

@ -20,10 +20,9 @@ pub fn segment(_: &ArgMatches) -> Segment {
const DIR_TRUNCATION_LENGTH: usize = 3; const DIR_TRUNCATION_LENGTH: usize = 3;
const HOME_SYMBOL: &str = "~"; const HOME_SYMBOL: &str = "~";
// TODO: Currently gets the physical directory. Get the logical directory.
let current_path = env::current_dir() let current_path = env::current_dir()
.expect("Unable to identify current directory") .expect("Unable to identify current directory");
.canonicalize()
.expect("Unable to canonicalize current directory");
let dir_string; let dir_string;
if let Ok(repo) = git2::Repository::discover(&current_path) { if let Ok(repo) = git2::Repository::discover(&current_path) {
@ -138,4 +137,17 @@ mod tests {
let segment = segment(&args); let segment = segment(&args);
assert_eq!(segment.value, "/"); assert_eq!(segment.value, "/");
} }
#[test]
fn do_not_canonicalize_paths() {
let args = App::new("starship")
.arg(Arg::with_name("status_code"))
.get_matches_from(vec!["starship", "0"]);
let root_dir = Path::new("/var");
env::set_current_dir(&root_dir).unwrap();
let segment = segment(&args);
assert_eq!(segment.value, "/var");
}
} }