Skip to content

Commit

Permalink
Modified path to follow symlinks for snapshots tests (#76)
Browse files Browse the repository at this point in the history
Some snapshot tests were failing on m2 macs due to a difference between
"/private/vars/folders..." and "/vars/folders...". "/vars/folders..."
seems to just by a symlink to "/private/vars/folders...", so the file
path was changed to follow said symlinks on macs only.

---------

Co-authored-by: Aiden Fujiwara <[email protected]>
  • Loading branch information
afujiwara-roblox and Aiden Fujiwara authored Aug 31, 2023
1 parent ed4bdef commit 4bec9b0
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 4bec9b0

Please sign in to comment.