Our project has its own wrappers for loading and comparing the programme output with a snapshot. It looks something like this:
fn assert_snapshot_matches(&self, snapshot_test_path: &str) -> &Self {
let assertion = assertion();
let normalized = self.get_normalized_stdout();
let mut snapshot_path = std::env::current_dir()?;
snapshot_path.push(snapshot_test_path);
let expected = Data::read_from(&snapshot_path, None);
assertion.eq(normalized, expected);
self
}
However, sometimes the symbol for transitioning to the parent directory .. may appear in the paths to the snapshot. Because of this, when submitting tests, you may see the following
---- expected: tests/integration/../integration/snapshots/snapshot_name.stdout.txt
++++ actual: In-memory
How about adding Path::canonicalize to the call, where you save the snapshot?
|
pub fn path(path: impl Into<std::path::PathBuf>) -> Self { |
|
Self { |
|
inner: DataSourceInner::Path(path.into()), |
|
} |
|
} |
But in Windows, truncating the current directory may break due to UNC paths :(
|
pub(crate) fn display_relpath(path: impl AsRef<std::path::Path>) -> String { |
|
let path = path.as_ref(); |
|
let relpath = if let Ok(cwd) = std::env::current_dir() { |
|
match path.strip_prefix(cwd) { |
|
Ok(path) => path, |
|
Err(_) => path, |
|
} |
|
} else { |
|
path |
|
}; |
|
relpath.display().to_string() |
|
} |
Our project has its own wrappers for loading and comparing the programme output with a snapshot. It looks something like this:
However, sometimes the symbol for transitioning to the parent directory
..may appear in the paths to the snapshot. Because of this, when submitting tests, you may see the followingHow about adding
Path::canonicalizeto the call, where you save the snapshot?snapbox/crates/snapbox/src/data/source.rs
Lines 14 to 18 in c461f19
But in
Windows, truncating the current directory may break due to UNC paths :(snapbox/crates/snapbox/src/dir/ops.rs
Lines 219 to 230 in c461f19