diff --git a/tests/cli.rs b/tests/cli.rs index 74824c0..9261e64 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -4,6 +4,9 @@ use std::{ path::{Path, PathBuf}, }; +#[allow(unused_imports)] +use std::fs::canonicalize; + use assert_cmd::Command; use insta::assert_snapshot; use tempfile::{tempdir, TempDir}; @@ -34,11 +37,7 @@ impl TestContext { home_directory.path().display(), std::path::MAIN_SEPARATOR ); - let working_directory_display = format!( - "{}{}", - working_directory.path().display(), - std::path::MAIN_SEPARATOR - ); + let working_directory_display = working_directory_display(&working_directory); Self { command, home_directory, @@ -103,6 +102,25 @@ impl TestContext { } } +#[cfg(not(target_os = "windows"))] +fn working_directory_display(dir: &TempDir) -> String { + format!( + "{}{}", + canonicalize(dir) + .expect( + " + unable to locate working directory", + ) + .display(), + std::path::MAIN_SEPARATOR + ) +} + +#[cfg(target_os = "windows")] +fn working_directory_display(dir: &TempDir) -> String { + format!("{}{}", dir.path().display(), std::path::MAIN_SEPARATOR) +} + fn write_file(path: &Path, content: &str) { std::fs::write(path, content).expect("unable to write file"); }